From 0d90b90d9402cbcab4037efc913728cdeb4eadbd Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Fri, 7 Mar 2014 20:00:34 +0100 Subject: we first shall check if the current session is valid - otherwise the session-id will be regenerated on login via basic auth --- lib/private/api.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/private/api.php b/lib/private/api.php index 3f96196e6df..e9d31242e3a 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -270,7 +270,19 @@ class OC_API { * @return string|false (username, or false on failure) */ private static function loginUser(){ - // basic auth + + // reuse existing login + $loggedIn = OC_User::isLoggedIn(); + $ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false; + if ($loggedIn === true && $ocsApiRequest) { + + // initialize the user's filesystem + \OC_Util::setUpFS(\OC_User::getUser()); + + return OC_User::getUser(); + } + + // basic auth $authUser = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : ''; $authPw = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : ''; $return = OC_User::login($authUser, $authPw); @@ -283,17 +295,6 @@ class OC_API { return $authUser; } - // reuse existing login - $loggedIn = OC_User::isLoggedIn(); - $ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false; - if ($loggedIn === true && $ocsApiRequest) { - - // initialize the user's filesystem - \OC_Util::setUpFS(\OC_User::getUser()); - - return OC_User::getUser(); - } - return false; } -- cgit v1.2.3 From 25f523680ac1ed46470ea40277e578fd35ec02a7 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Fri, 7 Mar 2014 20:06:06 +0100 Subject: fixing ident --- lib/private/api.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/private/api.php b/lib/private/api.php index e9d31242e3a..1537cc11dd0 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -271,18 +271,18 @@ class OC_API { */ private static function loginUser(){ - // reuse existing login - $loggedIn = OC_User::isLoggedIn(); - $ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false; - if ($loggedIn === true && $ocsApiRequest) { + // reuse existing login + $loggedIn = OC_User::isLoggedIn(); + $ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false; + if ($loggedIn === true && $ocsApiRequest) { - // initialize the user's filesystem - \OC_Util::setUpFS(\OC_User::getUser()); + // initialize the user's filesystem + \OC_Util::setUpFS(\OC_User::getUser()); - return OC_User::getUser(); - } + return OC_User::getUser(); + } - // basic auth + // basic auth $authUser = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : ''; $authPw = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : ''; $return = OC_User::login($authUser, $authPw); -- cgit v1.2.3 From 4562909a2021be795b89cb7fcf6f244d7f6a8204 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 25 Feb 2014 21:35:54 +0100 Subject: get trash size from file cache --- apps/files_trashbin/appinfo/database.xml | 4 +- apps/files_trashbin/appinfo/update.php | 2 +- apps/files_trashbin/appinfo/version | 2 +- apps/files_trashbin/lib/trashbin.php | 79 +++----------------------------- lib/private/files/cache/homecache.php | 2 +- 5 files changed, 11 insertions(+), 78 deletions(-) (limited to 'lib') 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 @@ type text - true + false 4 @@ -57,7 +57,7 @@ mime text - true + false 255 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); } -- cgit v1.2.3