dont go trough the view when moving to trash

This commit is contained in:
Robin Appelman 2015-05-13 14:09:07 +02:00
parent b085f58553
commit b70e1ffc6d
1 changed files with 27 additions and 12 deletions

View File

@ -184,22 +184,27 @@ class Trashbin {
// disable proxy to prevent recursive calls // disable proxy to prevent recursive calls
$trashPath = '/files_trashbin/files/' . $filename . '.d' . $timestamp; $trashPath = '/files_trashbin/files/' . $filename . '.d' . $timestamp;
/** @var \OC\Files\Storage\Storage $trashStorage */
list($trashStorage, $trashInternalPath) = $view->resolvePath($trashPath);
/** @var \OC\Files\Storage\Storage $sourceStorage */
list($sourceStorage, $sourceInternalPath) = $view->resolvePath('/files/' . $file_path);
try { try {
$sizeOfAddedFiles = $view->filesize('/files/' . $file_path); $sizeOfAddedFiles = $sourceStorage->filesize($sourceInternalPath);
if ($view->file_exists($trashPath)) { if ($trashStorage->file_exists($trashInternalPath)) {
$view->unlink($trashPath); $trashStorage->unlink($trashInternalPath);
} }
$view->rename('/files/' . $file_path, $trashPath); $trashStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
} catch (\OCA\Files_Trashbin\Exceptions\CopyRecursiveException $e) { } catch (\OCA\Files_Trashbin\Exceptions\CopyRecursiveException $e) {
$sizeOfAddedFiles = false; $sizeOfAddedFiles = false;
if ($view->file_exists($trashPath)) { if ($trashStorage->file_exists($trashInternalPath)) {
$view->deleteAll($trashPath); $trashStorage->unlink($trashInternalPath);
} }
\OC_Log::write('files_trashbin', 'Couldn\'t move ' . $file_path . ' to the trash bin', \OC_log::ERROR); \OC_Log::write('files_trashbin', 'Couldn\'t move ' . $file_path . ' to the trash bin', \OC_log::ERROR);
} }
if ($view->file_exists('/files/' . $file_path)) { // failed to delete the original file, abort if ($sourceStorage->file_exists($sourceInternalPath)) { // failed to delete the original file, abort
$view->unlink($trashPath); $sourceStorage->unlink($sourceInternalPath);
return false; return false;
} }
@ -257,18 +262,28 @@ class Trashbin {
} }
if ($rootView->is_dir($owner . '/files_versions/' . $ownerPath)) { if ($rootView->is_dir($owner . '/files_versions/' . $ownerPath)) {
/** @var \OC\Files\Storage\Storage $versionStorage */
list($versionStorage, $versionsInternalPath) = $rootView->resolvePath($owner . '/files_versions/' . $ownerPath);
/** @var \OC\Files\Storage\Storage $trashStorage */
list($trashStorage, $trashInternalPath) = $rootView->resolvePath($user . '/files_trashbin/versions/' . $filename . '.d' . $timestamp);
$size += self::calculateSize(new \OC\Files\View('/' . $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);
} }
$rootView->rename($owner . '/files_versions/' . $ownerPath, $user . '/files_trashbin/versions/' . $filename . '.d' . $timestamp); $trashStorage->moveFromStorage($versionStorage, $versionsInternalPath, $trashInternalPath);
} else if ($versions = \OCA\Files_Versions\Storage::getVersions($owner, $ownerPath)) { } else if ($versions = \OCA\Files_Versions\Storage::getVersions($owner, $ownerPath)) {
/** @var \OC\Files\Storage\Storage $versionStorage */
list($versionStorage, $versionsInternalPath) = $rootView->resolvePath($owner . '/files_versions/');
/** @var \OC\Files\Storage\Storage $trashStorage */
list($trashStorage, $trashInternalPath) = $rootView->resolvePath($user . '/files_trashbin/versions/');
foreach ($versions as $v) { foreach ($versions as $v) {
$size += $rootView->filesize($owner . '/files_versions' . $v['path'] . '.v' . $v['version']); $size += $versionStorage->filesize($versionsInternalPath . $v['path'] . '.v' . $v['version']);
if ($owner !== $user) { if ($owner !== $user) {
$rootView->copy($owner . '/files_versions' . $v['path'] . '.v' . $v['version'], $owner . '/files_trashbin/versions/' . $v['name'] . '.v' . $v['version'] . '.d' . $timestamp); $trashStorage->copyFromStorage($versionStorage, $versionsInternalPath . $v['path'] . '.v' . $v['version'], $owner . $trashInternalPath . $v['name'] . '.v' . $v['version'] . '.d' . $timestamp);
} }
$rootView->rename($owner . '/files_versions' . $v['path'] . '.v' . $v['version'], $user . '/files_trashbin/versions/' . $filename . '.v' . $v['version'] . '.d' . $timestamp); $trashStorage->moveFromStorage($versionStorage, $versionsInternalPath . $v['path'] . '.v' . $v['version'], $trashInternalPath . $filename . '.v' . $v['version'] . '.d' . $timestamp);
} }
} }
} }