Skip to content

Commit

Permalink
fix(portability): cross-platform size-on-disk
Browse files Browse the repository at this point in the history
Adds the filesize crate as a dependency.
  • Loading branch information
Freaky committed Jun 18, 2020
1 parent f19a4f5 commit b83a07a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions src/state/files/file_or_folder.rs
Original file line number Diff line number Diff line change
@@ -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),
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit b83a07a

Please sign in to comment.