summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-04-23 11:54:12 +0300
committerLars Wirzenius <liw@liw.fi>2021-04-23 11:54:12 +0300
commitcd270b969176a11d659ac8cbf81c15e7150b4b22 (patch)
tree18d5526276ff5de5054a1f8354a526477a9632f3
parent2e6bd0b306647e99a5b35dd1486682a687e3b847 (diff)
downloadsummain-rs-cd270b969176a11d659ac8cbf81c15e7150b4b22.tar.gz
add index for ordering entries later
-rw-r--r--src/bin/summain.rs8
-rw-r--r--src/lib.rs6
2 files changed, 9 insertions, 5 deletions
diff --git a/src/bin/summain.rs b/src/bin/summain.rs
index bd62e60..2eb4152 100644
--- a/src/bin/summain.rs
+++ b/src/bin/summain.rs
@@ -17,8 +17,8 @@ async fn async_main() -> anyhow::Result<()> {
opt.pathnames[..].sort();
let mut handles = vec![];
- for filename in opt.pathnames.iter().cloned() {
- handles.push(tokio::spawn(async move { manifest(filename) }));
+ for (i, filename) in opt.pathnames.iter().cloned().enumerate() {
+ handles.push(tokio::spawn(async move { manifest(i, filename) }));
}
let mut manifests = vec![];
@@ -39,8 +39,8 @@ struct Opt {
pathnames: Vec<PathBuf>,
}
-async fn manifest(path: PathBuf) -> anyhow::Result<ManifestEntry> {
- ManifestEntry::new(&path)
+async fn manifest(i: usize, path: PathBuf) -> anyhow::Result<ManifestEntry> {
+ ManifestEntry::new(i, &path)
.await
.with_context(|| format!("{}", path.display()))
}
diff --git a/src/lib.rs b/src/lib.rs
index 698cf31..6bcef0b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -42,6 +42,9 @@ const BUF_SIZE: usize = 1024 * 1024;
/// An entry in a file manifest.
#[derive(Serialize, Debug)]
pub struct ManifestEntry {
+ #[serde(skip)]
+ index: usize,
+
path: String,
#[serde(with = "mode")]
mode: u32,
@@ -60,7 +63,7 @@ impl ManifestEntry {
/// caller. This function doesn't query the system for it.
///
/// The structure can be serialized using serde.
- pub async fn new(path: &Path) -> std::io::Result<Self> {
+ pub async fn new(i: usize, path: &Path) -> std::io::Result<Self> {
let m = symlink_metadata(path)?;
let hash = if m.is_file() {
let path = path.to_path_buf();
@@ -74,6 +77,7 @@ impl ManifestEntry {
None
};
Ok(Self {
+ index: i,
path: path.to_string_lossy().into_owned(),
mode: m.st_mode(),
mtime: m.st_mtime(),