提交 e15b2e19 编写于 作者: D David Reiss 提交者: Kohsuke Kawaguchi

[FIXED JENKINS-13202] Don't set mtime or mode on symlinks

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.
上级 005effe6
...@@ -55,7 +55,9 @@ Upcoming changes</a> ...@@ -55,7 +55,9 @@ Upcoming changes</a>
<!-- Record your changes in the trunk here. --> <!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=--> <div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image> <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> </ul>
</div><!--=TRUNK-END=--> </div><!--=TRUNK-END=-->
......
...@@ -1812,12 +1812,12 @@ public final class FilePath implements Serializable { ...@@ -1812,12 +1812,12 @@ public final class FilePath implements Serializable {
new FilePath(f).symlinkTo(te.getLinkName(), TaskListener.NULL); new FilePath(f).symlinkTo(te.getLinkName(), TaskListener.NULL);
} else { } else {
IOUtils.copy(t,f); 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) { } catch(IOException e) {
......
...@@ -365,8 +365,8 @@ public class FilePathTest extends ChannelTestCase { ...@@ -365,8 +365,8 @@ public class FilePathTest extends ChannelTestCase {
try { try {
FilePath in = tmp.child("in"); FilePath in = tmp.child("in");
in.mkdirs(); in.mkdirs();
in.child("a").touch(0); in.child("c").touch(0);
in.child("b").symlinkTo("a", TaskListener.NULL); in.child("b").symlinkTo("c", TaskListener.NULL);
FilePath tar = tmp.child("test.tar"); FilePath tar = tmp.child("test.tar");
in.tar(tar.write(), "**/*"); in.tar(tar.write(), "**/*");
...@@ -374,7 +374,7 @@ public class FilePathTest extends ChannelTestCase { ...@@ -374,7 +374,7 @@ public class FilePathTest extends ChannelTestCase {
FilePath dst = in.child("dst"); FilePath dst = in.child("dst");
tar.untar(dst, TarCompression.NONE); tar.untar(dst, TarCompression.NONE);
assertEquals("a",dst.child("b").readLink()); assertEquals("c",dst.child("b").readLink());
} finally { } finally {
tmp.deleteRecursive(); tmp.deleteRecursive();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册