Skip to content

Commit

Permalink
Fix error when version_metadata is enabled and there is no quota (#40847
Browse files Browse the repository at this point in the history
)

* Fix error when version_metadata is enabled and there is no quota

* changelog
  • Loading branch information
IljaN authored Jun 26, 2023
1 parent 059407e commit 49921af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
24 changes: 13 additions & 11 deletions apps/files_versions/lib/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ public static function renameOrCopy($sourcePath, $targetPath, $operation) {

if (self::metaEnabled()) {
// NOTE: we need to move current file first as in case of interuption lack of this file could cause issues

// Also move/copy the current version
$src = '/files_versions/' . $sourcePath . MetaStorage::CURRENT_FILE_PREFIX . MetaStorage::VERSION_FILE_EXT;
$dst = '/files_versions/' . $targetPath . MetaStorage::CURRENT_FILE_PREFIX . MetaStorage::VERSION_FILE_EXT;
Expand Down Expand Up @@ -635,7 +635,7 @@ public static function publishCurrentVersion($filename) {
if (Filesystem::is_dir($filename) || !Filesystem::file_exists($filename)) {
return false;
}

list($uid, $currentFileName) = self::getUidAndFilename($filename);

// overwrite current file metadata with minor=false to create new major version
Expand Down Expand Up @@ -671,7 +671,7 @@ public static function getVersions($uid, $filename) {
if ($dirContent === false) {
return $versions;
}

// add historical versions
if (\is_resource($dirContent)) {
while (($entryName = \readdir($dirContent)) !== false) {
Expand All @@ -682,7 +682,7 @@ public static function getVersions($uid, $filename) {
$pathparts = \pathinfo($entryName);
$timestamp = \substr($pathparts['extension'], 1);
$filename = $pathparts['filename'];

// ordering key
$key = $timestamp . '#' . $filename;

Expand Down Expand Up @@ -971,15 +971,17 @@ public static function expire($filename, $uid) {
// if still not enough free space we rearrange the versions from all files
if ($availableSpace <= 0) {
$result = self::getFileHelper()->getAllVersions($uid);
$allVersions = $result['all'];
if ($result) {
$allVersions = $result['all'];

foreach ($result['by_file'] as $versions) {
list($toDeleteNew, $size) = self::getExpireList($time, $versions, $availableSpace <= 0);
$toDelete = \array_merge($toDelete, $toDeleteNew);
$sizeOfDeletedVersions += $size;
foreach ($result['by_file'] as $versions) {
list($toDeleteNew, $size) = self::getExpireList($time, $versions, $availableSpace <= 0);
$toDelete = \array_merge($toDelete, $toDeleteNew);
$sizeOfDeletedVersions += $size;
}
$availableSpace = $availableSpace + $sizeOfDeletedVersions;
$versionsSize = $versionsSize - $sizeOfDeletedVersions;
}
$availableSpace = $availableSpace + $sizeOfDeletedVersions;
$versionsSize = $versionsSize - $sizeOfDeletedVersions;
}

// we need to check if we have to remove any empty folder based on the
Expand Down
6 changes: 6 additions & 0 deletions changelog/unreleased/40847
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Versions expire job does not error with federated shares

Versions expire job does not error with federated shares when versioning meta-
data is enabled.

https://github.com/owncloud/core/pull/40847

0 comments on commit 49921af

Please sign in to comment.