Fixed Folder::move() deleting the folder if you move folder into itself, created empty file instead

This commit is contained in:
Matias Griese
2021-03-23 10:16:26 +02:00
parent fa819064ef
commit 9eb20e37c8
2 changed files with 7 additions and 6 deletions

View File

@@ -3,7 +3,8 @@
1. [](#bugfix)
* Ignore errors when using `set_time_limit` in `Archiver` and `GPM\Response` classes [#3023](https://github.com/getgrav/grav/issues/3023)
* Fixed moving page to itself causing the page folder to be lost (converted to an empty file)
* Fixed `Folder::move()` deleting the folder if you move folder into itself, created empty file instead
* Fixed moving `Flex Page` to itself causing the page to be lost [#3227](https://github.com/getgrav/grav/issues/3227)
* Fixed `PageStorage` detecting files as pages
# v1.7.9

View File

@@ -371,6 +371,10 @@ abstract class Folder
return;
}
if (strpos($target, $source) === 0) {
throw new RuntimeException('Cannot move folder to itself');
}
if (file_exists($target)) {
// Rename fails if target folder exists.
throw new RuntimeException('Cannot move files to existing folder/file.');
@@ -383,11 +387,7 @@ abstract class Folder
@rename($source, $target);
// Rename function can fail while still succeeding, so let's check if the folder exists.
if (!file_exists($target) || !is_dir($target)) {
// In some rare cases rename() creates file, not a folder. Get rid of it.
if (file_exists($target)) {
@unlink($target);
}
if (is_dir($source)) {
// Rename doesn't support moving folders across filesystems. Use copy instead.
self::copy($source, $target);
self::delete($source);