Support symlinks when saving File

This commit is contained in:
Matias Griese
2020-04-17 10:06:04 +03:00
parent ed2cf5174d
commit e84488e126
2 changed files with 7 additions and 2 deletions

View File

@@ -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

View File

@@ -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;
}