ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r692117 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java
Date Thu, 04 Sep 2008 15:48:02 GMT
Author: bodewig
Date: Thu Sep  4 08:48:01 2008
New Revision: 692117

URL: http://svn.apache.org/viewvc?rev=692117&view=rev
Log:
whitespace and javadocs

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java?rev=692117&r1=692116&r2=692117&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java Thu Sep
 4 08:48:01 2008
@@ -375,6 +375,8 @@
      *                                   <code>File</code> that doesn't exist.
      * @throws IOException             If calls to <code>File.rename</code>
      *                                   or <code>File.delete</code> fail.
+     * @deprecated use the two-arg version which also works if the link's
+     *             target can not be renamed.
      */
     public static void deleteSymlink(String path)
         throws IOException, FileNotFoundException {
@@ -388,11 +390,13 @@
      * <code>deleteSymlink(java.io.File)</code>.
      *
      * @param path    A string containing the path of the symlink to delete.
+     * @param task       An Ant Task required if "rm" needs to be invoked.
      *
      * @throws FileNotFoundException   When the path results in a
      *                                   <code>File</code> that doesn't exist.
      * @throws IOException             If calls to <code>File.rename</code>
      *                                   or <code>File.delete</code> fail.
+     * @since Ant 1.8.0
      */
     public static void deleteSymlink(String path, Task t)
         throws IOException, FileNotFoundException {
@@ -458,6 +462,7 @@
      *                                   <code>File.delete</code> or
      *                                   <code>File.getCanonicalPath</code>
      *                                   fail.
+     * @since Ant 1.8.0
      */
     public static void deleteSymlink(File linkfil, Task task)
         throws IOException {
@@ -475,47 +480,51 @@
 
         if (task == null || canfil.getParentFile().canWrite()) {
 
-        // rename the resource, thus breaking the link:
-        File temp = FILE_UTILS.createTempFile("symlink", ".tmp",
-                                              canfil.getParentFile(), false,
-                                              false);
-
-        if (FILE_UTILS.isLeadingPath(canfil, linkfil)) {
-            // link points to a parent directory, renaming the parent
-            // will rename the file
-            linkfil = new File(temp,
-                               FILE_UTILS.removeLeadingPath(canfil, linkfil));
-        }
+            // rename the resource, thus breaking the link:
+            File temp = FILE_UTILS.createTempFile("symlink", ".tmp",
+                                                  canfil.getParentFile(), false,
+                                                  false);
+
+            if (FILE_UTILS.isLeadingPath(canfil, linkfil)) {
+                // link points to a parent directory, renaming the parent
+                // will rename the file
+                linkfil = new File(temp,
+                                   FILE_UTILS.removeLeadingPath(canfil,
+                                                                linkfil));
+            }
 
-        boolean renamedTarget = false;
-        try {
+            boolean renamedTarget = false;
             try {
-                FILE_UTILS.rename(canfil, temp);
-                renamedTarget = true;
-            } catch (IOException e) {
-                throw new IOException(
-                    "Couldn't rename resource when attempting to delete "
-                    + linkfil);
-            }
-            // delete the (now) broken link:
-            if (!linkfil.delete()) {
-                throw new IOException("Couldn't delete symlink: " + linkfil
-                    + " (was it a real file? is this not a UNIX system?)");
-            }
-        } finally {
-            if (renamedTarget) {
-                // return the resource to its original name:
                 try {
-                    FILE_UTILS.rename(temp, canfil);
+                    FILE_UTILS.rename(canfil, temp);
+                    renamedTarget = true;
                 } catch (IOException e) {
-                    throw new IOException("Couldn't return resource " + temp
-                                          + " to its original name: "
-                                          + canfil.getAbsolutePath()
-                                          + "\n THE RESOURCE'S NAME ON DISK HAS "
-                                          + "BEEN CHANGED BY THIS ERROR!\n");
+                    throw new IOException("Couldn't rename resource when "
+                                          + "attempting to delete " + linkfil);
+                }
+                // delete the (now) broken link:
+                if (!linkfil.delete()) {
+                    throw new IOException("Couldn't delete symlink: "
+                                          + linkfil
+                                          + " (was it a real file? is this "
+                                          + "not a UNIX system?)");
+                }
+            } finally {
+                if (renamedTarget) {
+                    // return the resource to its original name:
+                    try {
+                        FILE_UTILS.rename(temp, canfil);
+                    } catch (IOException e) {
+                        throw new IOException("Couldn't return resource "
+                                              + temp
+                                              + " to its original name: "
+                                              + canfil.getAbsolutePath()
+                                              + "\n THE RESOURCE'S NAME ON DISK"
+                                              + " HAS BEEN CHANGED BY THIS"
+                                              + " ERROR!\n");
+                    }
                 }
             }
-        }
         } else {
             Execute.runCommand(task,
                                new String[] {"rm", linkfil.getAbsolutePath()});



Mime
View raw message