-
Notifications
You must be signed in to change notification settings - Fork 166
[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
Conversation
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.
Looks good to me, just a few minor comments. Thanks for the patch!
It will still need review from plugin maintainers to be released
src/main/resources/org/jenkinsci/plugins/pipeline/utility/steps/zip/ZipStep/help-overwrite.html
Outdated
Show resolved
Hide resolved
String canonicalZip = new File(zipFile.getRemote()).getCanonicalPath(); | ||
File zip = new File(zipFile.getRemote()); | ||
if (overwrite && zip.exists()) { | ||
if (!zip.delete()) { |
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.
https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#delete-java.nio.file.Path- would be a better File management API
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 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() | ||
} |
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.
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))) { |
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.
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)
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.
No, that sounds a bit weird indeed. 🤔
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 seems like a bug
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 am thinking the only workaround for now is to check if file exists before attempting to zip.
Added the possibility to overwrite the zip file in cases where the destination file already exists.