ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jaikiran <...@git.apache.org>
Subject [GitHub] ant pull request #49: [master branch] - Fix BZ-58683
Date Sun, 10 Dec 2017 08:25:15 GMT
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.
          *
    -     * <p> The link is constructed by calling <code>Execute.runCommand</code>.
          *
    -     * @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


Mime
View raw message