Merge pull request #20796 from owncloud/cleanup-trashbin-code
Cleanup trashbin expire code
This commit is contained in:
commit
22843fc6e3
|
@ -214,13 +214,13 @@ class Trashbin {
|
||||||
/** @var \OC\Files\Storage\Storage $sourceStorage */
|
/** @var \OC\Files\Storage\Storage $sourceStorage */
|
||||||
list($sourceStorage, $sourceInternalPath) = $ownerView->resolvePath('/files/' . $ownerPath);
|
list($sourceStorage, $sourceInternalPath) = $ownerView->resolvePath('/files/' . $ownerPath);
|
||||||
try {
|
try {
|
||||||
$sizeOfAddedFiles = $sourceStorage->filesize($sourceInternalPath);
|
$moveSuccessful = true;
|
||||||
if ($trashStorage->file_exists($trashInternalPath)) {
|
if ($trashStorage->file_exists($trashInternalPath)) {
|
||||||
$trashStorage->unlink($trashInternalPath);
|
$trashStorage->unlink($trashInternalPath);
|
||||||
}
|
}
|
||||||
$trashStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
|
$trashStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
|
||||||
} catch (\OCA\Files_Trashbin\Exceptions\CopyRecursiveException $e) {
|
} catch (\OCA\Files_Trashbin\Exceptions\CopyRecursiveException $e) {
|
||||||
$sizeOfAddedFiles = false;
|
$moveSuccessful = false;
|
||||||
if ($trashStorage->file_exists($trashInternalPath)) {
|
if ($trashStorage->file_exists($trashInternalPath)) {
|
||||||
$trashStorage->unlink($trashInternalPath);
|
$trashStorage->unlink($trashInternalPath);
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ class Trashbin {
|
||||||
|
|
||||||
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
|
$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 (?,?,?,?)");
|
$query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");
|
||||||
$result = $query->execute(array($filename, $timestamp, $location, $owner));
|
$result = $query->execute(array($filename, $timestamp, $location, $owner));
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
|
@ -258,7 +258,7 @@ class Trashbin {
|
||||||
self::scheduleExpire($owner);
|
self::scheduleExpire($owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ($sizeOfAddedFiles === false) ? false : true;
|
return $moveSuccessful;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -268,18 +268,14 @@ class Trashbin {
|
||||||
* @param string $owner owner user id
|
* @param string $owner owner user id
|
||||||
* @param string $ownerPath path relative to the owner's home storage
|
* @param string $ownerPath path relative to the owner's home storage
|
||||||
* @param integer $timestamp when the file was deleted
|
* @param integer $timestamp when the file was deleted
|
||||||
*
|
|
||||||
* @return int size of stored versions
|
|
||||||
*/
|
*/
|
||||||
private static function retainVersions($filename, $owner, $ownerPath, $timestamp) {
|
private static function retainVersions($filename, $owner, $ownerPath, $timestamp) {
|
||||||
$size = 0;
|
|
||||||
if (\OCP\App::isEnabled('files_versions') && !empty($ownerPath)) {
|
if (\OCP\App::isEnabled('files_versions') && !empty($ownerPath)) {
|
||||||
|
|
||||||
$user = \OCP\User::getUser();
|
$user = \OCP\User::getUser();
|
||||||
$rootView = new \OC\Files\View('/');
|
$rootView = new \OC\Files\View('/');
|
||||||
|
|
||||||
if ($rootView->is_dir($owner . '/files_versions/' . $ownerPath)) {
|
if ($rootView->is_dir($owner . '/files_versions/' . $ownerPath)) {
|
||||||
$size += self::calculateSize(new \OC\Files\View('/' . $owner . '/files_versions/' . $ownerPath));
|
|
||||||
if ($owner !== $user) {
|
if ($owner !== $user) {
|
||||||
self::copy_recursive($owner . '/files_versions/' . $ownerPath, $owner . '/files_trashbin/versions/' . basename($ownerPath) . '.d' . $timestamp, $rootView);
|
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)) {
|
} else if ($versions = \OCA\Files_Versions\Storage::getVersions($owner, $ownerPath)) {
|
||||||
|
|
||||||
foreach ($versions as $v) {
|
foreach ($versions as $v) {
|
||||||
$size += $rootView->filesize($owner . '/files_versions/' . $v['path'] . '.v' . $v['version']);
|
|
||||||
if ($owner !== $user) {
|
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);
|
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) {
|
public static function expire($user) {
|
||||||
$trashBinSize = self::getTrashbinSize($user);
|
$trashBinSize = self::getTrashbinSize($user);
|
||||||
$availableSpace = self::calculateFreeSpace($trashBinSize, $user);
|
$availableSpace = self::calculateFreeSpace($trashBinSize, $user);
|
||||||
$size = 0;
|
|
||||||
|
|
||||||
$dirContent = Helper::getTrashFiles('/', $user, 'mtime');
|
$dirContent = Helper::getTrashFiles('/', $user, 'mtime');
|
||||||
|
|
||||||
// delete all files older then $retention_obligation
|
// delete all files older then $retention_obligation
|
||||||
list($delSize, $count) = self::deleteExpiredFiles($dirContent, $user);
|
list($delSize, $count) = self::deleteExpiredFiles($dirContent, $user);
|
||||||
|
|
||||||
$size += $delSize;
|
$availableSpace += $delSize;
|
||||||
$availableSpace += $size;
|
|
||||||
|
|
||||||
// delete files from trash until we meet the trash bin size limit again
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue