Skip to content

Commit

Permalink
[FIXED JENKINS-9118]
Browse files Browse the repository at this point in the history
WorkspaceSnapshot now uses the tar.gz format to handle symlinks
correctly.
  • Loading branch information
kohsuke committed Mar 10, 2012
1 parent d184d53 commit 2dd7096
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion changelog.html
Expand Up @@ -56,7 +56,8 @@
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=bug>
tar/untar now correctly handles symlinks.
Workspace archiving wasn't handling symlinks correctly.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-9118">issue 9118</a>)
<li class=bug>
Fixed a bug in the auto-overwrite of bundled plugins on Windows.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-12514">issue 12514</a>)
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/FilePath.java
Expand Up @@ -415,11 +415,11 @@ public Integer invoke(File f, VirtualChannel channel) throws IOException {
});
}

private int archive(final ArchiverFactory factory, OutputStream os, final FileFilter filter) throws IOException, InterruptedException {
public int archive(final ArchiverFactory factory, OutputStream os, final FileFilter filter) throws IOException, InterruptedException {
return archive(factory,os,new DirScanner.Filter(filter));
}

private int archive(final ArchiverFactory factory, OutputStream os, final String glob) throws IOException, InterruptedException {
public int archive(final ArchiverFactory factory, OutputStream os, final String glob) throws IOException, InterruptedException {
return archive(factory,os,new DirScanner.Glob(glob,null));
}

Expand Down
16 changes: 12 additions & 4 deletions core/src/main/java/hudson/FileSystemProvisioner.java
Expand Up @@ -23,13 +23,16 @@
*/
package hudson;

import hudson.FilePath.TarCompression;
import hudson.matrix.MatrixBuild;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Computer;
import hudson.model.Describable;
import hudson.model.Job;
import hudson.model.TaskListener;
import hudson.util.DirScanner.Glob;
import hudson.util.io.ArchiverFactory;
import jenkins.model.Jenkins;
import hudson.model.listeners.RunListener;
import hudson.scm.SCM;
Expand Down Expand Up @@ -211,10 +214,10 @@ public WorkspaceSnapshot snapshot(AbstractBuild<?, ?> build, FilePath ws, TaskLi
* Creates a tar ball.
*/
public WorkspaceSnapshot snapshot(AbstractBuild<?, ?> build, FilePath ws, String glob, TaskListener listener) throws IOException, InterruptedException {
File wss = new File(build.getRootDir(),"workspace.zip");
File wss = new File(build.getRootDir(),"workspace.tgz");
OutputStream os = new BufferedOutputStream(new FileOutputStream(wss));
try {
ws.zip(os,glob);
ws.archive(ArchiverFactory.TARGZ,os,glob);
} finally {
os.close();
}
Expand All @@ -223,8 +226,13 @@ public WorkspaceSnapshot snapshot(AbstractBuild<?, ?> build, FilePath ws, String

public static final class WorkspaceSnapshotImpl extends WorkspaceSnapshot {
public void restoreTo(AbstractBuild<?,?> owner, FilePath dst, TaskListener listener) throws IOException, InterruptedException {
File wss = new File(owner.getRootDir(),"workspace.zip");
new FilePath(wss).unzip(dst);
File zip = new File(owner.getRootDir(),"workspace.zip");
if (zip.exists()) {// we used to keep it in zip
new FilePath(zip).unzip(dst);
} else {// but since 1.456 we do tgz
File tgz = new File(owner.getRootDir(),"workspace.tgz");
new FilePath(tgz).untar(dst, TarCompression.GZIP);
}
}
}

Expand Down

0 comments on commit 2dd7096

Please sign in to comment.