mirror of
https://github.com/getgrav/grav.git
synced 2026-02-28 01:21:30 +01:00
Fixed Folder::move() deleting the folder if you move folder into itself, created empty file instead
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user