Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 2AC6A200D59 for ; Sun, 10 Dec 2017 09:25:17 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 29469160C09; Sun, 10 Dec 2017 08:25:17 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6E8A3160C00 for ; Sun, 10 Dec 2017 09:25:16 +0100 (CET) Received: (qmail 11126 invoked by uid 500); 10 Dec 2017 08:25:15 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 11115 invoked by uid 99); 10 Dec 2017 08:25:15 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 10 Dec 2017 08:25:15 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3488FDFC32; Sun, 10 Dec 2017 08:25:15 +0000 (UTC) From: jaikiran To: dev@ant.apache.org Reply-To: dev@ant.apache.org References: In-Reply-To: Subject: [GitHub] ant pull request #49: [master branch] - Fix BZ-58683 Content-Type: text/plain Message-Id: <20171210082515.3488FDFC32@git1-us-west.apache.org> Date: Sun, 10 Dec 2017 08:25:15 +0000 (UTC) archived-at: Sun, 10 Dec 2017 08:25:17 -0000 Github user jaikiran commented on a diff in the pull request: https://github.com/apache/ant/pull/49#discussion_r155941101 --- Diff: src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java --- @@ -448,49 +432,67 @@ private void handleError(String msg) { /** * Conduct the actual construction of a link. * - *

The link is constructed by calling Execute.runCommand. * - * @param res The path of the resource we are linking to. - * @param lnk The name of the link we wish to make. + * @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); - String options = "-s"; - if (overwrite) { - options += "f"; - if (linkfil.exists()) { - try { - SYMLINK_UTILS.deleteSymbolicLink(linkfil, this); - } 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); + final Path link = Paths.get(lnk); + final Path target = Paths.get(res); + final boolean alreadyExists = Files.exists(link); + if (!alreadyExists) { + // if the path (at which the link is expected to be created) isn't already present + // then we just go ahead and attempt to symlink + try { + Files.createSymbolicLink(link, target); + } catch (IOException e) { + if (failonerror) { + throw new BuildException("Failed to create symlink " + lnk + " to target " + res, e); } + log("Unable to create symlink " + lnk + " to target " + res, e, Project.MSG_INFO); } + return; + } + // file already exists, see if we are allowed to overwrite + if (!overwrite) { + log("Skipping symlink creation, since file at " + lnk + " already exists and overwrite is set to false", Project.MSG_INFO); + return; + } + // we have been asked to overwrite, so we now do the necessary steps + + // initiate a deletion *only* if the path is a symlink, else we fail with error + if (!Files.isSymbolicLink(link)) { + throw new BuildException("Cannot overwrite, as symlink, at " + lnk + " since the path already exists and isn't a symlink"); --- End diff -- Yes, that was an oversight. Fixed. --- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org