ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 53095] New: Copy issue ant 1.8.2 windows (Failed copy deletes targeted file even when copy is not attempted)
Date Tue, 17 Apr 2012 15:30:24 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=53095

             Bug #: 53095
           Summary: Copy issue ant 1.8.2 windows (Failed copy deletes
                    targeted file even when copy is not attempted)
           Product: Ant
           Version: 1.8.2
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Core tasks
        AssignedTo: notifications@ant.apache.org
        ReportedBy: jweinste@gmail.com
    Classification: Unclassified


Copy issue ant 1.8.2 windows

(Failed copy deletes targeted file even when copy is not attempted)

In this case <copy> uses "overwrite" but not "force".

Using "force=true" also acts as workaround.


What I assume is happening based on code is targeted file canWrite fails,
"read-only" exception is thrown, and then targeted file is deleted, which
succeeds.

The later part is what i observe, read-only exception followed by file
deletion. This is not the behavior i would expect.

If the file is not to be copied to the target file, then the target file should
not be deleted.

Copy.java

  protected void doResourceOperations(Map map)
  {
    if (map.size() > 0) {
      log("Copying " + map.size() + " resource" + (map.size() == 1 ? "" : "s")
+ " to " + this.destDir.getAbsolutePath());

      Iterator iter = map.keySet().iterator();
      while (iter.hasNext()) {
        Resource fromResource = (Resource)iter.next();
        String[] toFiles = (String[])map.get(fromResource);

        for (int i = 0; i < toFiles.length; i++) {
          String toFile = toFiles[i];
          try
          {
            log("Copying " + fromResource + " to " + toFile, this.verbosity);

            FilterSetCollection executionFilters = new FilterSetCollection();

            if (this.filtering) {
              executionFilters.addFilterSet(getProject().getGlobalFilterSet());
            }

            Enumeration filterEnum = this.filterSets.elements();
            while (filterEnum.hasMoreElements()) {
             
executionFilters.addFilterSet((FilterSet)filterEnum.nextElement());
            }

            ResourceUtils.copyResource(fromResource, new
FileResource(this.destDir, toFile), executionFilters, this.filterChains,
this.forceOverwrite, this.preserveLastModified, false, this.inputEncoding,
this.outputEncoding, getProject(), getForce());
          }
          catch (IOException ioe)
          {
            String msg = "Failed to copy " + fromResource + " to " + toFile + "
due to " + getDueTo(ioe);

            File targetFile = new File(toFile);
            if ((targetFile.exists()) && (!targetFile.delete())) { -- file is
deleted when canWrite false, "read-only" file is not a corrupt file, canWrite
is false but delete succeeds
              msg = msg + " and I couldn't delete the corrupt " + toFile;
            }
            if (this.failonerror) {
              throw new BuildException(msg, ioe, getLocation());
            }
            log(msg, 0);
          }



ResourceUtils.java#copyResource



    File destFile = null;
    if (dest.as(FileProvider.class) != null) {
      destFile = ((FileProvider)dest.as(FileProvider.class)).getFile();
    }
    if ((destFile != null) && (destFile.isFile()) && (!destFile.canWrite()))
{
      if (!force) {
        throw new IOException("can't write to read-only destination file " +
destFile); -- "read-only" exception, canWrite false
      }

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

Mime
View raw message