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 #36541

Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Feb 8, 2023
1 parent 7341d33 commit 21cd3b0
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

1 comment on commit 21cd3b0

@nursoda
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the Code scanning / Psalm notice "PossiblyNullArgument" irrelevant here? Why?
("Argument 1 of substr cannot be null, possibly null value provided")?

Please sign in to comment.