Author: stevel
Date: Wed Sep 19 05:29:39 2007
New Revision: 577281
URL:
http://svn.apache.org/viewvc?rev=577281&view=rev
Log:
bugzilla ID 38199, symlink fails on second call
bugzilla ID 43426, <symlink> cant create a symlink
over a file
solution is the same: opt for ln -sf after trying to do it
internally. We could perhaps drop all ant deletion
operations, for a much simpler operation.
Added:
ant/core/trunk/src/tests/antunit/taskdefs/optional/unix/
ant/core/trunk/src/tests/antunit/taskdefs/optional/unix/syml
ink-test.xml
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/option
al/unix/Symlink.java
Modified: ant/core/trunk/WHATSNEW
URL: http://
svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=577281&
;r1=577280&r2=577281&view=diff
============================================================
==================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Wed Sep 19 05:29:39 2007
 -41,6
+41,13 
Fixed bugs:
-----------
+ * <symlink> task couldn't overwrite existing
symlinks that pointed to nonexistent files
+ Bugzilla report 38199
+
+ * <symlink> task couldn't overwrite files that were
in the way of the symlink.
+ Bugzilla report 43426
+
+
Other changes:
--------------
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/option
al/unix/Symlink.java
URL: http://svn
.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/
ant/taskdefs/optional/unix/Symlink.java?rev=577281&r1=57
7280&r2=577281&view=diff
============================================================
==================
---
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/option
al/unix/Symlink.java (original)
+++
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/option
al/unix/Symlink.java Wed Sep 19 05:29:39 2007
 -404,7
+404,7 
* fail.
*/
public static void deleteSymlink(File linkfil)
- throws IOException, FileNotFoundException {
+ throws IOException{
if (!linkfil.exists()) {
throw new FileNotFoundException("No such
symlink: " + linkfil);
}
 -466,6
+466,7 
*
* param msg The message to log, or include in the
*
<code>BuildException</code>.
+ * throws BuildException with the message if
failonerror=true
*/
private void handleError(String msg) {
if (failonerror) {
 -481,20
+482,24 
*
* param res The path of the resource we are linking
to.
* param lnk The name of the link we wish to
make.
+ * throws BuildException when things go wrong
*/
private void doLink(String res, String lnk) throws
BuildException {
File linkfil = new File(lnk);
- if (overwrite && linkfil.exists()) {
- try {
- deleteSymlink(linkfil);
- } catch (FileNotFoundException fnfe) {
- handleError("Symlink disappeared
before it was deleted: " + lnk);
- } catch (IOException ioe) {
- handleError("Unable to overwrite
preexisting link: " + lnk);
+ String options = "-s";
+ if (overwrite) {
+ options += "f";
+ if (linkfil.exists()) {
+ try {
+ deleteSymlink(linkfil);
+ } catch (FileNotFoundException fnfe) {
+ log("Symlink disappeared before it
was deleted: " + lnk);
+ } catch (IOException ioe) {
+ log("Unable to overwrite
preexisting link or file: " + lnk,ioe,
Project.MSG_INFO);
+ }
}
}
- String[] cmd = new String[] {"ln",
"-s", res, lnk};
- log(Commandline.toString(cmd));
+ String[] cmd = new String[] {"ln",
options, res, lnk};
Execute.runCommand(this, cmd);
}
Added:
ant/core/trunk/src/tests/antunit/taskdefs/optional/unix/syml
ink-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/sr
c/tests/antunit/taskdefs/optional/unix/symlink-test.xml?rev=
577281&view=auto
============================================================
==================
---
ant/core/trunk/src/tests/antunit/taskdefs/optional/unix/syml
ink-test.xml (added)
+++
ant/core/trunk/src/tests/antunit/taskdefs/optional/unix/syml
ink-test.xml Wed Sep 19 05:29:39 2007
 -0,0
+1,55 
+<?xml version="1.0"
encoding="utf-8"?>
+<project name="symlink-test"
+ default="antunit"
xmlns:au="antlib:org.apache.ant.antunit">
+ <import
file="../../../antunit-base.xml"/>
+
+ <property name="build.dir"
location="build" />
+
+ <target name="setUp">
+ <condition property="isUnix">
+ <os family="unix" />
+ </condition>
+ </target>
+
+ <target name="os">
+
+ <mkdir dir="${build.dir}" />
+ <condition property="unix">
+ <os family="unix" />
+ </condition>
+ <property name="file_ref"
+ location="${build.dir}/file"/>
+ <property name="hanging_ref"
+ location="${build.dir}/hanging_ref"/>
+ </target>
+
+ <target name="init" depends="os"
if="unix">
+ <touch file="$" />
+ </target>
+
+ <target name="tearDown">
+ <delete dir="${build.dir}" />
+ </target>
+
+ <target name="testCreateDouble"
depends="init" if="unix">
+ <symlink overwrite="true"
link="${build.dir}/link"
+ resource="$"/>
+ <symlink overwrite="true"
link="${build.dir}/link"
+ resource="$"/>
+ </target>
+
+
+ <target name="testCreateDoubleHanging"
depends="init" if="unix">
+ <symlink overwrite="true"
link="${build.dir}/link2"
+ resource="$"/>
+ <symlink overwrite="true"
link="${build.dir}/link2"
+ resource="$"/>
+ </target>
+
+ <target name="testCreateOverFile"
depends="init" if="unix">
+ <touch file="${build.dir}/link3" />
+ <symlink overwrite="true"
link="${build.dir}/link3"
+ resource="$"/>
+ </target>
+
+</project>
No newline at end of file
------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribe ant.apache.org
For additional commands, e-mail: dev-help ant.apache.org
|