chiark / gitweb /
bundle auto-zip: wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 15 May 2022 17:37:22 +0000 (18:37 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 15 May 2022 23:26:51 +0000 (00:26 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Cargo.lock
cli/Cargo.toml
cli/otter.rs
cli/usebundles.rs

index ddf6c4c94c48a1a7c5e3567f8ce57bbf86b66e89..1adc166b0d40e3d61428b494acd6c9eab4cfbf93 100644 (file)
@@ -2773,6 +2773,7 @@ dependencies = [
  "serde",
  "serde_with",
  "strum",
+ "walkdir",
 ]
 
 [[package]]
index 0a73bb5063c777513adb5c4eb2f1e054b450aa2f..bd33d3986e967c8db1b88373b65a2290ab9e869d 100644 (file)
@@ -31,6 +31,7 @@ otter-base.version="=1.0.0"
 argparse="0.2"
 directories="4"
 ron="0.7"
+walkdir="2.3"
 
 fehler="1"
 num-traits="0.2"
index 91d99dd6fdf8fbf9add4ad9f81760a7f99f2fc35..944d31c0e625543af706ebcb55fbce38a4846d2c 100644 (file)
@@ -23,6 +23,7 @@ pub use std::rc::Rc;
 pub use argparse::{self,ArgumentParser,action::{TypedAction,ParseResult}};
 pub use argparse::action::{Action,IFlagAction,IArgAction};
 pub use derive_more::Display;
+pub use walkdir::WalkDir;
 
 pub use otter::prelude::*;
 pub use otter::commands::*;
index 91f83f3db9218d45dc913316b28b22a691078162..1f0461a4df1b81f053709929260f8dcb12149ad7 100644 (file)
@@ -18,9 +18,30 @@ pub struct BundleForUpload {
 impl BundleForUpload {
   #[throws(AE)]
   pub fn prepare(file: String) -> Self {
-    let f = File::open(&file)
-      .with_context(|| file.clone())
-      .context("open bundle file")?;
+    let mut walk = WalkDir::new(&file)
+      .same_file_system(true)
+      .follow_links(true)
+      .sort_by_file_name()
+      .into_iter()
+      .peekable();
+
+    let peek = walk.peek().ok_or_else(|| anyhow!("unable to inspect"))?;
+    if_let!{
+      Ok(peek) = peek;
+      else Err(
+        walk.next().unwrap().unwrap_err()
+      ).context("inspect")?
+    };
+    if ! peek.file_type().is_dir() {
+      let f = File::open(&file).context("open")?;
+      Self::prepare_open_file(&file, f)?
+    } else {
+      Self::prepare_from_dir(&file, walk)?
+    }
+  }
+
+  #[throws(AE)]
+  pub fn prepare_open_file(file: &str, f: File) -> Self {
     let size = f
       .metadata().context("fstat bundle file")?
       .len()
@@ -31,7 +52,7 @@ impl BundleForUpload {
     let hash = bundles::Hash(hash.into());
     let kind = bundles::Kind::only();
     f.rewind().context("rewind bundle file")?;
-    BundleForUpload { file, f, size, hash, kind }
+    BundleForUpload { file: file.to_owned(), f, size, hash, kind }
   }
 
   #[throws(AE)]
@@ -52,6 +73,16 @@ impl BundleForUpload {
     progress.clear();
     bundle
   }
+
+//  #[throws(AE)]
+  pub fn prepare_from_dir<W>(_file: &str, walk: W) -> Result<Self,AE>
+  where W: Iterator<Item=walkdir::Result<walkdir::DirEntry>>
+  {
+    for ent in walk {
+      eprintln!("GOT {:?} {:?}", &ent, &ent.as_ref().unwrap().file_name());
+    }
+    panic!("NYI")
+  }
 }
 
 mod upload_bundle {