Fixed watcher to also update the owner's folder sizes
Note that the root folder size is mandatory for quota calculation.
This commit is contained in:
parent
d48ba5a5bf
commit
e3868ba118
3 changed files with 43 additions and 7 deletions
|
@ -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'])) {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
9
lib/private/files/cache/watcher.php
vendored
9
lib/private/files/cache/watcher.php
vendored
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue