mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
File: Avoid leaving behind file system changes when moveFileTo() fails
This commit is contained in:
parent
b8f3030e0b
commit
3f52b29432
3 changed files with 16 additions and 0 deletions
|
|
@ -360,6 +360,14 @@ File File::getParentDirectory() const
|
|||
return createFileWithoutCheckingPath (getPathUpToLastSlash());
|
||||
}
|
||||
|
||||
bool File::isNonEmptyDirectory() const
|
||||
{
|
||||
if (! isDirectory())
|
||||
return false;
|
||||
|
||||
return RangedDirectoryIterator (*this, false, "*", findFilesAndDirectories) != RangedDirectoryIterator();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
String File::getFileName() const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -510,6 +510,10 @@ public:
|
|||
Also note that on some OSes (e.g. Windows), moving files between different
|
||||
volumes may not be possible.
|
||||
|
||||
This function will often fail to move directories because of the ambiguities
|
||||
about merging existing directories. Use copyDirectoryTo() and deleteRecursively()
|
||||
in these situations.
|
||||
|
||||
@returns true if the operation succeeds
|
||||
*/
|
||||
bool moveFileTo (const File& targetLocation) const;
|
||||
|
|
@ -1150,6 +1154,7 @@ private:
|
|||
|
||||
static String parseAbsolutePath (const String&);
|
||||
String getPathUpToLastSlash() const;
|
||||
bool isNonEmptyDirectory() const;
|
||||
|
||||
Result createDirectoryInternal (const String&) const;
|
||||
bool copyInternal (const File&) const;
|
||||
|
|
|
|||
|
|
@ -405,6 +405,9 @@ bool File::moveInternal (const File& dest) const
|
|||
if (rename (fullPath.toUTF8(), dest.getFullPathName().toUTF8()) == 0)
|
||||
return true;
|
||||
|
||||
if (isNonEmptyDirectory())
|
||||
return false;
|
||||
|
||||
if (hasWriteAccess() && copyInternal (dest))
|
||||
{
|
||||
if (deleteFile())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue