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

Add contiguous mode to the Builder #234

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

synek317
Copy link

Closes #227

There are many ways to implement this. Here is my proposal, I'm open to any suggestions.

Copy link
Owner

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Perhaps a more descriptive name like "skip_footer_section" or something like that could be used instead of "contiguous" too?

@@ -356,6 +363,14 @@ impl<W: Write> Builder<W> {
self.finished = true;
self.get_mut().write_all(&[0; 1024])
}

fn finalize(&mut self) -> io::Result<()> {
if !self.contiguous {
Copy link
Owner

Choose a reason for hiding this comment

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

Since finish() is a public method, I think that it might be best if this check is folded into there? That can just keep the documentation, though, that it is not required to be called.

Copy link
Author

Choose a reason for hiding this comment

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

I've introduced finalize since I wanted to give the user the possibility to write the 'footer' section, as you can see in the example.

I could move the check to finish and then create public method write_footer_section. Then this:

let mut builder = tar::Builder::new(...);
builder.skip_footer_section(true);
builder.finish();

would have no effect and would need to be transformed into:

let mut builder = tar::Builder::new(...);
builder.skip_footer_section(true);
builder.write_footer_section();

Copy link
Owner

Choose a reason for hiding this comment

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

I think though that this implementation, as-is, doesn't work. If you call finish it ignores the skip_footer_section flag introduced here, which I think is a bug. I think it'd be fine to basically say that finish is optional if skip_footer_section is true.

Copy link
Author

Choose a reason for hiding this comment

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

It does work, please take a look at the example I've added to examples/ or even tests. But I see your point, I will rename contiguous to skip_footer_section and move

self.get_mut().write_all(&[0; 1024]) 

To new public method write_footer_section. Would that work in your opinion?

Copy link
Owner

Choose a reason for hiding this comment

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

Yes while it works I think it's too confusing. I think adding a separate method makes sense. That way there's a flag to disable auto-inclusion of the footer and in that scenario you can either create a tar::Builder at the end with the flag enabled or you can manually call the footer write.

Copy link
Author

@synek317 synek317 left a comment

Choose a reason for hiding this comment

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

Perhaps a more descriptive name like "skip_footer_section" or something like that could be used instead of "contiguous" too?

Indeed, skip_footer_section sounds much more readable. I was checking various tar format descriptions and it seems there is no fancy name for this. The official documentation uses 'end-of-archive entry' which is too long I guess.

@@ -356,6 +363,14 @@ impl<W: Write> Builder<W> {
self.finished = true;
self.get_mut().write_all(&[0; 1024])
}

fn finalize(&mut self) -> io::Result<()> {
if !self.contiguous {
Copy link
Author

Choose a reason for hiding this comment

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

I've introduced finalize since I wanted to give the user the possibility to write the 'footer' section, as you can see in the example.

I could move the check to finish and then create public method write_footer_section. Then this:

let mut builder = tar::Builder::new(...);
builder.skip_footer_section(true);
builder.finish();

would have no effect and would need to be transformed into:

let mut builder = tar::Builder::new(...);
builder.skip_footer_section(true);
builder.write_footer_section();

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.

Add a way to use Builder in append mode, that would not write empty blocks on the end of the archive
2 participants