-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
|
||
/// Internal tar-file compression algorithms | ||
#[derive(Debug, Copy, Clone, PartialEq, Eq)] | ||
pub(crate) enum CompressionImpl { |
There was a problem hiding this comment.
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-dist
s CompressionImpl
so we can carry over the function code mostly unmodified (with the exception of the error handling)
f026266
to
089bd56
Compare
// 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) { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
@@ -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<()> { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this 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
Adds:
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 archivesThis should replace most of the existing fs code within cargo-dist, which would be the next step after merging and cutting a release.