Browse Source

Tests for bug 25181

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276536 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 21 years ago
parent
commit
c012d33f03
3 changed files with 83 additions and 16 deletions
  1. +49
    -2
      src/etc/testcases/taskdefs/optional/unix/symlink.xml
  2. +20
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java
  3. +14
    -12
      src/testcases/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java

+ 49
- 2
src/etc/testcases/taskdefs/optional/unix/symlink.xml View File

@@ -104,6 +104,8 @@
Link: ${tdir}/symtest1/symtest2/link3==> Link: ${tdir}/symtest1/symtest2/link3==>
${tdir}/symtest1/symtest2/file2 ${tdir}/symtest1/symtest2/file2
Link: ${tdir}/symtest1/dirlink==>${tdir}/symtest1/symtest3 Link: ${tdir}/symtest1/dirlink==>${tdir}/symtest1/symtest3
Link: ${tdir}/symtest1/dirlink2==>${tdir}/symtest1/symtest3
Link: ${tdir}/symtest1/dirlink3==>${tdir}/symtest1/symtest3
File: ${tdir}/symtest1/recorded.links File: ${tdir}/symtest1/recorded.links
File: ${tdir}/symtest1/symtest2/recorded.links File: ${tdir}/symtest1/symtest2/recorded.links
Deletes: Deletes:
@@ -134,6 +136,12 @@
<symlink resource="${tdir}/symtest1/symtest3" <symlink resource="${tdir}/symtest1/symtest3"
link="${tdir}/symtest1/dirlink" link="${tdir}/symtest1/dirlink"
failonerror="no" /> failonerror="no" />
<symlink resource="${tdir}/symtest1/symtest3"
link="${tdir}/symtest1/dirlink2"
failonerror="no"/>
<symlink resource="${tdir}/symtest1/symtest3"
link="${tdir}/symtest1/dirlink3"
failonerror="no"/>


<sleep seconds="${delay}"/> <!-- make sure OS has time to catch up --> <sleep seconds="${delay}"/> <!-- make sure OS has time to catch up -->


@@ -188,6 +196,11 @@
<available file="${tdir}/symtest1/dirlink" <available file="${tdir}/symtest1/dirlink"
property="test.record.dirlink.created"/> property="test.record.dirlink.created"/>


<!-- this is redundant for this test, but used in the recreate test -->

<available file="${tdir}/symtest1/dirlink2"
property="test.record.dirlink2.created"/>

<!-- Test to see if the linkfiles were created --> <!-- Test to see if the linkfiles were created -->


<available file="${tdir}/symtest1/recorded.links" <available file="${tdir}/symtest1/recorded.links"
@@ -213,14 +226,26 @@
Link: ${tdir}/symtest1/link2==>${tdir}/symtest1/symtest2/file2 Link: ${tdir}/symtest1/link2==>${tdir}/symtest1/symtest2/file2
Link: ${tdir}/symtest1/symtest2/link3==> Link: ${tdir}/symtest1/symtest2/link3==>
${tdir}/symtest1/symtest2/file2 ${tdir}/symtest1/symtest2/file2
Link: ${tdir}/sumtest1/dirlink==>${tdir}/symtest1/symtest3
Link: ${tdir}/symtest1/dirlink==>${tdir}/symtest1/symtest3
Link: ${tdir}/symtest1/dirlink3==>${tdir}/symtest1/symtest3

Creates
Link: ${tdir}/symtest1/dirlink3==>${tdir}/symtest1/symtest2


Recreates: Recreates:
Link: ${tdir}/symtest1/link1==>${tdir}/symtest1/file1 Link: ${tdir}/symtest1/link1==>${tdir}/symtest1/file1
Link: ${tdir}/symtest1/link2==>${tdir}/symtest1/symtest2/file2 Link: ${tdir}/symtest1/link2==>${tdir}/symtest1/symtest2/file2
Link: ${tdir}/symtest1/symtest2/link3==> Link: ${tdir}/symtest1/symtest2/link3==>
${tdir}/symtest1/symtest2/file2 ${tdir}/symtest1/symtest2/file2
Link: ${tdir}/sumtest1/dirlink==>${tdir}/symtest1/symtest3
Link: ${tdir}/symtest1/dirlink==>${tdir}/symtest1/symtest3

Should Change:
Link: ${tdir}/symtest1/dirlink3==>${tdir}/symtest1/symtest2
to
${tdir}/symtest1/dirlink3==>${tdir}/symtest1/symtest3

Should Not Create (bug 25181):
Link: ${tdir}/symtest1/symtest3/dirlink2==>${tdir}/symtest1/symtest3
--> -->


<target name="test-recreate" depends="test-record"> <target name="test-recreate" depends="test-record">
@@ -229,6 +254,16 @@
<symlink action="delete" link="${tdir}/symtest1/link2"/> <symlink action="delete" link="${tdir}/symtest1/link2"/>
<symlink action="delete" link="${tdir}/symtest1/symtest2/link3"/> <symlink action="delete" link="${tdir}/symtest1/symtest2/link3"/>
<symlink action="delete" link="${tdir}/symtest1/dirlink"/> <symlink action="delete" link="${tdir}/symtest1/dirlink"/>
<!-- dirlink2 intentionally not deleted to test bug 25181 -->
<symlink action="delete" link="${tdir}/symtest1/dirlink3"/>

<sleep seconds="${delay}"/> <!-- make sure OS has time to catch up -->

<symlink resource="${tdir}/symtest1/symtest2"
link="${tdir}/symtest1/dirlink3"
failonerror="no"/>

<sleep seconds="${delay}"/> <!-- make sure OS has time to catch up -->


<available file="${tdir}/symtest1/link1" <available file="${tdir}/symtest1/link1"
property="test.recreate.link1.not.removed" property="test.recreate.link1.not.removed"
@@ -265,6 +300,18 @@


