Initial commit

This commit is contained in:
2024-09-15 04:51:03 +03:00
commit 56fa91d998
6 changed files with 79 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/target
/.idea

7
Cargo.lock generated Normal file
View File

@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "fix_parent_mtime"
version = "0.1.0"

6
Cargo.toml Normal file
View File

@@ -0,0 +1,6 @@
[package]
name = "fix_parent_mtime"
version = "0.1.0"
edition = "2021"
[dependencies]

64
src/main.rs Normal file
View File

@@ -0,0 +1,64 @@
use std::env;
use std::path::PathBuf;
use std::process::exit;
fn main() -> std::io::Result<()> {
let args: Vec<String> = env::args().collect();
if args.len() < 3 {
usage("");
}
let root_dir = &args[1];
let root_path = PathBuf::from(root_dir);
if !root_path.exists() {
usage(format!("Path does not exists: {}", root_dir).as_str());
}
if !root_path.is_dir() {
usage(format!("Not a directory: {}", root_dir).as_str());
}
if let Ok(metadata) = root_path.metadata() {
if let Ok(time) = metadata.modified() {
println!("{:?}", time);
} else {
usage("Filesystem mtime not supported on this platform");
}
} else {
usage(format!("No access to path: {}", root_dir).as_str());
}
Ok(())
}
fn usage(message: &str) {
let app_name = env!("CARGO_PKG_NAME");
if !message.is_empty() {
eprintln!("{}", message);
}
eprintln!("Usage: {} path", app_name);
exit(1);
}
#[cfg(test)]
mod test {
use super::*;
const TEST_DIR: &str = "test_folder";
fn prepare(dir: &str) {
let test_dir = PathBuf::from(dir);
let cur_dir = env::current_dir().unwrap();
let root_dir = cur_dir.join(&test_dir);
dbg!(test_dir);
dbg!(cur_dir);
dbg!(root_dir);
}
#[test]
fn test_metadata() {
prepare(TEST_DIR);
assert!(true);
}
}

View File

0
test_folder/outer.txt Normal file
View File