Initial commit
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/target
|
||||
/.idea
|
||||
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal 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
6
Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "fix_parent_mtime"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
64
src/main.rs
Normal file
64
src/main.rs
Normal 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);
|
||||
}
|
||||
}
|
||||
0
test_folder/folder/inner.txt
Normal file
0
test_folder/folder/inner.txt
Normal file
0
test_folder/outer.txt
Normal file
0
test_folder/outer.txt
Normal file
Reference in New Issue
Block a user