diff --git a/Cargo.lock b/Cargo.lock index 673ab92..e9f29b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -229,6 +229,7 @@ version = "0.1.0" dependencies = [ "cargo-insta 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "filesize 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "signal-hook 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", @@ -277,6 +278,14 @@ name = "fake-simd" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "filesize" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "fuchsia-cprng" version = "0.1.1" @@ -1073,6 +1082,7 @@ dependencies = [ "checksum failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9" "checksum failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" +"checksum filesize 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "12d741e2415d4e2e5bd1c1d00409d1a8865a57892c2d689b504365655d237d43" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" "checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" diff --git a/Cargo.toml b/Cargo.toml index 43cd470..aa4359d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ failure = "0.1" walkdir = "2" signal-hook = "0.1.10" structopt = "0.3" +filesize = "0.2.0" [dev-dependencies] insta = "0.12.0" diff --git a/src/state/files/file_or_folder.rs b/src/state/files/file_or_folder.rs index 2746953..f830054 100644 --- a/src/state/files/file_or_folder.rs +++ b/src/state/files/file_or_folder.rs @@ -1,9 +1,10 @@ use ::std::collections::{HashMap, VecDeque}; use ::std::ffi::OsString; use ::std::fs::Metadata; -use ::std::os::unix::fs::MetadataExt; // TODO: support other OSs use ::std::path::PathBuf; +use ::filesize::PathExt; + #[derive(Debug, Clone)] pub enum FileOrFolder { Folder(Folder), @@ -58,7 +59,7 @@ impl Folder { if entry_metadata.is_dir() { self.add_folder(relative_path); } else { - let size = entry_metadata.blocks() * 512; // TODO: support other OSs that do not have blocks + let size = relative_path.size_on_disk_fast(&entry_metadata).unwrap_or(entry_metadata.len()); self.add_file(relative_path, size); } }