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

[JENKINS-34122] Exclude output file from itself #18

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected Void run() throws Exception {
listener.getLogger().println("Writing zip file of " + source.getRemote()
+ " filtered by [" + step.getGlob() + "] to " + destination.getRemote());
}
int count = source.act(new ZipItFileCallable(destination, step.getGlob()));
int count = source.act(new ZipItFileCallable(destination, step.getGlob(), step.getZipFile()));
listener.getLogger().println("Zipped " + count + " entries.");
if (step.isArchive()) {
listener.getLogger().println("Archiving " + destination.getRemote());
Expand All @@ -112,16 +112,19 @@ protected Void run() throws Exception {
static class ZipItFileCallable extends MasterToSlaveFileCallable<Integer> {
final FilePath zipFile;
final String glob;
private final String zipFileName;

public ZipItFileCallable(FilePath zipFile, String glob) {
public ZipItFileCallable(FilePath zipFile, String glob, String zipFileName) {
this.zipFile = zipFile;
this.glob = StringUtils.isBlank(glob) ? "**/*" : glob;
this.zipFileName = zipFileName;
Copy link
Member

Choose a reason for hiding this comment

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

isn;t this just zipFile.getName()?

Copy link
Member

Choose a reason for hiding this comment

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

what if you are writing a zip file in /foo/bar/wibble/zip.zip and you are archiving /bob/jane/freddy which contains a file called zip.zip - but not the same zip.zip as you are writing to?

Copy link
Member Author

Choose a reason for hiding this comment

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

zipFile.getName() wouldn't return the correct value. If you zip to test/archive.zip, then zipFile.getName() is archive and is not excluded correctly from the FileSet.

Copy link
Member

Choose a reason for hiding this comment

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

Hence I think we need to find a way to exclude a specific absolute path, so that it can work in all occations.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm trying to make a unit test with @jtnord scenario, but either my changeset doesn't introduce this regression, or I didn't reproduce the scenario correctly.

Copy link
Member

Choose a reason for hiding this comment

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

not needed use zipFile.getRemote()

Copy link
Member

Choose a reason for hiding this comment

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

I think that if you add the full path to the exclude list you should be safe.

Copy link
Member Author

Choose a reason for hiding this comment

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

for the same reason I've told to @jtnord, the FileSet contains relative paths to file which should be added to the zip. Using zipFile.getName() or zipFile.getRemote() wouldn't return a value which would properly exclude the file from itself

Copy link
Member Author

Choose a reason for hiding this comment

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

you can try to change this.zipFileName = zipFileName by this.zipFileName = zipFile.getRemote() or zipFile.getName() and you can see that it is not excluded correctly.

}

@Override
public Integer invoke(File dir, VirtualChannel channel) throws IOException, InterruptedException {
Archiver archiver = ArchiverFactory.ZIP.create(zipFile.write());
FileSet fs = Util.createFileSet(dir, glob);
fs.setExcludes(zipFileName);
Copy link
Member

@jtnord jtnord Oct 12, 2016

Choose a reason for hiding this comment

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

at this point you must know where the zipFile is so must know its full canonical location and hence its absolute path.
on line 128 you know (or can obtain) the absolute path to the file you are about to add.

You just need to check that the canonical files location are not the same before calling archiver.visit.

DirectoryScanner scanner = fs.getDirectoryScanner(new org.apache.tools.ant.Project());
try {
for (String path : scanner.getIncludedFiles()) {
Expand Down