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 - 73837] Changing DirScanner to allow empty directories in TARArchiver #10114

Closed
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions core/src/main/java/hudson/util/DirScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ public void scan(File dir, FileVisitor visitor) throws IOException {
File file = new File(dir, f);
scanSingle(file, f, visitor);
}
for (String d : ds.getIncludedDirectories()) {
if (!d.isEmpty()) {
File directory = new File(dir, d);
scanSingle(directory, d, visitor);
}
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/jenkins/util/VirtualFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,8 @@ public Collection<String> call() throws IOException {

private static void collectFiles(VirtualFile d, Collection<String> names, String prefix) throws IOException {
for (VirtualFile child : d.list()) {
if (child.isFile()) {
names.add(prefix + child.getName());
} else if (child.isDirectory()) {
names.add(prefix + child.getName());
if (child.isDirectory()) {
collectFiles(child, names, prefix + child.getName() + "/");
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/hudson/FilePathTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ public void testEOFbrokenFlush() throws IOException, InterruptedException {
// Compress archive
final FilePath tmpDirPath = new FilePath(srcFolder);
int tarred = tmpDirPath.tar(Files.newOutputStream(archive.toPath()), "**");
assertEquals("One file should have been compressed", 3, tarred);
assertEquals("One file should have been compressed", 4, tarred);

// Decompress
final File dstFolder = temp.newFolder("dst");
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/hudson/util/io/TarArchiverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private static void run(FilePath dir, String... cmds) throws InterruptedExceptio
}
}

@Ignore("TODO fails to add empty directories to archive")
//@Ignore("TODO fails to add empty directories to archive")
@Issue("JENKINS-73837")
@Test
public void emptyDirectory() throws Exception {
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/hudson/util/io/ZipArchiverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void huge64bitFile() throws IOException {
}
}

@Ignore("TODO fails to add empty directories to archive")
//@Ignore("TODO fails to add empty directories to archive")
@Issue("JENKINS-49296")
@Test
public void emptyDirectory() throws Exception {
Expand Down
42 changes: 27 additions & 15 deletions core/src/test/java/jenkins/util/VirtualFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ private static String modeString(int mode) throws IOException {
System.err.println("testing " + vf.getClass().getName());
assertEquals("[.hg/config.txt, sub/mid.txt, sub/subsub/lowest.txt, top.txt]", new TreeSet<>(vf.list("**/*.txt", null, false)).toString());
assertEquals("[sub/mid.txt, sub/subsub/lowest.txt, top.txt]", new TreeSet<>(vf.list("**/*.txt", null, true)).toString());
assertEquals("[.hg/config.txt, sub/mid.txt, sub/subsub/lowest.txt, top.txt, very/deep/path/here]", new TreeSet<>(vf.list("**", null, false)).toString());
assertEquals("[.hg, .hg/config.txt, sub, sub/mid.txt, sub/subsub, sub/subsub/lowest.txt, top.txt, very, very/deep, very/deep/path, very/deep/path/here]", new TreeSet<>(vf.list("**", null, false)).toString());
assertEquals("[]", new TreeSet<>(vf.list("", null, false)).toString());
assertEquals("[sub/mid.txt, sub/subsub/lowest.txt]", new TreeSet<>(vf.list("sub/", null, false)).toString());
assertEquals("[sub/mid.txt]", new TreeSet<>(vf.list("sub/", "sub/subsub/", false)).toString());
assertEquals("[sub/mid.txt]", new TreeSet<>(vf.list("sub/", "sub/subsub/**", false)).toString());
assertEquals("[sub/mid.txt]", new TreeSet<>(vf.list("sub/", "**/subsub/", false)).toString());
assertEquals("[sub, sub/mid.txt, sub/subsub, sub/subsub/lowest.txt]", new TreeSet<>(vf.list("sub/", null, false)).toString());
assertEquals("[sub, sub/mid.txt]", new TreeSet<>(vf.list("sub/", "sub/subsub/", false)).toString());
assertEquals("[sub, sub/mid.txt]", new TreeSet<>(vf.list("sub/", "sub/subsub/**", false)).toString());
assertEquals("[sub, sub/mid.txt]", new TreeSet<>(vf.list("sub/", "**/subsub/", false)).toString());
assertEquals("[.hg/config.txt, sub/mid.txt]", new TreeSet<>(vf.list("**/mid*,**/conf*", null, false)).toString());
assertEquals("[sub/mid.txt, sub/subsub/lowest.txt]", new TreeSet<>(vf.list("sub/", "**/notthere/", false)).toString());
assertEquals("[sub, sub/mid.txt, sub/subsub, sub/subsub/lowest.txt]", new TreeSet<>(vf.list("sub/", "**/notthere/", false)).toString());
assertEquals("[top.txt]", new TreeSet<>(vf.list("*.txt", null, false)).toString());
assertEquals("[sub/subsub/lowest.txt, top.txt, very/deep/path/here]", new TreeSet<>(vf.list("**", "**/mid*,**/conf*", false)).toString());
assertEquals("[.hg, sub, sub/subsub, sub/subsub/lowest.txt, top.txt, very, very/deep, very/deep/path, very/deep/path/here]", new TreeSet<>(vf.list("**", "**/mid*,**/conf*", false)).toString());
}
}
/** Roughly analogous to {@code org.jenkinsci.plugins.compress_artifacts.ZipStorage}. */
Expand Down Expand Up @@ -240,7 +240,13 @@ public void list_Glob_NoFollowLinks_FileVF() throws Exception {
assertThat(children, containsInAnyOrder(
"a/aa/aa.txt",
"a/ab/ab.txt",
"b/ba/ba.txt"
"b/ba/ba.txt",
"a",
"a/aa",
"a/aa/aaa",
"a/ab",
"b",
"b/ba"
));
}

Expand All @@ -256,7 +262,13 @@ public void list_Glob_NoFollowLinks_FilePathVF() throws Exception {
assertThat(children, containsInAnyOrder(
"a/aa/aa.txt",
"a/ab/ab.txt",
"b/ba/ba.txt"
"b/ba/ba.txt",
"a",
"a/aa",
"a/aa/aaa",
"a/ab",
"b",
"b/ba"
));
}

Expand All @@ -281,7 +293,7 @@ public void zip_NoFollowLinks_FilePathVF() throws Exception {
assertTrue(unzipPath.isDirectory());
assertTrue(unzipPath.child("a").child("aa").child("aa.txt").exists());
assertTrue(unzipPath.child("a").child("ab").child("ab.txt").exists());
assertFalse(unzipPath.child("a").child("aa").child("aaa").exists());
assertTrue(unzipPath.child("a").child("aa").child("aaa").exists());
assertFalse(unzipPath.child("a").child("_b").exists());
assertTrue(unzipPath.child("b").child("ba").child("ba.txt").exists());
assertFalse(unzipPath.child("b").child("_a").exists());
Expand Down Expand Up @@ -311,7 +323,7 @@ public void zip_NoFollowLinks_FilePathVF_withPrefix() throws Exception {
assertTrue(unzipPath.child(prefix).isDirectory());
assertTrue(unzipPath.child(prefix).child("a").child("aa").child("aa.txt").exists());
assertTrue(unzipPath.child(prefix).child("a").child("ab").child("ab.txt").exists());
assertFalse(unzipPath.child(prefix).child("a").child("aa").child("aaa").exists());
assertTrue(unzipPath.child(prefix).child("a").child("aa").child("aaa").exists());
assertFalse(unzipPath.child(prefix).child("a").child("_b").exists());
assertTrue(unzipPath.child(prefix).child("b").child("ba").child("ba.txt").exists());
assertFalse(unzipPath.child(prefix).child("b").child("_a").exists());
Expand Down Expand Up @@ -339,7 +351,7 @@ public void zip_NoFollowLinks_FileVF() throws Exception {
assertTrue(unzipPath.isDirectory());
assertTrue(unzipPath.child("a").child("aa").child("aa.txt").exists());
assertTrue(unzipPath.child("a").child("ab").child("ab.txt").exists());
assertFalse(unzipPath.child("a").child("aa").child("aaa").exists());
assertTrue(unzipPath.child("a").child("aa").child("aaa").exists());
assertFalse(unzipPath.child("a").child("_b").exists());
assertTrue(unzipPath.child("b").child("ba").child("ba.txt").exists());
assertFalse(unzipPath.child("b").child("_a").exists());
Expand Down Expand Up @@ -369,7 +381,7 @@ public void zip_NoFollowLinks_FileVF_withPrefix() throws Exception {
assertTrue(unzipPath.child(prefix).isDirectory());
assertTrue(unzipPath.child(prefix).child("a").child("aa").child("aa.txt").exists());
assertTrue(unzipPath.child(prefix).child("a").child("ab").child("ab.txt").exists());
assertFalse(unzipPath.child(prefix).child("a").child("aa").child("aaa").exists());
assertTrue(unzipPath.child(prefix).child("a").child("aa").child("aaa").exists());
assertFalse(unzipPath.child(prefix).child("a").child("_b").exists());
assertTrue(unzipPath.child(prefix).child("b").child("ba").child("ba.txt").exists());
assertFalse(unzipPath.child(prefix).child("b").child("_a").exists());
Expand Down Expand Up @@ -504,7 +516,7 @@ public void list_Glob_NoFollowLinks_ExternalSymlink_FilePathVF() throws Exceptio
VirtualFile symlinkVirtualPath = VirtualFile.forFilePath(symlinkPath);
VirtualFile symlinkChildVirtualPath = symlinkVirtualPath.child("aa");
Collection<String> children = symlinkChildVirtualPath.list("**", null, true, LinkOption.NOFOLLOW_LINKS);
assertThat(children, contains("aa.txt"));
assertThat(children, containsInAnyOrder("aa.txt", "aaa"));
}

@Test
Expand All @@ -519,7 +531,7 @@ public void list_Glob_NoFollowLinks_ExternalSymlink_FileVF() throws Exception {
VirtualFile symlinkVirtualFile = VirtualFile.forFile(symlinkFile);
VirtualFile symlinkChildVirtualFile = symlinkVirtualFile.child("aa");
Collection<String> children = symlinkChildVirtualFile.list("**", null, true, LinkOption.NOFOLLOW_LINKS);
assertThat(children, contains("aa.txt"));
assertThat(children, containsInAnyOrder("aa.txt", "aaa"));
}

@Test
Expand Down
Loading