Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add more methods used in cargo-dist #38

Merged
merged 7 commits into from
Apr 27, 2023
Merged

Conversation

shadows-withal
Copy link
Contributor

Adds:

  • Parent directory creation to LocalAsset::write_new,
  • LocalAsset::create_directory to create a single directory,
  • LocalAsset::remove to remove a file/directory,
  • LocalAsset::tar_[gz,xz,zstd]_dir to create tar archives,
  • LocalAsset::zip_dir to create zip archives

This should replace most of the existing fs code within cargo-dist, which would be the next step after merging and cutting a release.


/// Internal tar-file compression algorithms
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub(crate) enum CompressionImpl {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it'd be best to expose all possible methods, while at the same time keeping a crate-internal duplicate of cargo-dists CompressionImpl so we can carry over the function code mostly unmodified (with the exception of the error handling)

// The contents of the zip (e.g. a tar)
let dir_name = src_path.file_name().unwrap();
let zip_contents_name = format!("{dir_name}.tar");
let final_zip_file = match fs::File::create(dest_path) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a spot where we could use LocalAsset::write_new?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure, since we're just creating the file and not initially writing anything to it, before passing it off to the various buffer writers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we could- and it would help with debugging as the error that throws is the write new error and so using the associated function i think makes sense

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, if anything, i'd rather add a new write_and_open method or something, since write_new doesn't actually return a File (which is what we need here). either that or we use write_new and then do File::open afterwards

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh got it, sorry, haven't had any coffee yet today lol. i like the write and open idea but we could file that as an issue and not block on it

src/error.rs Show resolved Hide resolved
src/error.rs Show resolved Hide resolved
src/local.rs Show resolved Hide resolved
src/local.rs Show resolved Hide resolved
src/local.rs Outdated Show resolved Hide resolved
@@ -182,6 +224,38 @@ impl LocalAsset {
}
}

/// Creates a new .tar.gz file from a provided directory
pub fn tar_gz_dir(origin_dir: &str, dest_dir: &str) -> Result<()> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would we want a tar_dir function that takes a compressionimpl as an arg w/a default instead of having it in the function name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what gankra and me were talking about -- our usage of some of the compression enums in cargo-dist is bound to how we generate toml files via serde, so i avoided porting those over here (imagine we add a new enum variant to one of them for another project, and then we suddenly introduced new behavior into cargo-dist unwillingly)

Copy link
Contributor Author

@shadows-withal shadows-withal Apr 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see discussion on discord: 1100431732366397560

src/local.rs Outdated Show resolved Hide resolved
Copy link
Member

@ashleygwilliams ashleygwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few final comments, but otherwise good to go i think! i am guessing the todos/error handling are direct copies from cargo-dist but it would be nice to square those away or at least file issues before we publish code with them

src/compression.rs Show resolved Hide resolved
src/compression.rs Show resolved Hide resolved
src/error.rs Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants