Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoranyssen2015-11-18 14:08:40 +0000
committerJan Sievers2015-11-20 09:20:43 +0000
commit309fbd05d46510671218ef2863885b48a12d8451 (patch)
treef4cc641393f0db819b80e9379335b05e5ed73aed
parentbd715d9dc044256e9298a8b71cbab2b910f6623c (diff)
downloadorg.eclipse.tycho-309fbd05d46510671218ef2863885b48a12d8451.tar.gz
org.eclipse.tycho-309fbd05d46510671218ef2863885b48a12d8451.tar.xz
org.eclipse.tycho-309fbd05d46510671218ef2863885b48a12d8451.zip
Bug 482469: Ensure TarGzArchiver can handle directory symlinks.
Ensure TarGzArchiver.addToTarRecursively() does not descent into those directory symlinks whose target is contained below the tar root folder. Add a test to TarGzArchiverTest to check for correct behavior. Change-Id: I4ca9e24e8441b0dbc1c41d193529799995820f6a Signed-off-by: anyssen <alexander.nyssen@itemis.de>
-rw-r--r--tycho-p2/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java3
-rw-r--r--tycho-p2/tycho-p2-director-plugin/src/test/java/org/eclipse/tycho/plugins/tar/TarGzArchiverTest.java24
2 files changed, 26 insertions, 1 deletions
diff --git a/tycho-p2/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java b/tycho-p2/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java
index e1dcf9f82..515faa71f 100644
--- a/tycho-p2/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java
+++ b/tycho-p2/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java
@@ -7,6 +7,7 @@
*
* Contributors:
* SAP SE - initial API and implementation
+ * Alexander Nyßen (itemis AG) - Fix for bug #482469
*******************************************************************************/
package org.eclipse.tycho.plugins.tar;
@@ -104,7 +105,7 @@ public class TarGzArchiver {
copyFileContentToTarStream(source, tarStream);
}
tarStream.closeArchiveEntry();
- if (source.isDirectory()) {
+ if (source.isDirectory() && (!tarEntry.isSymbolicLink() || !resolvesBelow(source, tarRootDir))) {
File[] children = source.listFiles();
if (children != null) {
for (File child : children) {
diff --git a/tycho-p2/tycho-p2-director-plugin/src/test/java/org/eclipse/tycho/plugins/tar/TarGzArchiverTest.java b/tycho-p2/tycho-p2-director-plugin/src/test/java/org/eclipse/tycho/plugins/tar/TarGzArchiverTest.java
index a9730214e..cb6d31740 100644
--- a/tycho-p2/tycho-p2-director-plugin/src/test/java/org/eclipse/tycho/plugins/tar/TarGzArchiverTest.java
+++ b/tycho-p2/tycho-p2-director-plugin/src/test/java/org/eclipse/tycho/plugins/tar/TarGzArchiverTest.java
@@ -7,6 +7,7 @@
*
* Contributors:
* SAP SE - initial API and implementation
+ * Alexander Nyßen (itemis AG) - Fix for bug #482469
*******************************************************************************/
package org.eclipse.tycho.plugins.tar;
@@ -129,6 +130,16 @@ public class TarGzArchiverTest {
}
@Test
+ public void testRelativeSymbolicLinkToFolderWithinArchivePreserved() throws Exception {
+ createSymbolicLink(new File(archiveRoot, "dir2/testSymLink"), Paths.get("../"));
+ archiver.createArchive();
+ TarArchiveEntry symLinkEntry = getTarEntries().get("dir2/testSymLink");
+ assertTrue(symLinkEntry.isSymbolicLink());
+ assertEquals("..", symLinkEntry.getLinkName());
+ assertEquals("Expect 8 entries in the archive", 8, getTarEntries().size());
+ }
+
+ @Test
public void testSymbolicLinkAbsoluteTargetConvertedToRelative() throws Exception {
// use absolute path as symlink target
Path absoluteLinkTarget = new File(archiveRoot, "dir2/dir3/test.sh").getAbsoluteFile().toPath();
@@ -154,6 +165,19 @@ public class TarGzArchiverTest {
}
@Test
+ public void testSymbolicLinkToDirOutsideArchiveInlined() throws Exception {
+ File linkTargetDir = tempFolder.newFolder("dirLinkTargetOutsideArchiveRoot");
+ FileUtils.fileWrite(new File(linkTargetDir, "test.txt"), "testContent");
+ createSymbolicLink(new File(archiveRoot, "testDirSymLink"), linkTargetDir.toPath());
+ archiver.createArchive();
+ TarArchiveEntry inlinedSymLinkEntry = getTarEntries().get("testDirSymLink/");
+ assertFalse(inlinedSymLinkEntry.isSymbolicLink());
+ assertTrue(inlinedSymLinkEntry.isDirectory());
+ String content = new String(getTarEntry("testDirSymLink/test.txt"), "UTF-8");
+ assertEquals("testContent", content);
+ }
+
+ @Test
public void testLongPathEntry() throws Exception {
final String longPath = "very/long/path/exceeding/100/chars/very/long/path/exceeding/100/chars/very/long/path/exceeding/100/chars/test.txt";
File longPathFile = new File(archiveRoot, longPath);

Back to the top