matthiaskrgr / cargo-cache

manage cargo cache (${CARGO_HOME}, ~/.cargo/), print sizes of dirs and remove dirs selectively
Other
858 stars 17 forks source link

crate source verification #110

Open matthiaskrgr opened 2 years ago

matthiaskrgr commented 2 years ago

It would be interesting if cargo-cache could find local extracted sources that differ from the contents of the respective .xz /.crate archives.

EDIT: idea dump:

matthiaskrgr commented 2 years ago

might get away with checking if any files contained inside the extracted sources are newer than downloaded source archive (.crate)

matthiaskrgr commented 2 years ago

compare in-zip file against local source cache

https://rust-lang-nursery.github.io/rust-cookbook/compression/tar.html

use flate2::read::GzDecoder;
use std::fs::File;
use tar::Archive;

fn main() -> Result<(), std::io::Error> {
    let path = "datetime-0.5.2.crate";

    let tar_gz = File::open(path)?;
    let tar = GzDecoder::new(tar_gz);
    let mut archive = Archive::new(tar);

    let files = archive.entries()?;

    files.into_iter().for_each(|f| {
        let file = f.unwrap();
        // println!("{}", file.path().unwrap().display());
        // println!("{:?}", file.header());
        // print the file name and the size
        println!("{}, {} bytes", file.path().unwrap().display(), file.size());
    });

    Ok(())
}
matthiaskrgr commented 2 years ago

For the git source, we can go into checkouts, for instance: ~/.cargo/git/checkouts/druid-f6980810fb848923/c42de0b and check with git-status / git diff

matthiaskrgr commented 2 years ago

still missing: git checkout verification, check something like git status --porcelain also handle what happens if we have checkout but no repo?