浏览代码

Implement archive feature use flag

timvisee 7 年之前
父节点
当前提交
358bc6816a
共有 7 个文件被更改,包括 97 次插入63 次删除
  1. 23 5
      Cargo.lock
  2. 1 1
      api/src/file/remote_file.rs
  3. 5 2
      cli/Cargo.toml
  4. 57 50
      cli/src/action/upload.rs
  5. 1 0
      cli/src/cmd/matcher/upload.rs
  6. 9 5
      cli/src/cmd/subcmd/upload.rs
  7. 1 0
      cli/src/main.rs

+ 23 - 5
Cargo.lock

@@ -385,7 +385,7 @@ dependencies = [
  "failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "hkdf 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "hyper 0.11.26 (registry+https://github.com/rust-lang/crates.io-index)",
+ "hyper 0.11.27 (registry+https://github.com/rust-lang/crates.io-index)",
  "mime_guess 2.0.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "openssl 0.10.7 (registry+https://github.com/rust-lang/crates.io-index)",
  "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -493,7 +493,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "hyper"
-version = "0.11.26"
+version = "0.11.27"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "base64 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -514,6 +514,7 @@ dependencies = [
  "tokio-proto 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "tokio-service 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "unicase 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "want 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -522,7 +523,7 @@ version = "0.1.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
- "hyper 0.11.26 (registry+https://github.com/rust-lang/crates.io-index)",
+ "hyper 0.11.27 (registry+https://github.com/rust-lang/crates.io-index)",
  "native-tls 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
  "tokio-io 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -980,7 +981,7 @@ dependencies = [
  "bytes 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
  "encoding_rs 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
- "hyper 0.11.26 (registry+https://github.com/rust-lang/crates.io-index)",
+ "hyper 0.11.27 (registry+https://github.com/rust-lang/crates.io-index)",
  "hyper-tls 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "libflate 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1420,6 +1421,11 @@ dependencies = [
  "serde 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "try-lock"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
 [[package]]
 name = "typenum"
 version = "1.10.0"
@@ -1539,6 +1545,16 @@ name = "void"
 version = "1.0.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
+[[package]]
+name = "want"
+version = "0.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "try-lock 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "winapi"
 version = "0.2.8"
@@ -1660,7 +1676,7 @@ dependencies = [
 "checksum hkdf 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "706d158974721895e9234c91af77ee28bbbf561fa276b014f32d685d27fbdc30"
 "checksum hmac 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44f3bdb08579d99d7dc761c0e266f13b5f2ab8c8c703b9fc9ef333cd8f48f55e"
 "checksum httparse 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2f407128745b78abc95c0ffbe4e5d37427fdc0d45470710cfef8c44522a2e37"
-"checksum hyper 0.11.26 (registry+https://github.com/rust-lang/crates.io-index)" = "66b16eb6213713f3c72d0ed14ce56423ae84dced8df73d2a2c8675f0495ae7ea"
+"checksum hyper 0.11.27 (registry+https://github.com/rust-lang/crates.io-index)" = "34a590ca09d341e94cddf8e5af0bbccde205d5fbc2fa3c09dd67c7f85cea59d7"
 "checksum hyper-tls 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a5aa51f6ae9842239b0fac14af5f22123b8432b4cc774a44ff059fcba0f675ca"
 "checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d"
 "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08"
@@ -1762,6 +1778,7 @@ dependencies = [
 "checksum tokio-tls 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "772f4b04e560117fe3b0a53e490c16ddc8ba6ec437015d91fa385564996ed913"
 "checksum tokio-udp 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "137bda266504893ac4774e0ec4c2108f7ccdbcb7ac8dced6305fe9e4e0b5041a"
 "checksum toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a0263c6c02c4db6c8f7681f9fd35e90de799ebd4cfdeab77a38f4ff6b3d8c0d9"
+"checksum try-lock 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee2aa4715743892880f70885373966c83d73ef1b0838a664ef0c76fffd35e7c2"
 "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169"
 "checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d"
 "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33"
@@ -1781,6 +1798,7 @@ dependencies = [
 "checksum version-compare 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "78068add8bf1e4d37d13fa5867182fe4c03f8e525c831053733f83aaba942d37"
 "checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d"
 "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
+"checksum want 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a05d9d966753fa4b5c8db73fcab5eed4549cfe0e1e4e66911e5564a0085c35d1"
 "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
 "checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3"
 "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"

+ 1 - 1
api/src/file/remote_file.rs

@@ -289,7 +289,7 @@ impl RemoteFile {
     /// This is ofcourse only done for properties that may be empty.
     ///
     /// The file IDs are not asserted for equality.
-    #[allow(useless_let_if_seq)]
+    #[allow(unknown_lints, useless_let_if_seq)]
     pub fn merge(&mut self, other: &RemoteFile, overwrite: bool) -> bool {
         // Remember whether anything has changed
         let mut changed = false;

+ 5 - 2
cli/Cargo.toml

@@ -13,11 +13,14 @@ path = "src/main.rs"
 name = "ffsend"
 
 [features]
-default = ["clipboard", "history"]
+default = ["archive", "clipboard", "history"]
 
 # Compile with file history support
 history = []
 
+# Compile with file archiving support
+archive = []
+
 # Compile without colored output support
 no-color = ["colored/no-color"]
 
@@ -39,7 +42,7 @@ prettytable-rs = "0.6"
 rpassword = "2.0"
 serde = "1.0"
 serde_derive = "1.0"
-tar = "0.4"
+tar = { version = "0.4", option = true }
 tempfile = "3"
 toml = "0.4"
 version-compare = "0.0.6"

+ 57 - 50
cli/src/action/upload.rs

@@ -22,6 +22,7 @@ use self::tempfile::{
     NamedTempFile,
 };
 
+#[cfg(feature = "archive")]
 use archive::archiver::Archiver;
 use cmd::matcher::{Matcher, MainMatcher, UploadMatcher};
 #[cfg(feature = "history")]
@@ -131,52 +132,55 @@ impl<'a> Upload<'a> {
         // A temporary archive file, only used when archiving
         // The temporary file is stored here, to ensure it's lifetime exceeds the upload process
         let mut tmp_archive: Option<NamedTempFile> = None;
-        let archive_extention = ".tar";
-
-        // Archive the file if specified
-        if matcher_upload.archive() {
-            println!("Archiving file...");
-
-            // Create a new temporary file to write the archive to
-            tmp_archive = Some(
-                TempBuilder::new()
-                    .prefix(&format!(".{}-archive-", crate_name!()))
-                    .suffix(archive_extention)
-                    .tempfile()
-                    .map_err(ArchiveError::TempFile)?
-            );
-            if let Some(tmp_archive) = &tmp_archive {
-                // Get the path, and the actual file
-                let archive_path = tmp_archive.path().to_path_buf();
-                let archive_file = tmp_archive.as_file()
-                    .try_clone()
-                    .map_err(ArchiveError::CloneHandle)?;
-
-                // Select the file name to use if not set
-                if file_name.is_none() {
-                    // TODO: use canonical path here
-                    file_name = Some(
-                        path.file_name()
-                            .ok_or(ArchiveError::FileName)?
-                            .to_str()
-                            .map(|s| s.to_owned())
-                            .expect("failed to create string from file name")
-                    );
-                }
-
-                // Build an archiver and append the file
-                let mut archiver = Archiver::new(archive_file);
-                archiver.append_path(file_name.as_ref().unwrap(), &path)
-                    .map_err(ArchiveError::AddFile)?;
 
-                // Finish the archival process, writes the archive file
-                archiver.finish().map_err(ArchiveError::Write)?;
-
-                // Append archive extention to name, set to upload archived file
-                if let Some(ref mut file_name) = file_name {
-                    file_name.push_str(archive_extention);
+        #[cfg(feature = "archive")]
+        {
+            // Archive the file if specified
+            if matcher_upload.archive() {
+                println!("Archiving file...");
+                let archive_extention = ".tar";
+
+                // Create a new temporary file to write the archive to
+                tmp_archive = Some(
+                    TempBuilder::new()
+                        .prefix(&format!(".{}-archive-", crate_name!()))
+                        .suffix(archive_extention)
+                        .tempfile()
+                        .map_err(ArchiveError::TempFile)?
+                );
+                if let Some(tmp_archive) = &tmp_archive {
+                    // Get the path, and the actual file
+                    let archive_path = tmp_archive.path().to_path_buf();
+                    let archive_file = tmp_archive.as_file()
+                        .try_clone()
+                        .map_err(ArchiveError::CloneHandle)?;
+
+                    // Select the file name to use if not set
+                    if file_name.is_none() {
+                        // TODO: use canonical path here
+                        file_name = Some(
+                            path.file_name()
+                                .ok_or(ArchiveError::FileName)?
+                                .to_str()
+                                .map(|s| s.to_owned())
+                                .expect("failed to create string from file name")
+                        );
+                    }
+
+                    // Build an archiver and append the file
+                    let mut archiver = Archiver::new(archive_file);
+                    archiver.append_path(file_name.as_ref().unwrap(), &path)
+                        .map_err(ArchiveError::AddFile)?;
+
+                    // Finish the archival process, writes the archive file
+                    archiver.finish().map_err(ArchiveError::Write)?;
+
+                    // Append archive extention to name, set to upload archived file
+                    if let Some(ref mut file_name) = file_name {
+                        file_name.push_str(archive_extention);
+                    }
+                    path = archive_path;
                 }
-                path = archive_path;
             }
         }
 
@@ -218,12 +222,15 @@ impl<'a> Upload<'a> {
             }
         }
 
-        // Close the temporary zip file, to ensure it's removed
-        if let Some(tmp_archive) = tmp_archive.take() {
-            if let Err(err) = tmp_archive.close() {
-                print_error(
-                    err.context("failed to clean up temporary archive file, ignoring").compat(),
-                );
+        #[cfg(feature = "archive")]
+        {
+            // Close the temporary zip file, to ensure it's removed
+            if let Some(tmp_archive) = tmp_archive.take() {
+                if let Err(err) = tmp_archive.close() {
+                    print_error(
+                        err.context("failed to clean up temporary archive file, ignoring").compat(),
+                    );
+                }
             }
         }
 

+ 1 - 0
cli/src/cmd/matcher/upload.rs

@@ -73,6 +73,7 @@ impl<'a: 'b, 'b> UploadMatcher<'a> {
 
     /// Check whether to archive the file to upload.
     /// TODO: infer to use this flag if a directory is selected
+    #[cfg(feature = "archive")]
     pub fn archive(&self) -> bool {
         self.matches.is_present("archive")
     }

+ 9 - 5
cli/src/cmd/subcmd/upload.rs

@@ -32,16 +32,20 @@ impl CmdUpload {
                 .alias("f")
                 .value_name("NAME")
                 .help("Rename the file being uploaded"))
-            .arg(Arg::with_name("archive")
-                .long("archive")
-                .short("a")
-                .alias("arch")
-                .help("Package the file as an archive"))
             .arg(Arg::with_name("open")
                 .long("open")
                 .short("o")
                 .help("Open the share link in your browser"));
 
+        // Optional archive support
+        #[cfg(feature = "archive")] {
+            cmd = cmd.arg(Arg::with_name("archive")
+                .long("archive")
+                .short("a")
+                .alias("arch")
+                .help("Package the file as an archive"))
+        }
+
         // Optional clipboard support
         #[cfg(feature = "clipboard")] {
             cmd = cmd.arg(Arg::with_name("copy")

+ 1 - 0
cli/src/main.rs

@@ -17,6 +17,7 @@ extern crate serde;
 extern crate serde_derive;
 
 mod action;
+#[cfg(feature = "archive")]
 mod archive;
 mod cmd;
 mod error;