diff options
author | Vincent Petry <pvince81@owncloud.com> | 2013-11-05 13:58:14 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2013-11-05 13:58:14 +0100 |
commit | e3868ba118777fc21172b75a516334e107769401 (patch) | |
tree | 142a881a1fdbdf5489165c09f39326ed3432499c | |
parent | d48ba5a5bf0668690e54d4ed68f8aa31d8946cf9 (diff) | |
download | nextcloud-server-e3868ba118777fc21172b75a516334e107769401.tar.gz nextcloud-server-e3868ba118777fc21172b75a516334e107769401.zip |
Fixed watcher to also update the owner's folder sizes
Note that the root folder size is mandatory for quota calculation.
-rw-r--r-- | apps/files_sharing/lib/sharedstorage.php | 4 | ||||
-rw-r--r-- | apps/files_sharing/lib/watcher.php | 37 | ||||
-rw-r--r-- | 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 257da89c84e..6141d832199 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 6fdfc1db36d..818830411d0 100644 --- a/apps/files_sharing/lib/watcher.php +++ b/apps/files_sharing/lib/watcher.php @@ -27,13 +27,46 @@ 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 8bfd4602f3a..58f624c8990 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; } /** |