From 472c46251f1e0f3c7e68528f23617f21b80366cb Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 4 Sep 2008 15:48:01 +0000 Subject: [PATCH] whitespace and javadocs git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@692117 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/taskdefs/optional/unix/Symlink.java | 79 +++++++++++-------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java b/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java index e1cc3dc70..c4bc3e72d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java @@ -375,6 +375,8 @@ public class Symlink extends DispatchTask { * File that doesn't exist. * @throws IOException If calls to File.rename * or File.delete 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 @@ public class Symlink extends DispatchTask { * deleteSymlink(java.io.File). * * @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 * File that doesn't exist. * @throws IOException If calls to File.rename * or File.delete fail. + * @since Ant 1.8.0 */ public static void deleteSymlink(String path, Task t) throws IOException, FileNotFoundException { @@ -458,6 +462,7 @@ public class Symlink extends DispatchTask { * File.delete or * File.getCanonicalPath * fail. + * @since Ant 1.8.0 */ public static void deleteSymlink(File linkfil, Task task) throws IOException { @@ -475,47 +480,51 @@ public class Symlink extends DispatchTask { 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()});