Merge pull request #20796 from owncloud/cleanup-trashbin-code

Cleanup trashbin expire code
This commit is contained in:
Thomas Müller 2015-12-07 10:24:09 +01:00
commit 22843fc6e3
1 changed files with 6 additions and 15 deletions

View File

@ -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;
}
/**
@ -633,18 +626,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);
}
/**