Skip to content

Commit

Permalink
Handle empty DB while expiring versions
Browse files Browse the repository at this point in the history
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 nextcloud#36541

Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge authored and summersab committed Jun 26, 2023
1 parent a86abc1 commit 82efc41
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions apps/files_versions/lib/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
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;
Expand Down Expand Up @@ -592,11 +593,16 @@ public static function expireOlderThanMaxForUser($uid) {
// 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
Expand Down

0 comments on commit 82efc41

Please sign in to comment.