diff options
Diffstat (limited to 'apps/files_trashbin/lib')
-rw-r--r-- | apps/files_trashbin/lib/trashbin.php | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index d492810b95f..bd6798f0eff 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -147,7 +147,7 @@ class Trashbin { * * @param string $sourcePath * @param string $owner - * @param $targetPath + * @param string $targetPath * @param $user * @param integer $timestamp */ @@ -214,13 +214,13 @@ class Trashbin { /** @var \OC\Files\Storage\Storage $sourceStorage */ list($sourceStorage, $sourceInternalPath) = $ownerView->resolvePath('/files/' . $ownerPath); try { - $sizeOfAddedFiles = $sourceStorage->filesize($sourceInternalPath); + $moveSuccessful = true; if ($trashStorage->file_exists($trashInternalPath)) { $trashStorage->unlink($trashInternalPath); } $trashStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath); } catch (\OCA\Files_Trashbin\Exceptions\CopyRecursiveException $e) { - $sizeOfAddedFiles = false; + $moveSuccessful = false; if ($trashStorage->file_exists($trashInternalPath)) { $trashStorage->unlink($trashInternalPath); } @@ -234,7 +234,7 @@ class Trashbin { $trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath); - if ($sizeOfAddedFiles !== false) { + if ($moveSuccessful) { $query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)"); $result = $query->execute(array($filename, $timestamp, $location, $owner)); if (!$result) { @@ -258,7 +258,7 @@ class Trashbin { self::scheduleExpire($owner); } - return ($sizeOfAddedFiles === false) ? false : true; + return $moveSuccessful; } /** @@ -268,18 +268,14 @@ class Trashbin { * @param string $owner owner user id * @param string $ownerPath path relative to the owner's home storage * @param integer $timestamp when the file was deleted - * - * @return int size of stored versions */ private static function retainVersions($filename, $owner, $ownerPath, $timestamp) { - $size = 0; if (\OCP\App::isEnabled('files_versions') && !empty($ownerPath)) { $user = \OCP\User::getUser(); $rootView = new \OC\Files\View('/'); if ($rootView->is_dir($owner . '/files_versions/' . $ownerPath)) { - $size += self::calculateSize(new \OC\Files\View('/' . $owner . '/files_versions/' . $ownerPath)); if ($owner !== $user) { self::copy_recursive($owner . '/files_versions/' . $ownerPath, $owner . '/files_trashbin/versions/' . basename($ownerPath) . '.d' . $timestamp, $rootView); } @@ -287,7 +283,6 @@ class Trashbin { } else if ($versions = \OCA\Files_Versions\Storage::getVersions($owner, $ownerPath)) { foreach ($versions as $v) { - $size += $rootView->filesize($owner . '/files_versions/' . $v['path'] . '.v' . $v['version']); if ($owner !== $user) { self::copy($rootView, $owner . '/files_versions' . $v['path'] . '.v' . $v['version'], $owner . '/files_trashbin/versions/' . $v['name'] . '.v' . $v['version'] . '.d' . $timestamp); } @@ -295,8 +290,6 @@ class Trashbin { } } } - - return $size; } /** @@ -417,7 +410,7 @@ class Trashbin { * @param string $uniqueFilename new file name to restore the file without overwriting existing files * @param string $location location if file * @param int $timestamp deletion time - * @return bool + * @return false|null */ private static function restoreVersions(\OC\Files\View $view, $file, $filename, $uniqueFilename, $location, $timestamp) { @@ -507,9 +500,10 @@ class Trashbin { /** * @param \OC\Files\View $view - * @param $file - * @param $filename - * @param $timestamp + * @param string $file + * @param string $filename + * @param integer|null $timestamp + * @param string $user * @return int */ private static function deleteVersions(\OC\Files\View $view, $file, $filename, $timestamp, $user) { @@ -633,18 +627,16 @@ class Trashbin { public static function expire($user) { $trashBinSize = self::getTrashbinSize($user); $availableSpace = self::calculateFreeSpace($trashBinSize, $user); - $size = 0; $dirContent = Helper::getTrashFiles('/', $user, 'mtime'); // delete all files older then $retention_obligation list($delSize, $count) = self::deleteExpiredFiles($dirContent, $user); - $size += $delSize; - $availableSpace += $size; + $availableSpace += $delSize; // delete files from trash until we meet the trash bin size limit again - $size += self::deleteFiles(array_slice($dirContent, $count), $user, $availableSpace); + self::deleteFiles(array_slice($dirContent, $count), $user, $availableSpace); } /** @@ -693,7 +685,7 @@ class Trashbin { * * @param array $files list of files sorted by mtime * @param string $user - * @return array size of deleted files and number of deleted files + * @return integer[] size of deleted files and number of deleted files */ public static function deleteExpiredFiles($files, $user) { $application = new Application(); |