commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thilina Dampahala (Updated) (JIRA)" <>
Subject [jira] [Updated] (IO-300) FileUtils.moveDirectoryToDirectory removing source directory
Date Mon, 13 Feb 2012 16:37:00 GMT


Thilina Dampahala updated IO-300:

    Attachment: IO-300.patch

I have added a check before deleting the source directory; so that the it only proceeds with
the deletion if the source directory not on the target path.
> FileUtils.moveDirectoryToDirectory removing source directory
> ------------------------------------------------------------
>                 Key: IO-300
>                 URL:
>             Project: Commons IO
>          Issue Type: Bug
>            Reporter: dennis lucero
>         Attachments: IO-300.patch
> Since moveDirectoryToDirectory performs a copy then delete, if you specify a target directory
that is a subdirectory of the source, everything under the source directory is deleted.
> Steps to recreate:
>         File dest = new File("/tmp/dir1/dir2");
>         File src  = new File("/tmp/dir1/");
>         dest.mkdirs();
>         System.out.println(src.exists());
>         FileUtils.moveDirectoryToDirectory(src, dest, false);
>         System.out.println(src.exists());
> Output:
>  true
>  false
> If you try the same thing with a move command on Linux, you receive: "mv: cannot move
`dir1/' to a subdirectory of itself, `dir1/dir2/dir1'"
> Maybe throw an exception if dest.getCanonicalPath().startsWith(src.getCanonicalPath())

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message