diff --git a/CHANGELOG.md b/CHANGELOG.md index eb3a678e3..59a2b63da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ 1. [](#new) * Added `Route::getBase()` method +1. [](#improved) + * Support symlinks when saving `File` 1. [](#bugfix) * Fixed flex objects with integer keys not working [#2863](https://github.com/getgrav/grav/issues/2863) * Fixed user avatar creation for new `Flex Users` when using folder storage diff --git a/system/src/Grav/Framework/File/AbstractFile.php b/system/src/Grav/Framework/File/AbstractFile.php index 88089abf4..71298af71 100644 --- a/system/src/Grav/Framework/File/AbstractFile.php +++ b/system/src/Grav/Framework/File/AbstractFile.php @@ -279,11 +279,14 @@ class AbstractFile implements FileInterface $tmp = false; } } else { + // Support for symlinks. + $realpath = is_link($filepath) ? realpath($filepath) : $filepath; + // Create file with a temporary name and rename it to make the save action atomic. - $tmp = $this->tempname($filepath); + $tmp = $this->tempname($realpath); if (@file_put_contents($tmp, $data) === false) { $tmp = false; - } elseif (@rename($tmp, $filepath) === false) { + } elseif (@rename($tmp, $realpath) === false) { @unlink($tmp); $tmp = false; }