Skip to content

Throw specific exception when creating empty archive using single file archiver #61

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

Closed
wants to merge 2 commits into from
Closed

Throw specific exception when creating empty archive using single file archiver #61

wants to merge 2 commits into from

Conversation

plamentotev
Copy link
Member

@plamentotev plamentotev commented May 27, 2017

With the merge of #51 EmptyArchiveException is introduced. But it is thrown only by tar and zip (jar/war etc) archives. Archivers that accpet only single file (such as SnappyArchiver) throw NoSuchElementException.

Closes #52

p.s. This reminds me that there is a lot of duplicated code. BZip2Archiver, GZipArchiver.java & co are practically the same, maybe some day we should refactor them to eliminate the code duplication.

@plamentotev plamentotev changed the title Throw specific exception when creating empty archive with single file archivers Throw specific exception when creating empty archive using single file archivers May 27, 2017
@plamentotev plamentotev changed the title Throw specific exception when creating empty archive using single file archivers Throw specific exception when creating empty archive using single file archiver May 27, 2017
…e archiver

Currently archivers that accept single file (like BZip2Archiver)
will throw `NoSuchElementException`.
Modify them to throw `EmptyArchiveException` so they are
consistent with `TarArchiver` and `ZipArchiver`.
And it makes more sense.
@michael-o
Copy link
Member

The more I think about this, the more I think this need some differentiation. Zip files and directories can be empty, can't they? As for single file like gzip, bz2, xz, snappy, you are right.

@plamentotev
Copy link
Member Author

plamentotev commented May 28, 2017

Yes, as far I know it is perfectly fine to create empty zip or tar file. As a matter of fact there is AbstractZipArchiver#createEmptyZip that does just that. But I think in most cases you don't want to get an empty archive. It is more likely that you'll want to skip the creation of the archive altogether. That being said I think that would be nice to:

  • be able to create empty archive if you really want to (and preferably without the need to call separate method such as createEmptyZip)
  • have a way to check if the archive is going to be empty

Maybe we could add additional flag that indicates if you want to allow the creation of empty archive. allowEmpty (probably not the best name but I think you get the idea). This way we could preserve the current behavior by default and allow more flexibility. Also we could add isEmpty so you could skip the creation of the archive altogether.

Maybe we should have two separate hierarchies for archives (zip, tar, etc) and single compressed files (gzip, bzip2, etc). Things like allowEmpty and isEmpty does not make sense for the latter.

And as a note, while we are discussing empty archives we should include the update mode into consideration as well.

@plamentotev
Copy link
Member Author

plamentotev commented Jun 22, 2017

Maybe I should split this pull request. ZipArchiver and TarArchiverTest are already throwing EmptyArchiveException and it would be nice to have this behavior tested. We could discuss further changes separately. @michael-o what do you think? Does it makes sense?

@michael-o
Copy link
Member

michael-o commented Jun 23, 2017

@plamentotev Yes, this makes sense. I still think that empty tar or zip files are fine and should be configurable, but this is another issue. Please split and I will merge.

@plamentotev
Copy link
Member Author

Closing in favor of #63

@plamentotev plamentotev deleted the handle-creation-of-empty-archives branch June 24, 2017 05:01
@michael-o
Copy link
Member

michael-o commented Jun 24, 2017

@plamentotev I am waiting for the second split PR for the single file archivers. I want to push 3.5 today or tomorrow.

@plamentotev
Copy link
Member Author

@michael-o looks like I misunderstood you about them. Here is the second PR - #64

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