1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added a flag to specify if File::deleteRecursively should follow symlinks or not

This commit is contained in:
hogliux 2018-06-13 12:07:25 +01:00
parent 5799a4ee5b
commit 6d55fe78fe
3 changed files with 19 additions and 10 deletions

View file

@ -256,13 +256,13 @@ bool File::setExecutePermission (bool shouldBeExecutable) const
return setFileExecutableInternal (shouldBeExecutable);
}
bool File::deleteRecursively() const
bool File::deleteRecursively (bool followSymlinks) const
{
bool worked = true;
if (isDirectory())
if (isDirectory() && (followSymlinks || ! isSymbolicLink()))
for (auto& f : findChildFiles (File::findFilesAndDirectories, false))
worked = f.deleteRecursively() && worked;
worked = f.deleteRecursively (followSymlinks) && worked;
return deleteFile() && worked;
}

View file

@ -457,6 +457,9 @@ public:
If this file is actually a directory, it may not be deleted correctly if it
contains files. See deleteRecursively() as a better way of deleting directories.
If this file is a symlink, then the symlink will be deleted and not the target
of the symlink.
@returns true if the file has been successfully deleted (or if it didn't exist to
begin with).
@see deleteRecursively
@ -468,11 +471,14 @@ public:
If this file is a directory, this will try to delete it and all its subfolders. If
it's just a file, it will just try to delete the file.
@returns true if the file and all its subfolders have been successfully deleted
(or if it didn't exist to begin with).
@param followSymlinks If true, then any symlink pointing to a directory will also
recursively delete the contents of that directory
@returns true if the file and all its subfolders have been successfully
deleted (or if it didn't exist to begin with).
@see deleteFile
*/
bool deleteRecursively() const;
bool deleteRecursively (bool followSymlinks = false) const;
/** Moves this file or folder to the trash.

View file

@ -428,11 +428,14 @@ bool File::setFileTimesInternal (int64 modificationTime, int64 accessTime, int64
bool File::deleteFile() const
{
if (! exists() && ! isSymbolicLink())
return true;
if (! isSymbolicLink())
{
if (! exists())
return true;
if (isDirectory())
return rmdir (fullPath.toUTF8()) == 0;
if (isDirectory())
return rmdir (fullPath.toUTF8()) == 0;
}
return remove (fullPath.toUTF8()) == 0;
}