Prevent renaming ML object into existing file.

When renaming objects in the Media Library,
s9y didn't check if a file with the same
name already exists, resulting in a file
name collision deleting both files from
the database _and_ from disk.

Add a check to avoid that.

An error message would be nice, too, but
that may be added later on.

Tested on s9y-stable test instance.

Cherry-picked from master branch.

Signed-off-by: Thomas Hochstein <thh@inter.net>
This commit is contained in:
Thomas Hochstein 2020-03-20 17:50:00 +01:00
parent 1f31fd19c3
commit 307f1c3dad
2 changed files with 9 additions and 0 deletions

View File

@ -20,6 +20,11 @@ Version 2.3.3-beta1 ()
Also fixes missing "keep strip tags" configuration option
* Fix: Add valid HTTP referrer when trying to delete a
* Fix: Prevent renaming a ML object into an existing file,
resulting in deletion of both from disk and database.
* Fix invalid HTTP referrer error when trying to delete a
trackback from the frontend
* Use the video tag for videos in the Medialibrary, also when

View File

@ -2261,6 +2261,10 @@ function serendipity_renameFile($id, $newName, $path = null) {
$newPath = "{$imgBase}{$path}{$newName}.{$file['extension']}";
if (file_exists($newPath)) {
return false;
}
rename("{$imgBase}{$file['path']}{$file['realname']}", $newPath);
serendipity_renameThumbnails($id, "{$path}$newName");