aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis Chemineau <louis@chmn.me>2023-02-06 10:45:24 +0100
committerLouis (Rebase PR Action) <artonge@users.noreply.github.com>2023-02-08 13:56:49 +0000
commit21cd3b0e0d3b34ad0e3973aeac1d9a562456d258 (patch)
tree8fdd7f0004fb76238b2976ab4a2fd635b24f72a7
parent7341d339eb7a1aa20c6b35e8edb40c1cd7946b96 (diff)
downloadnextcloud-server-21cd3b0e0d3b34ad0e3973aeac1d9a562456d258.tar.gz
nextcloud-server-21cd3b0e0d3b34ad0e3973aeac1d9a562456d258.zip
Handle empty DB while expiring versions
Version on the FS can have no equivalent in the DB if they were created before the version naming feature. This makes sure that we catch the resulting exception and proceed as usual. Fix https://github.com/nextcloud/server/issues/36541 Signed-off-by: Louis Chemineau <louis@chmn.me>
-rw-r--r--apps/files_versions/lib/Storage.php14
1 files changed, 10 insertions, 4 deletions
diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php
index 2fd208cd364..75ca7e4bcee 100644
--- a/apps/files_versions/lib/Storage.php
+++ b/apps/files_versions/lib/Storage.php
@@ -52,6 +52,7 @@ use OCA\Files_Versions\Command\Expire;
use OCA\Files_Versions\Db\VersionsMapper;
use OCA\Files_Versions\Events\CreateVersionEvent;
use OCA\Files_Versions\Versions\IVersionManager;
+use OCP\AppFramework\Db\DoesNotExistException;
use OCP\Files\FileInfo;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
@@ -592,11 +593,16 @@ class Storage {
// Check that the version does not have a label.
$path = $versionsRoot->getRelativePath($info->getPath());
$node = $userFolder->get(substr($path, 0, -strlen('.v'.$version)));
- $versionEntity = $versionsMapper->findVersionForFileId($node->getId(), $version);
- $versionEntities[$info->getId()] = $versionEntity;
+ try {
+ $versionEntity = $versionsMapper->findVersionForFileId($node->getId(), $version);
+ $versionEntities[$info->getId()] = $versionEntity;
- if ($versionEntity->getLabel() !== '') {
- return false;
+ if ($versionEntity->getLabel() !== '') {
+ return false;
+ }
+ } catch (DoesNotExistException $ex) {
+ // Version on FS can have no equivalent in the DB if they were created before the version naming feature.
+ // So we ignore DoesNotExistException.
}
// Check that the version's timestamp is lower than $threshold