diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-11-28 16:29:44 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-11-28 17:03:45 +0200 |
commit | 2583b50e2a49fb0492ae0d341a51353b806c3233 (patch) | |
tree | 440f691dbf74da7fb17f7deaed9f43e130391787 | |
parent | 8fae3c648d81d75510ecb68ed80d0042a5a2088f (diff) | |
download | summain-rs-2583b50e2a49fb0492ae0d341a51353b806c3233.tar.gz |
feat! ManifestEntry::new now looks up metadata itself
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | src/bin/summain.rs | 4 | ||||
-rw-r--r-- | src/lib.rs | 9 |
3 files changed, 8 insertions, 8 deletions
@@ -1,6 +1,6 @@ [package] name = "summain" -version = "0.1.0" +version = "0.2.0" description = "File manifests" readme = "README.md" license = "GPL-3.0-or-later" @@ -13,5 +13,6 @@ edition = "2018" anyhow = "1" serde = { version = "1", features = ["derive"] } serde_yaml = "0.8" +sha2 = "0.9" structopt = "0.3" unix_mode = "0.1" diff --git a/src/bin/summain.rs b/src/bin/summain.rs index 056bc8b..0abe2f5 100644 --- a/src/bin/summain.rs +++ b/src/bin/summain.rs @@ -1,5 +1,4 @@ use anyhow::Context; -use std::fs::symlink_metadata; use std::path::{Path, PathBuf}; use structopt::StructOpt; use summain::ManifestEntry; @@ -20,8 +19,7 @@ struct Opt { } fn report(pathname: &Path) -> anyhow::Result<()> { - let m = symlink_metadata(pathname)?; - let e = ManifestEntry::new(pathname, m); + let e = ManifestEntry::new(pathname)?; println!("{}", serde_yaml::to_string(&e)?); Ok(()) } @@ -32,7 +32,7 @@ //! ~~~ use serde::Serialize; -use std::fs::Metadata; +use std::fs::symlink_metadata; use std::os::linux::fs::MetadataExt; use std::path::{Path, PathBuf}; @@ -57,8 +57,9 @@ impl ManifestEntry { /// caller. This function doesn't query the system for it. /// /// The structure can be serialized using serde. - pub fn new(path: &Path, m: Metadata) -> Self { - Self { + pub fn new(path: &Path) -> std::io::Result<Self> { + let m = symlink_metadata(path)?; + Ok(Self { path: path.to_path_buf(), atime: m.st_atime(), atime_nsec: m.st_atime_nsec(), @@ -67,7 +68,7 @@ impl ManifestEntry { mtime_nsec: m.st_mtime_nsec(), nlink: m.st_nlink(), size: if m.is_dir() { None } else { Some(m.st_size()) }, - } + }) } } |