Skip to content

Commit

Permalink
[FIXED JENKINS-13202] Don't set mtime or mode on symlinks
Browse files Browse the repository at this point in the history
Previously, the untar code tries to set the last modified time and mode
on every untarred file.  However, if the tar contains a broken symlink,
or a symlink that points to a file that has not been untarred yet, the
time/mode setting would fail on the broken symlink.

Symlinks don't have meaningful modified times or modes of their own, so
only set these values on non-symlinks.

Rename the file "a" in the test to expose the bug.
  • Loading branch information
dreiss authored and kohsuke committed May 8, 2012
1 parent 005effe commit e15b2e1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion changelog.html
Expand Up @@ -55,7 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=>
<li class=bug>
Artifact archiving from an ssh slave fails if symlinks are present
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-13202">issue 13202</a>)
</ul>
</div><!--=TRUNK-END=-->

Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/hudson/FilePath.java
Expand Up @@ -1812,12 +1812,12 @@ private static void readFromTar(String name, File baseDir, InputStream in) throw
new FilePath(f).symlinkTo(te.getLinkName(), TaskListener.NULL);
} else {
IOUtils.copy(t,f);

f.setLastModified(te.getModTime().getTime());
int mode = te.getMode()&0777;
if(mode!=0 && !Functions.isWindows()) // be defensive
_chmod(f,mode);
}

f.setLastModified(te.getModTime().getTime());
int mode = te.getMode()&0777;
if(mode!=0 && !Functions.isWindows()) // be defensive
_chmod(f,mode);
}
}
} catch(IOException e) {
Expand Down
6 changes: 3 additions & 3 deletions core/src/test/java/hudson/FilePathTest.java
Expand Up @@ -365,16 +365,16 @@ public void testSymlinkInTar() throws Exception {
try {
FilePath in = tmp.child("in");
in.mkdirs();
in.child("a").touch(0);
in.child("b").symlinkTo("a", TaskListener.NULL);
in.child("c").touch(0);
in.child("b").symlinkTo("c", TaskListener.NULL);

FilePath tar = tmp.child("test.tar");
in.tar(tar.write(), "**/*");

FilePath dst = in.child("dst");
tar.untar(dst, TarCompression.NONE);

assertEquals("a",dst.child("b").readLink());
assertEquals("c",dst.child("b").readLink());
} finally {
tmp.deleteRecursive();
}
Expand Down

0 comments on commit e15b2e1

Please sign in to comment.