diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-04-23 16:03:20 +0200 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2025-04-24 11:31:00 +0000 |
commit | cf0814a7fdc2c77fb827a2c158dea2c0b8371b35 (patch) | |
tree | 1ab18703adbcfa6197e4cf284bcc0e1e8c4b9428 | |
parent | 6c8fa2a14543583c920790b5ccb86f00f4741dec (diff) | |
download | nextcloud-server-backport/52373/stable31.tar.gz nextcloud-server-backport/52373/stable31.zip |
fix(files_versions): create version if previous does not existbackport/52373/stable31
This issue happens reproducible if:
- Versions is disabled
- Upload a file
- Enable versions
- Upload same file unchanged
- Now the error happens.
Problem is that the mtime is unchanged so no version will be created on the upload, but it tries to update the last version which does not exists.
Instead of "upload same file unchanged" you can also - like in the example stack trace above - use Android with an SD card with invalid mtime -> the mtime will be stripped so its always the same.
Instead of disable versions the same also happens if e.g. the versions creation failed due to other issues.
The solution now is to catch the exception and create if not exists.
A cleaner solution would be to have a method on the versions backend
like `hasVersionEntity(File $file, int $revision): bool` but this would
be a breaking change or at least a feature that apps need to implement.
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r-- | apps/files_versions/lib/Listener/FileEventsListener.php | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/apps/files_versions/lib/Listener/FileEventsListener.php b/apps/files_versions/lib/Listener/FileEventsListener.php index 49150f4e726..c581c61b4ae 100644 --- a/apps/files_versions/lib/Listener/FileEventsListener.php +++ b/apps/files_versions/lib/Listener/FileEventsListener.php @@ -196,8 +196,8 @@ class FileEventsListener implements IEventListener { } if ( - $writeHookInfo['versionCreated'] && - $node->getMTime() !== $writeHookInfo['previousNode']->getMTime() + $writeHookInfo['versionCreated'] + && $node->getMTime() !== $writeHookInfo['previousNode']->getMTime() ) { // If a new version was created, insert a version in the DB for the current content. // If both versions have the same mtime, it means the latest version file simply got overrode, @@ -218,6 +218,15 @@ class FileEventsListener implements IEventListener { ], ); } + } catch (DoesNotExistException $e) { + // This happens if the versions app was not enabled while the file was created or updated the last time. + // meaning there is no such revision and we need to create this file. + if ($writeHookInfo['versionCreated']) { + $this->created($node); + } else { + // Normally this should not happen so we re-throw the exception to not hide any potential issues. + throw $e; + } } catch (Exception $e) { $this->logger->error('Failed to update existing version for ' . $node->getPath(), [ 'exception' => $e, |