<available file="${tdir}/symtest1/dirlink" <available file="${tdir}/symtest1/dirlink"
property="test.recreate.dirlink.recreated"/> property="test.recreate.dirlink.recreated"/>

<!-- this should not get set -->
<available file="${tdir}/symtest1/symtest3/symtest3"
property="test.recreate.dirlink2.recreated.twice"
value="ERROR: dirlink2 was created a second time (bug 25181)"/>

<touch file="${tdir}/symtest1/dirlink3/WhereAmI"/>

<sleep seconds="${delay}"/> <!-- make sure OS has time to do the execs -->

<available file="${tdir}/symtest1/symtest3/WhereAmI"
property="test.recreate.dirlink3.was.altered"/>
</target> </target>






+ 20
- 2
src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java View File

@@ -160,7 +160,26 @@ public class Symlink extends Task {
while (keys.hasMoreElements()) { while (keys.hasMoreElements()) {
link = (String) keys.nextElement(); link = (String) keys.nextElement();
resource = listOfLinks.getProperty(link); resource = listOfLinks.getProperty(link);
doLink(resource, link);
// handle the case where the link exists
// and points to a directory (bug 25181)
try {
FileUtils fu = FileUtils.newFileUtils();
File test = new File(link);
File testRes = new File(resource);
if (!fu.isSymbolicLink(test.getParentFile(),
test.getName())) {
doLink(resource, link);
} else {
if (!test.getCanonicalPath().
equals(testRes.getCanonicalPath())) {
Symlink.deleteSymlink(link);
doLink(resource,link);
} // else the link exists, do nothing
}
} catch (IOException ioe) {
handleError("IO exception while creating "
+ "link");
}
} }
} else if (action.equals("record")) { } else if (action.equals("record")) {
Vector vectOfLinks; Vector vectOfLinks;
@@ -735,7 +754,6 @@ public class Symlink extends Task {
keys = propTemp.keys(); keys = propTemp.keys();
propTemp.list(System.out); propTemp.list(System.out);
// Write the contents to our master list of links // Write the contents to our master list of links

// This method assumes that all links are defined in // This method assumes that all links are defined in
// terms of absolute paths, or paths relative to the // terms of absolute paths, or paths relative to the
// working directory // working directory


+ 14
- 12
src/testcases/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java View File

@@ -47,7 +47,6 @@ public class SymlinkTest extends BuildFileTest {


private Project p; private Project p;
private boolean supportsSymlinks = Os.isFamily("unix"); private boolean supportsSymlinks = Os.isFamily("unix");
private boolean testfail = false;


public SymlinkTest(String name) { public SymlinkTest(String name) {
super(name); super(name);
@@ -62,7 +61,6 @@ public class SymlinkTest extends BuildFileTest {




public void testSingle() { public void testSingle() {
testfail = true;
if (supportsSymlinks) { if (supportsSymlinks) {
executeTarget("test-single"); executeTarget("test-single");
p = getProject(); p = getProject();
@@ -71,11 +69,9 @@ public class SymlinkTest extends BuildFileTest {
assertNotNull("Failed to create link", assertNotNull("Failed to create link",
p.getProperty("test.single.link.created")); p.getProperty("test.single.link.created"));
} }
testfail = false;
} }


public void testDelete() { public void testDelete() {
testfail = true;
if (supportsSymlinks) { if (supportsSymlinks) {
executeTarget("test-delete"); executeTarget("test-delete");
p = getProject(); p = getProject();
@@ -86,11 +82,9 @@ public class SymlinkTest extends BuildFileTest {
fail(linkDeleted); fail(linkDeleted);
} }
} }
testfail = false;
} }


public void testRecord() { public void testRecord() {
testfail = true;
if (supportsSymlinks) { if (supportsSymlinks) {
executeTarget("test-record"); executeTarget("test-record");
p = getProject(); p = getProject();
@@ -128,6 +122,9 @@ public class SymlinkTest extends BuildFileTest {
assertNotNull("Failed to create dirlink", assertNotNull("Failed to create dirlink",
p.getProperty("test.record.dirlink.created")); p.getProperty("test.record.dirlink.created"));


assertNotNull("Failed to create dirlink2",
p.getProperty("test.record.dirlink2.created"));

assertNotNull("Couldn't record links in dir1", assertNotNull("Couldn't record links in dir1",
p.getProperty("test.record.dir1.recorded")); p.getProperty("test.record.dir1.recorded"));


@@ -141,11 +138,9 @@ public class SymlinkTest extends BuildFileTest {
} }


} }
testfail = false;
} }


public void testRecreate() { public void testRecreate() {
testfail = true;
if (supportsSymlinks) { if (supportsSymlinks) {
executeTarget("test-recreate"); executeTarget("test-recreate");
p = getProject(); p = getProject();
@@ -173,14 +168,21 @@ public class SymlinkTest extends BuildFileTest {
p.getProperty("test.recreate.link3.recreated")); p.getProperty("test.recreate.link3.recreated"));
assertNotNull("Failed to recreate dirlink", assertNotNull("Failed to recreate dirlink",
p.getProperty("test.recreate.dirlink.recreated")); p.getProperty("test.recreate.dirlink.recreated"));
String doubleRecreate = p.getProperty("test.recreate.dirlink2.recreated.twice");

if (doubleRecreate != null) {
fail(doubleRecreate);
}

assertNotNull("Failed to alter dirlink3",
p.getProperty("test.recreate.dirlink3.was.altered"));

} }
testfail = false;
} }


public void tearDown() { public void tearDown() {
if (supportsSymlinks && !testfail) {
executeTarget("teardown");
}
executeTarget("teardown");
} }


} }

Loading…
Cancel
Save