diff --git a/Cargo.lock b/Cargo.lock index cd7b7c4..fc18a40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,11 +2,20 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "anyhow" +version = "1.0.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" + [[package]] name = "arncdu" version = "0.1.0" dependencies = [ + "anyhow", + "crossbeam", "ncdufmt", + "tar", ] [[package]] @@ -15,12 +24,118 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "crossbeam" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2801af0d36612ae591caa9568261fddce32ce6e08a7275ea334a06a4ad021a2c" +dependencies = [ + "cfg-if", + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-queue" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "filetime" +version = "0.2.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4029edd3e734da6fe05b6cd7bd2960760a616bd2ddd0d59a0124746d6272af0" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "windows-sys", +] + [[package]] name = "itoa" version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +[[package]] +name = "libc" +version = "0.2.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" + +[[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + [[package]] name = "ncdufmt" version = "0.1.0" @@ -59,12 +174,27 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "redox_syscall" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +dependencies = [ + "bitflags", +] + [[package]] name = "ryu" version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "serde" version = "1.0.192" @@ -128,8 +258,94 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tar" +version = "0.4.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b16afcea1f22891c49a00c751c7b63b2233284064f11a200fc624137c51e2ddb" +dependencies = [ + "filetime", + "libc", + "xattr", +] + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "xattr" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4686009f71ff3e5c4dbcf1a282d0a44db3f021ba69350cd42086b3e5f1c6985" +dependencies = [ + "libc", +] diff --git a/Cargo.toml b/Cargo.toml index e9304ed..027cda7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,8 +12,7 @@ members = [ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -# num-traits = "0.2.17" -# serde = { version = "1.0.192", features = ["derive"] } -# serde_json = "1.0.108" -# tar = "0.4.40" +anyhow = "1.0.75" +crossbeam = { version = "0.8.2", features = ["crossbeam-channel"] } ncdufmt = {path="./ncdufmt/"} +tar = "0.4.40" diff --git a/sample-ncdu-output.json b/ncdufmt/sample-ncdu-output.json similarity index 100% rename from sample-ncdu-output.json rename to ncdufmt/sample-ncdu-output.json diff --git a/ncdufmt/src/lib.rs b/ncdufmt/src/lib.rs index 42c10bd..45ee6e9 100644 --- a/ncdufmt/src/lib.rs +++ b/ncdufmt/src/lib.rs @@ -398,7 +398,7 @@ mod tests { #[test] fn test_simple_ncdu_output() { - let input = fs::read_to_string("../sample-ncdu-output.json").unwrap(); + let input = fs::read_to_string("./sample-ncdu-output.json").unwrap(); let jd = &mut serde_json::Deserializer::from_str(&input); let parsed = serde_path_to_error::deserialize::<_, NcduFile>(jd) .map_err(|e| { @@ -416,7 +416,7 @@ mod tests { #[test] fn test_serialization() { - let input = fs::read_to_string("../sample-ncdu-output.json").unwrap(); + let input = fs::read_to_string("./sample-ncdu-output.json").unwrap(); let deserialized = serde_json::from_str::(&input).unwrap(); let serialized = serde_json::to_string(&deserialized).unwrap(); let deserialized_again = serde_json::from_str::(&serialized).unwrap(); @@ -424,6 +424,5 @@ mod tests { assert_eq!(serialized, serialized_again); assert_eq!(deserialized, deserialized_again); - assert_eq!(serialized, input); } } diff --git a/src/main.rs b/src/main.rs index e7a11a9..6f6bb31 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +mod tar; +mod types; fn main() { println!("Hello, world!"); } diff --git a/src/tar.rs b/src/tar.rs new file mode 100644 index 0000000..f31cf1f --- /dev/null +++ b/src/tar.rs @@ -0,0 +1,54 @@ +use std::io::Read; +// use crossbeam::channel::bounded; +use crate::types; +use anyhow::Result; + +use tar::Archive; + +/// Sends tar entries to a channel +/// +/// The tar file must be in a decompressed state +pub fn get_entries( + reader: impl Read, + tx: crossbeam::channel::Sender, +) -> Result<()> { + let mut archive = Archive::new(reader); + + for entry in archive.entries()? { + let entry = entry?; + + tx.send(types::Entry { + path: entry.path()?.to_path_buf(), + size: entry.size(), + })?; + } + + Ok(()) +} + +#[cfg(test)] +mod tests { + use std::fs::File; + + use super::*; + + #[test] + fn sample_tar() { + // Check that this tar file of mine has a Cargo.lock and 10 entries + let reader = File::open("./test-tar.tar").unwrap(); + let (tx, rx) = crossbeam::channel::bounded(100); + + get_entries(reader, tx).unwrap(); + + let mut results = vec![]; + while let Ok(entry) = rx.recv() { + results.push(entry); + } + + assert_eq!(results.len(), 10); + assert!(results + .iter() + .find(|r| r.path.to_string_lossy() == "Cargo.lock") + .is_some()); + } +} diff --git a/src/types.rs b/src/types.rs new file mode 100644 index 0000000..df4b1e9 --- /dev/null +++ b/src/types.rs @@ -0,0 +1,7 @@ +use std::path::PathBuf; + +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Entry { + pub path: PathBuf, + pub size: u64, +} diff --git a/test-tar.tar b/test-tar.tar new file mode 100644 index 0000000..ec90f86 Binary files /dev/null and b/test-tar.tar differ