You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bu...@apache.org on 2012/04/17 17:30:24 UTC

DO NOT REPLY [Bug 53095] New: Copy issue ant 1.8.2 windows (Failed copy deletes targeted file even when copy is not attempted)

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.

[Bug 53095] Copy issue ant 1.8.2 windows (Failed copy deletes targeted file even when copy is not attempted)

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53095

bob <bs...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bsmith488@gmail.com

--- Comment #2 from bob <bs...@gmail.com> ---
Simple steps to reproduce on XP:

C:\ant>ver

Microsoft Windows XP [Version 5.1.2600]

C:\ant>call java -version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode, sharing)

C:\ant>call ant -version
Apache Ant(TM) version 1.9.0 compiled on March 5 2013

C:\ant>type build.xml
<?xml version="1.0"?>
<project name="testcopy">
        <target name="testcopy">
                <copy verbose="true"
                          file="testfile"
                          todir="./temp"
                />
        </target>
</project>

C:\ant>mkdir temp

C:\ant>attrib -r testfile
File not found - testfile

C:\ant>attrib -r temp\testfile
File not found - temp\testfile

C:\ant>copy c:\WINDOWS\system32\winver.exe .\testfile
        1 file(s) copied.

C:\ant>copy c:\WINDOWS\system32\winver.exe .\temp\testfile
        1 file(s) copied.

C:\ant>ver > .\testfile :: update file

C:\ant>attrib -r testfile

C:\ant>attrib +r temp\testfile

C:\ant>echo :::: before
:::: before

C:\ant>attrib testfile
A          C:\ant\testfile

C:\ant>attrib temp\testfile
A    R     C:\ant\temp\testfile

C:\ant>call ant testcopy
Buildfile: C:\ant\build.xml

testcopy:
     [copy] Copying 1 file to C:\ant\temp
     [copy] Copying C:\ant\testfile to C:\ant\temp\testfile

BUILD FAILED
C:\ant\build.xml:7: Failed to copy C:\ant\testfile to C:\ant\temp\testfile due
to can't write to read-only destination file C:\ant\temp\testfile

Total time: 0 seconds

C:\ant>echo :::: after (where is temp\testfile ?)
:::: after (where is temp\testfile ?)

C:\ant>attrib testfile
A          C:\ant\testfile

C:\ant>attrib temp\testfile
File not found - temp\testfile

C:\ant>

-- 
You are receiving this mail because:
You are the assignee for the bug.

DO NOT REPLY [Bug 53095] Copy issue ant 1.8.2 windows (Failed copy deletes targeted file even when copy is not attempted)

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53095

jweinste@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jweinste@gmail.com

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

[Bug 53095] Copy issue ant 1.8.2 windows (Failed copy deletes targeted file even when copy is not attempted)

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53095

--- Comment #1 from bob <bs...@gmail.com> ---
Created attachment 30117
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=30117&action=edit
copy target test

Just a sample copy target.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 53095] Copy issue ant 1.8.2 windows (Failed copy deletes targeted file even when copy is not attempted)

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53095

Stefan Bodewig <bo...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |1.9.4

--- Comment #3 from Stefan Bodewig <bo...@apache.org> ---
finally fixed with svn revision 1555363

-- 
You are receiving this mail because:
You are the assignee for the bug.