summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-11-28 16:29:44 +0200
committerLars Wirzenius <liw@liw.fi>2020-11-28 17:03:45 +0200
commit2583b50e2a49fb0492ae0d341a51353b806c3233 (patch)
tree440f691dbf74da7fb17f7deaed9f43e130391787
parent8fae3c648d81d75510ecb68ed80d0042a5a2088f (diff)
downloadsummain-rs-2583b50e2a49fb0492ae0d341a51353b806c3233.tar.gz
feat! ManifestEntry::new now looks up metadata itself
-rw-r--r--Cargo.toml3
-rw-r--r--src/bin/summain.rs4
-rw-r--r--src/lib.rs9
3 files changed, 8 insertions, 8 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 09e4dde..3435e8c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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(())
}
diff --git a/src/lib.rs b/src/lib.rs
index eacce62..ccd652f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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()) },
- }
+ })
}
}