commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bojan Vukojevic (JIRA)" <j...@apache.org>
Subject [jira] Created: (TRANSACTION-18) applyDeletes method does not delete symbolic links
Date Fri, 15 Jun 2007 01:46:26 GMT
applyDeletes method does not delete symbolic links
--------------------------------------------------

                 Key: TRANSACTION-18
                 URL: https://issues.apache.org/jira/browse/TRANSACTION-18
             Project: Commons Transaction
          Issue Type: Bug
    Affects Versions: 1.2
         Environment: Linux CENT OS
            Reporter: Bojan Vukojevic


applyDeletes static method in FileResourceManager (line 154) checks "isFile" and if this returns
"false" assumes it is a directory. This fails if the resource is symbolic link. Instead, it
should call "isDirectory" and then recursively call itself, otherwise, it should delete the
resource.
The fix is shown below:

protected static void applyDeletes(File removeDir, File targetDir, File rootDir) throws IOException
{
        if (removeDir.isDirectory() && targetDir.isDirectory()) {
            File[] files = removeDir.listFiles();
            for (int i = 0; i < files.length; i++) {
                File removeFile = files[i];
                File targetFile = new File(targetDir, removeFile.getName());
                if (!removeFile.isDirectory()) {  //===========THIS IS THE FIX - WAS removeFile.isFile=======
                    if (targetFile.exists()) {
                        if (!targetFile.delete()) {
                            throw new IOException("Could not delete file " + removeFile.getName()
                                    + " in directory targetDir");
                        }
                    }
                    // indicate, this has been done
                    removeFile.delete();
                } else {
                    applyDeletes(removeFile, targetFile, rootDir);
                }
                // delete empty target directories, except root dir
                if (!targetDir.equals(rootDir) && targetDir.list().length == 0) {
                    targetDir.delete();
                }
            }
        }
    }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message