From e3868ba118777fc21172b75a516334e107769401 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 5 Nov 2013 13:58:14 +0100 Subject: [PATCH] Fixed watcher to also update the owner's folder sizes Note that the root folder size is mandatory for quota calculation. --- apps/files_sharing/lib/sharedstorage.php | 4 +-- apps/files_sharing/lib/watcher.php | 37 ++++++++++++++++++++++-- lib/private/files/cache/watcher.php | 9 ++++-- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 257da89c84..6141d83219 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -43,7 +43,7 @@ class Shared extends \OC\Files\Storage\Common { * @param string Shared target file path * @return Returns array with the keys path, permissions, and owner or false if not found */ - private function getFile($target) { + public function getFile($target) { if (!isset($this->files[$target])) { // Check for partial files if (pathinfo($target, PATHINFO_EXTENSION) === 'part') { @@ -66,7 +66,7 @@ class Shared extends \OC\Files\Storage\Common { * @param string Shared target file path * @return string source file path or false if not found */ - private function getSourcePath($target) { + public function getSourcePath($target) { $source = $this->getFile($target); if ($source) { if (!isset($source['fullPath'])) { diff --git a/apps/files_sharing/lib/watcher.php b/apps/files_sharing/lib/watcher.php index 6fdfc1db36..818830411d 100644 --- a/apps/files_sharing/lib/watcher.php +++ b/apps/files_sharing/lib/watcher.php @@ -26,14 +26,47 @@ namespace OC\Files\Cache; */ class Shared_Watcher extends Watcher { + /** + * @brief get file owner and path + * @param string $filename + * @return array with the oweners uid and the owners path + */ + private static function getUidAndFilename($filename) { + // FIXME: duplicate of Updater::getUidAndFilename() + $uid = \OC\Files\Filesystem::getOwner($filename); + \OC\Files\Filesystem::initMountPoints($uid); + + if ($uid != \OCP\User::getUser()) { + $info = \OC\Files\Filesystem::getFileInfo($filename); + $ownerView = new \OC\Files\View('/' . $uid . '/files'); + $filename = $ownerView->getPath($info['fileid']); + } + return array($uid, '/files/' . $filename); + } + /** * check $path for updates * * @param string $path */ public function checkUpdate($path) { - if ($path != '') { - parent::checkUpdate($path); + if ($path != '' && parent::checkUpdate($path)) { + // since checkUpdate() has already updated the size of the subdirs, + // only apply the update to the owner's parent dirs + + // find last parent before reaching the shared storage root, + // which is the actual shared dir from the owner + $baseDir = substr($path, 0, strpos($path, '/')); + + // find the path relative to the data dir + $file = $this->storage->getFile($baseDir); + $view = new \OC\Files\View('/' . $file['fileOwner']); + + // find the owner's storage and path + list($storage, $internalPath) = $view->resolvePath($file['path']); + + // update the parent dirs' sizes in the owner's cache + $storage->getCache()->correctFolderSize(dirname($internalPath)); } } diff --git a/lib/private/files/cache/watcher.php b/lib/private/files/cache/watcher.php index 8bfd4602f3..58f624c899 100644 --- a/lib/private/files/cache/watcher.php +++ b/lib/private/files/cache/watcher.php @@ -15,17 +15,17 @@ class Watcher { /** * @var \OC\Files\Storage\Storage $storage */ - private $storage; + protected $storage; /** * @var Cache $cache */ - private $cache; + protected $cache; /** * @var Scanner $scanner; */ - private $scanner; + protected $scanner; /** * @param \OC\Files\Storage\Storage $storage @@ -40,6 +40,7 @@ class Watcher { * check $path for updates * * @param string $path + * @return boolean true if path was updated, false otherwise */ public function checkUpdate($path) { $cachedEntry = $this->cache->get($path); @@ -53,7 +54,9 @@ class Watcher { $this->cleanFolder($path); } $this->cache->correctFolderSize($path); + return true; } + return false; } /**