Skip to content

[JENKINS-42591] && [JENKINS-47060] Add overwrite option to zip step. #76

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

Merged
merged 4 commits into from
Jun 26, 2020

Conversation

fabiodcasilva
Copy link
Contributor

Added the possibility to overwrite the zip file in cases where the destination file already exists.

Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

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

Looks good to me, just a few minor comments. Thanks for the patch!
It will still need review from plugin maintainers to be released

String canonicalZip = new File(zipFile.getRemote()).getCanonicalPath();
File zip = new File(zipFile.getRemote());
if (overwrite && zip.exists()) {
if (!zip.delete()) {
Copy link
Member

Choose a reason for hiding this comment

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

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 changed it to the api you suggested.
@oleg-nenashev can you check if it is as expected?
Thank you very much


f.entry(field: 'overwrite', title: _('Overwrite')) {
f.checkbox()
}
Copy link
Member

Choose a reason for hiding this comment

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

Just a reminder to myself that all the optional arguments should be put behind an advanced section.

}

@Override
public Integer invoke(File dir, VirtualChannel channel) throws IOException, InterruptedException {
String canonicalZip = new File(zipFile.getRemote()).getCanonicalPath();
String canonicalZip = zipFile.getRemote();
if (overwrite && !Files.deleteIfExists(Paths.get(canonicalZip))) {
Copy link

Choose a reason for hiding this comment

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

So now it throws the exception (and fails) if the zip does not exist and overwrite=true. Was that intended?

My case: I need the file to be overwritten when it exists + be created when it does not. That used to work without specifying the overwrite flag (which wasn't there obviously)

Copy link
Member

Choose a reason for hiding this comment

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

No, that sounds a bit weird indeed. 🤔

Choose a reason for hiding this comment

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

This seems like a bug

Choose a reason for hiding this comment

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

I am thinking the only workaround for now is to check if file exists before attempting to zip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants