diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-07-27 17:24:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-27 17:24:47 +0200 |
commit | dc58206ded857001415593d75f3de5f051f3efb2 (patch) | |
tree | 23717c378eb5a7ed9a8fddb548b3e9cdb03c346b /apps | |
parent | c7757b07f85555dc839d44a4a075cb333c2c1ff3 (diff) | |
parent | 549845aa738493d62867c8aff8bae5c8fbcff48d (diff) | |
download | nextcloud-server-dc58206ded857001415593d75f3de5f051f3efb2.tar.gz nextcloud-server-dc58206ded857001415593d75f3de5f051f3efb2.zip |
Merge pull request #5852 from nextcloud/preview_trash_cleanup
Preview trash cleanup
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_trashbin/lib/Trashbin.php | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index 75035b8bab6..88d23cee711 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -42,6 +42,8 @@ use OC\Files\Filesystem; use OC\Files\View; use OCA\Files_Trashbin\AppInfo\Application; use OCA\Files_Trashbin\Command\Expire; +use OCP\Files\File; +use OCP\Files\Folder; use OCP\Files\NotFoundException; use OCP\User; @@ -485,9 +487,16 @@ class Trashbin { */ public static function deleteAll() { $user = User::getUser(); + $userRoot = \OC::$server->getUserFolder($user)->getParent(); $view = new View('/' . $user); $fileInfos = $view->getDirectoryContent('files_trashbin/files'); + try { + $trash = $userRoot->get('files_trashbin'); + } catch (NotFoundException $e) { + return false; + } + // Array to store the relative path in (after the file is deleted, the view won't be able to relativise the path anymore) $filePaths = array(); foreach($fileInfos as $fileInfo){ @@ -504,7 +513,7 @@ class Trashbin { } // actual file deletion - $view->deleteAll('files_trashbin'); + $trash->delete(); $query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trash` WHERE `user`=?'); $query->execute(array($user)); @@ -516,8 +525,8 @@ class Trashbin { self::emitTrashbinPostDelete($path); } - $view->mkdir('files_trashbin'); - $view->mkdir('files_trashbin/files'); + $trash = $userRoot->newFolder('files_trashbin'); + $trash->newFolder('files'); return true; } @@ -548,6 +557,7 @@ class Trashbin { * @return int size of deleted files */ public static function delete($filename, $user, $timestamp = null) { + $userRoot = \OC::$server->getUserFolder($user)->getParent(); $view = new View('/' . $user); $size = 0; @@ -561,13 +571,20 @@ class Trashbin { $size += self::deleteVersions($view, $file, $filename, $timestamp, $user); - if ($view->is_dir('/files_trashbin/files/' . $file)) { + try { + $node = $userRoot->get('/files_trashbin/files/' . $file); + } catch (NotFoundException $e) { + return $size; + } + + if ($node instanceof Folder) { $size += self::calculateSize(new View('/' . $user . '/files_trashbin/files/' . $file)); - } else { + } else if ($node instanceof File) { $size += $view->filesize('/files_trashbin/files/' . $file); } + self::emitTrashbinPreDelete('/files_trashbin/files/' . $file); - $view->unlink('/files_trashbin/files/' . $file); + $node->delete(); self::emitTrashbinPostDelete('/files_trashbin/files/' . $file); return $size; |