diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs index b62247e..f49422d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ use camino::{Utf8Path, Utf8PathBuf}; // and blackslash are escaped, too. there is no header. if a time // cannot be attained due to an error, it is left blank // data is in the format: path, creation-time, modification-time +// the path is relative to the given path fn main() { // currently only accepts one argument, the path to the directory it will @@ -23,14 +24,14 @@ fn main() { // computationally. i'm not quite sure why. // first pass: read and output file information // second pass: read and outut directory information - process(path) + process(&path, &path) } -fn process(path: Utf8PathBuf) { +fn process(root_path: &Utf8Path, path: &Utf8Path) { //TODO: do not panic, please - let root_meta = std::fs::metadata(&path).unwrap(); - let root_times = Times::metadata(&root_meta); - row(&path, &root_times); + let this_meta = std::fs::metadata(&path).unwrap(); + let this_times = Times::metadata(&this_meta); + row(root_path, &path, &this_times); for entry in path.read_dir_utf8().unwrap() { let entry = entry.unwrap(); @@ -40,7 +41,7 @@ fn process(path: Utf8PathBuf) { Ok(ft) if ft.is_file() => { let meta = entry.metadata().unwrap(); let times = Times::metadata(&meta); - row(entry.path(), ×) + row(root_path, entry.path(), ×) } Ok(_) => {} } @@ -51,16 +52,18 @@ fn process(path: Utf8PathBuf) { match entry.file_type() { Err(_) => panic!(), - Ok(ft) if ft.is_dir() => process(entry.into_path()), + Ok(ft) if ft.is_dir() => process(root_path, entry.path()), Ok(_) => {} } } } -fn row<P: AsRef<Utf8Path>>(path: P, times: &Times) { +fn row<P: AsRef<Utf8Path>>(root: &Utf8Path, path: P, times: &Times) { + let relative = path.as_ref().strip_prefix(root).unwrap(); + println!( "{},{},{},{}", - escape(path.as_ref()), + escape(relative), times .created() .map(|d| d.as_secs().to_string()) |