[jira] [Resolved] (IO-372) FileUtils.moveDirectory can produce misleading error message on failiure

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Resolved] (IO-372) FileUtils.moveDirectory can produce misleading error message on failiure

Lars Bruun-Hansen (Jira)

     [ https://issues.apache.org/jira/browse/IO-372?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb resolved IO-372.
---------------------

       Resolution: Fixed
    Fix Version/s: 2.5

Thanks:

URL: http://svn.apache.org/r1468602
Log:
IO-372 FileUtils.moveDirectory can produce misleading error message on failiure

Modified:
    commons/proper/io/trunk/src/changes/changes.xml
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java

               

> FileUtils.moveDirectory can produce misleading error message on failiure
> ------------------------------------------------------------------------
>
>                 Key: IO-372
>                 URL: https://issues.apache.org/jira/browse/IO-372
>             Project: Commons IO
>          Issue Type: Bug
>            Reporter: Max
>             Fix For: 2.5
>
>
> I am seeing the following error message when trying to move a directory:
> "Cannot move directory: /path/to/directory to a subdirectory of itself: /path/to/directory_renamed"
> This statement is iincorrect the destination path is not a sub directory of the source path.
> Looking at the source l.2752 the destination directory is being compared to the source directory without using a File.separator
> Here's a patch for the current trunk.
> {noformat}
> Index: src/main/java/org/apache/commons/io/FileUtils.java
> ===================================================================
> --- src/main/java/org/apache/commons/io/FileUtils.java (revision 1453996)
> +++ src/main/java/org/apache/commons/io/FileUtils.java (working copy)
> @@ -2803,7 +2803,7 @@
>          }
>          final boolean rename = srcDir.renameTo(destDir);
>          if (!rename) {
> -            if (destDir.getCanonicalPath().startsWith(srcDir.getCanonicalPath())) {
> +            if (destDir.getCanonicalPath().startsWith(srcDir.getCanonicalPath() + File.separator)) {
>                  throw new IOException("Cannot move directory: "+srcDir+" to a subdirectory of itself: "+destDir);
>              }
>              copyDirectory( srcDir, destDir );
>   {noformat}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira