diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php index f4acc8290bc3..686cde4b0390 100644 --- a/lib/private/connector/sabre/file.php +++ b/lib/private/connector/sabre/file.php @@ -187,9 +187,6 @@ public function put($data) { throw new FileLocked($e->getMessage(), $e->getCode(), $e); } - // since we skipped the view we need to scan and emit the hooks ourselves - $this->fileView->getUpdater()->update($this->path); - if ($view) { $this->emitPostHooks($exists); } @@ -197,9 +194,15 @@ public function put($data) { // allow sync clients to send the mtime along in a header $request = \OC::$server->getRequest(); if (isset($request->server['HTTP_X_OC_MTIME'])) { - if ($this->fileView->touch($this->path, $request->server['HTTP_X_OC_MTIME'])) { + if ($this->fileView->touch($this->path, $request->server['HTTP_X_OC_MTIME'],true)) { header('X-OC-MTime: accepted'); } + // touch() has done already a updateMtime(), now we only need to run a updateFolderSize() + $this->fileView->getUpdater ()->updateFolderSize ( $this->path ); + } else { // no touch was done so we need to do a full update + + // since we skipped the view we need to scan and emit the hooks ourselves + $this->fileView->getUpdater ()->update ( $this->path ); } $this->refreshInfo(); } catch (StorageNotAvailableException $e) { diff --git a/lib/private/files/cache/updater.php b/lib/private/files/cache/updater.php index 1e180e7993a4..154f55416ed1 100644 --- a/lib/private/files/cache/updater.php +++ b/lib/private/files/cache/updater.php @@ -102,19 +102,69 @@ public function update($path, $time = null) { if (!$this->enabled or Scanner::isPartialFile($path)) { return; } + + $this->updateMtime($path,$time, true); + $this->updateFolderSize($path,$time); + + } + + /** + * Update the cache for $path update the mtime of the parent folders + * + * @param string $path + * @param int $time + * @param boolean $skipPropagatingChanges + */ + public function updateMtime($path, $time = null, $skipPropagatingChanges=false) { + if (!$this->enabled or Scanner::isPartialFile($path)) { + return; + } /** * @var \OC\Files\Storage\Storage $storage * @var string $internalPath */ list($storage, $internalPath) = $this->view->resolvePath($path); if ($storage) { - $this->propagator->addChange($path); - $cache = $storage->getCache($internalPath); - $scanner = $storage->getScanner($internalPath); - $data = $scanner->scan($internalPath, Scanner::SCAN_SHALLOW, -1, false); $this->correctParentStorageMtime($storage, $internalPath); - $cache->correctFolderSize($internalPath, $data); - $this->propagator->propagateChanges($time); + if (!$skipPropagatingChanges) { + $data=[]; + $scanner = $storage->getScanner ( $internalPath ); + $data = $scanner->scan ( $internalPath, Scanner::SCAN_SHALLOW, - 1, false ); + $cache = $storage->getCache ( $internalPath ); + $entry = $cache->get($internalPath); + $cache->update($entry['fileid'],$data); + $this->propagator->addChange($path); + $this->propagator->propagateChanges($time); + } + } + } + + /** + * Update the cache for $path update the size and etag of the parent folders + * + * @param string $path + * @param int $time + * @param boolean $skipPropagatingChanges + */ + public function updateFolderSize($path, $time = null, $skipPropagatingChanges=false) { + if (!$this->enabled or Scanner::isPartialFile($path)) { + return; + } + /** + * @var \OC\Files\Storage\Storage $storage + * @var string $internalPath + */ + list($storage, $internalPath) = $this->view->resolvePath($path); + if ($storage) { + $scanner = $storage->getScanner ( $internalPath ); + $data = $scanner->scan ( $internalPath, Scanner::SCAN_SHALLOW, - 1, false ); + $cache = $storage->getCache ( $internalPath ); + $cache->correctFolderSize ( $internalPath, $data ); + + if (!$skipPropagatingChanges) { + $this->propagator->addChange($path); + $this->propagator->propagateChanges($time); + } } } diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 95b688fef5c2..ecad5bbfb908 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -451,7 +451,7 @@ public function filemtime($path) { * @param int|string $mtime * @return bool */ - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null, $skipPropagatingChanges=false) { if (!is_null($mtime) and !is_numeric($mtime)) { $mtime = strtotime($mtime); } @@ -462,7 +462,7 @@ public function touch($path, $mtime = null) { $hooks[] = 'create'; $hooks[] = 'write'; } - $result = $this->basicOperation('touch', $path, $hooks, $mtime); + $result = $this->basicOperation('touch', $path, $hooks, $mtime, $skipPropagatingChanges); if (!$result) { // If create file fails because of permissions on external storage like SMB folders, // check file exists and return false if not. @@ -993,7 +993,7 @@ public function free_space($path = '/') { * files), processes hooks and proxies, sanitises paths, and finally passes them on to * \OC\Files\Storage\Storage for delegation to a storage backend for execution */ - private function basicOperation($operation, $path, $hooks = array(), $extraParam = null) { + private function basicOperation($operation, $path, $hooks = array(), $extraParam = null, $skipPropagatingChanges=false) { $postFix = (substr($path, -1, 1) === '/') ? '/' : ''; $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); if (Filesystem::isValidPath($path) @@ -1037,7 +1037,7 @@ private function basicOperation($operation, $path, $hooks = array(), $extraParam $this->updater->update($path); } if (in_array('touch', $hooks)) { - $this->updater->update($path, $extraParam); + $this->updater->updateMtime($path, $extraParam, $skipPropagatingChanges); } if ((in_array('write', $hooks) || in_array('delete', $hooks)) && ($operation !== 'fopen' || $result === false)) {