diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-02-25 21:35:54 +0100 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-03-10 15:13:28 +0100 |
commit | 4562909a2021be795b89cb7fcf6f244d7f6a8204 (patch) | |
tree | c485c2c36c1dfdd14b96c4dd036d808ba7f77b0b | |
parent | abad625cac2ef0417996f196f522ef006836940d (diff) | |
download | nextcloud-server-4562909a2021be795b89cb7fcf6f244d7f6a8204.tar.gz nextcloud-server-4562909a2021be795b89cb7fcf6f244d7f6a8204.zip |
get trash size from file cache
-rw-r--r-- | apps/files_trashbin/appinfo/database.xml | 4 | ||||
-rw-r--r-- | apps/files_trashbin/appinfo/update.php | 2 | ||||
-rw-r--r-- | apps/files_trashbin/appinfo/version | 2 | ||||
-rw-r--r-- | apps/files_trashbin/lib/trashbin.php | 79 | ||||
-rw-r--r-- | lib/private/files/cache/homecache.php | 2 |
5 files changed, 11 insertions, 78 deletions
diff --git a/apps/files_trashbin/appinfo/database.xml b/apps/files_trashbin/appinfo/database.xml index d08c3469b02..db104ee9298 100644 --- a/apps/files_trashbin/appinfo/database.xml +++ b/apps/files_trashbin/appinfo/database.xml @@ -49,7 +49,7 @@ <name>type</name> <type>text</type> <default></default> - <notnull>true</notnull> + <notnull>false</notnull> <length>4</length> </field> @@ -57,7 +57,7 @@ <name>mime</name> <type>text</type> <default></default> - <notnull>true</notnull> + <notnull>false</notnull> <length>255</length> </field> diff --git a/apps/files_trashbin/appinfo/update.php b/apps/files_trashbin/appinfo/update.php index 0ca232668d7..ca7b87a8681 100644 --- a/apps/files_trashbin/appinfo/update.php +++ b/apps/files_trashbin/appinfo/update.php @@ -2,7 +2,7 @@ $installedVersion=OCP\Config::getAppValue('files_trashbin', 'installed_version'); -if (version_compare($installedVersion, '0.4', '<')) { +if (version_compare($installedVersion, '0.6', '<')) { //size of the trash bin could be incorrect, remove it for all users to //enforce a recalculation during next usage. $query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trashsize`'); diff --git a/apps/files_trashbin/appinfo/version b/apps/files_trashbin/appinfo/version index 2eb3c4fe4ee..5a2a5806df6 100644 --- a/apps/files_trashbin/appinfo/version +++ b/apps/files_trashbin/appinfo/version @@ -1 +1 @@ -0.5 +0.6 diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index 3933395c298..f6816b2b4c2 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -112,9 +112,6 @@ class Trashbin { $timestamp = time(); $userTrashSize = self::getTrashbinSize($user); - if ($userTrashSize === false || $userTrashSize < 0) { - $userTrashSize = self::calculateSize(new \OC\Files\View('/' . $user . '/files_trashbin')); - } // disable proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; @@ -146,17 +143,12 @@ class Trashbin { $userTrashSize += $size; $userTrashSize -= self::expire($userTrashSize, $user); - self::setTrashbinSize($user, $userTrashSize); // if owner !== user we also need to update the owners trash size if($owner !== $user) { $ownerTrashSize = self::getTrashbinSize($owner); - if ($ownerTrashSize === false || $ownerTrashSize < 0) { - $ownerTrashSize = self::calculateSize(new \OC\Files\View('/' . $owner . '/files_trashbin')); - } $ownerTrashSize += $size; $ownerTrashSize -= self::expire($ownerTrashSize, $owner); - self::setTrashbinSize($owner, $ownerTrashSize); } } @@ -317,10 +309,6 @@ class Trashbin { $user = \OCP\User::getUser(); $view = new \OC\Files\View('/' . $user); - $trashbinSize = self::getTrashbinSize($user); - if ($trashbinSize === false || $trashbinSize < 0) { - $trashbinSize = self::calculateSize(new \OC\Files\View('/' . $user . '/files_trashbin')); - } $location = ''; if ($timestamp) { $query = \OC_DB::prepare('SELECT `location` FROM `*PREFIX*files_trash`' @@ -361,22 +349,15 @@ class Trashbin { $view->chroot($fakeRoot); \OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', array('filePath' => \OC\Files\Filesystem::normalizePath('/' . $location . '/' . $uniqueFilename), 'trashPath' => \OC\Files\Filesystem::normalizePath($file))); - if ($view->is_dir($target)) { - $trashbinSize -= self::calculateSize(new \OC\Files\View('/' . $user . '/' . $target)); - } else { - $trashbinSize -= $view->filesize($target); - } - $trashbinSize -= self::restoreVersions($view, $file, $filename, $uniqueFilename, $location, $timestamp); - $trashbinSize -= self::restoreEncryptionKeys($view, $file, $filename, $uniqueFilename, $location, $timestamp); + self::restoreVersions($view, $file, $filename, $uniqueFilename, $location, $timestamp); + self::restoreEncryptionKeys($view, $file, $filename, $uniqueFilename, $location, $timestamp); if ($timestamp) { $query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trash` WHERE `user`=? AND `id`=? AND `timestamp`=?'); $query->execute(array($user, $filename, $timestamp)); } - self::setTrashbinSize($user, $trashbinSize); - // enable proxy \OC_FileProxy::$enabled = $proxyStatus; @@ -399,10 +380,8 @@ class Trashbin { * @param $location location if file * @param $timestamp deleteion time * - * @return size of restored versions */ private static function restoreVersions($view, $file, $filename, $uniqueFilename, $location, $timestamp) { - $size = 0; if (\OCP\App::isEnabled('files_versions')) { // disable proxy to prevent recursive calls @@ -423,15 +402,12 @@ class Trashbin { } if ($view->is_dir('/files_trashbin/versions/' . $file)) { - $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . 'files_trashbin/versions/' . $file)); $rootView->rename(\OC\Files\Filesystem::normalizePath($user . '/files_trashbin/versions/' . $file), \OC\Files\Filesystem::normalizePath($owner . '/files_versions/' . $ownerPath)); } else if ($versions = self::getVersionsFromTrash($versionedFile, $timestamp)) { foreach ($versions as $v) { if ($timestamp) { - $size += $view->filesize('files_trashbin/versions/' . $versionedFile . '.v' . $v . '.d' . $timestamp); $rootView->rename($user . '/files_trashbin/versions/' . $versionedFile . '.v' . $v . '.d' . $timestamp, $owner . '/files_versions/' . $ownerPath . '.v' . $v); } else { - $size += $view->filesize('files_trashbin/versions/' . $versionedFile . '.v' . $v); $rootView->rename($user . '/files_trashbin/versions/' . $versionedFile . '.v' . $v, $owner . '/files_versions/' . $ownerPath . '.v' . $v); } } @@ -440,7 +416,6 @@ class Trashbin { // enable proxy \OC_FileProxy::$enabled = $proxyStatus; } - return $size; } /** @@ -453,11 +428,9 @@ class Trashbin { * @param $location location of file * @param $timestamp deleteion time * - * @return size of restored encrypted file */ private static function restoreEncryptionKeys($view, $file, $filename, $uniqueFilename, $location, $timestamp) { // Take care of encryption keys TODO! Get '.key' in file between file name and delete date (also for permanent delete!) - $size = 0; if (\OCP\App::isEnabled('files_encryption')) { $user = \OCP\User::getUser(); $rootView = new \OC\Files\View('/'); @@ -502,18 +475,15 @@ class Trashbin { if ($rootView->is_dir($keyfile)) { // handle keyfiles - $size += self::calculateSize(new \OC\Files\View($keyfile)); $rootView->rename($keyfile, $baseDir . '/keyfiles/' . $ownerPath); // handle share-keys if ($timestamp) { $sharekey .= '.d' . $timestamp; } - $size += self::calculateSize(new \OC\Files\View($sharekey)); $rootView->rename($sharekey, $baseDir . '/share-keys/' . $ownerPath); } else { // handle keyfiles - $size += $rootView->filesize($keyfile); $rootView->rename($keyfile, $baseDir . '/keyfiles/' . $ownerPath . '.key'); // handle share-keys @@ -522,8 +492,6 @@ class Trashbin { $ownerShareKey .= '.d' . $timestamp; } - $size += $rootView->filesize($ownerShareKey); - // move only owners key $rootView->rename($ownerShareKey, $baseDir . '/share-keys/' . $ownerPath . '.' . $user . '.shareKey'); @@ -550,7 +518,6 @@ class Trashbin { // enable proxy \OC_FileProxy::$enabled = $proxyStatus; } - return $size; } /** @@ -560,7 +527,6 @@ class Trashbin { $user = \OCP\User::getUser(); $view = new \OC\Files\View('/' . $user); $view->deleteAll('files_trashbin'); - self::setTrashbinSize($user, 0); $query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trash` WHERE `user`=?'); $query->execute(array($user)); @@ -581,11 +547,6 @@ class Trashbin { $view = new \OC\Files\View('/' . $user); $size = 0; - $trashbinSize = self::getTrashbinSize($user); - if ($trashbinSize === false || $trashbinSize < 0) { - $trashbinSize = self::calculateSize(new \OC\Files\View('/' . $user . '/files_trashbin')); - } - if ($timestamp) { $query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trash` WHERE `user`=? AND `id`=? AND `timestamp`=?'); $query->execute(array($user, $filename, $timestamp)); @@ -604,8 +565,6 @@ class Trashbin { } $view->unlink('/files_trashbin/files/' . $file); \OC_Hook::emit('\OCP\Trashbin', 'delete', array('path' => '/files_trashbin/files/' . $file)); - $trashbinSize -= $size; - self::setTrashbinSize($user, $trashbinSize); return $size; } @@ -751,17 +710,10 @@ class Trashbin { $size = self::getTrashbinSize($user); - if ($size === false || $size < 0) { - $size = self::calculateSize(new \OC\Files\View('/' . $user . '/files_trashbin')); - } - $freeSpace = self::calculateFreeSpace($size); if ($freeSpace < 0) { - $newSize = $size - self::expire($size, $user); - if ($newSize !== $size) { - self::setTrashbinSize($user, $newSize); - } + self::expire($size, $user); } } @@ -938,28 +890,9 @@ class Trashbin { * @return mixed trash bin size or false if no trash bin size is stored */ private static function getTrashbinSize($user) { - $query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*files_trashsize` WHERE `user`=?'); - $result = $query->execute(array($user))->fetchAll(); - - if ($result) { - return (int)$result[0]['size']; - } - return false; - } - - /** - * write to the database how much space is in use for the trash bin - * - * @param $user owner of the trash bin - * @param $size size of the trash bin - */ - private static function setTrashbinSize($user, $size) { - if (self::getTrashbinSize($user) === false) { - $query = \OC_DB::prepare('INSERT INTO `*PREFIX*files_trashsize` (`size`, `user`) VALUES (?, ?)'); - } else { - $query = \OC_DB::prepare('UPDATE `*PREFIX*files_trashsize` SET `size`=? WHERE `user`=?'); - } - $query->execute(array($size, $user)); + $view = new \OC\Files\View('/' . $user); + $fileInfo = $view->getFileInfo('/files_trashbin'); + return $fileInfo['size']; } /** diff --git a/lib/private/files/cache/homecache.php b/lib/private/files/cache/homecache.php index a7c310a3782..a35e4d5e1b9 100644 --- a/lib/private/files/cache/homecache.php +++ b/lib/private/files/cache/homecache.php @@ -16,7 +16,7 @@ class HomeCache extends Cache { * @return int */ public function calculateFolderSize($path) { - if ($path !== '/' and $path !== '' and $path !== 'files') { + if ($path !== '/' and $path !== '' and $path !== 'files' and $path !== 'files_trashbin') { return parent::calculateFolderSize($path); } |