Browse Source

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

tags/2021-05-28
hogliux 7 years ago
parent
commit
6d55fe78fe
3 changed files with 19 additions and 10 deletions
  1. +3
    -3
      modules/juce_core/files/juce_File.cpp
  2. +9
    -3
      modules/juce_core/files/juce_File.h
  3. +7
    -4
      modules/juce_core/native/juce_posix_SharedCode.h

+ 3
- 3
modules/juce_core/files/juce_File.cpp 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;
}


+ 9
- 3
modules/juce_core/files/juce_File.h 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.


+ 7
- 4
modules/juce_core/native/juce_posix_SharedCode.h 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;
}


Loading…
Cancel
Save