diff options
author | Morris Jobke <hey@morrisjobke.de> | 2016-02-26 14:56:31 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2016-02-26 14:56:31 +0100 |
commit | bbfc5bbf30a22c268ede1223707e5d50ae9cc4f1 (patch) | |
tree | 48fd2e42be895df4a8290e30dcd559ec3e925891 | |
parent | 54f8ec8be0bf6fcd908018681542fd9689abe617 (diff) | |
parent | 1384bf5066c38f09e8c6995d26aa5c03dd63ec2c (diff) | |
download | nextcloud-server-bbfc5bbf30a22c268ede1223707e5d50ae9cc4f1.tar.gz nextcloud-server-bbfc5bbf30a22c268ede1223707e5d50ae9cc4f1.zip |
Merge pull request #22676 from owncloud/fed-share-etag-82
[8.2] use the default view for propagation if possible
-rw-r--r-- | apps/files_sharing/tests/external/ownerpropagation.php | 50 | ||||
-rw-r--r-- | lib/private/files/cache/updater.php | 33 | ||||
-rw-r--r-- | lib/private/files/view.php | 3 |
3 files changed, 78 insertions, 8 deletions
diff --git a/apps/files_sharing/tests/external/ownerpropagation.php b/apps/files_sharing/tests/external/ownerpropagation.php new file mode 100644 index 00000000000..a0e42e1a658 --- /dev/null +++ b/apps/files_sharing/tests/external/ownerpropagation.php @@ -0,0 +1,50 @@ +<?php +/** + * Copyright (c) 2016 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCA\Files_Sharing\Tests\External; + +use OC\AppFramework\Http; +use OC\Files\View; +use Test\Connector\Sabre\RequestTest\RequestTest; + +class OwnerPropagation extends RequestTest { + public function testBasicUpload() { + $user = $this->getUniqueID(); + $userView = $this->setupUser($user, 'pass'); + + $userView->mkdir('/a/b/share'); + + $subView = new View('/' . $user . '/files/a/b/share'); + $this->assertTrue($subView->is_dir('')); + + $oldInfos = [ + $userView->getFileInfo(''), + $userView->getFileInfo('a'), + $userView->getFileInfo('a/b'), + $userView->getFileInfo('a/b/share'), + ]; + + $this->assertFalse($subView->file_exists('foo.txt')); + $response = $this->request($subView, $user, 'pass', 'PUT', '/foo.txt', 'asd'); + + $this->assertEquals(Http::STATUS_CREATED, $response->getStatus()); + $this->assertTrue($subView->file_exists('foo.txt')); + $this->assertEquals('asd', $subView->file_get_contents('foo.txt')); + + $newInfos = [ + $userView->getFileInfo(''), + $userView->getFileInfo('a'), + $userView->getFileInfo('a/b'), + $userView->getFileInfo('a/b/share'), + ]; + + foreach($oldInfos as $i => $oldInfo) { + $this->assertNotEquals($oldInfo->getEtag(), $newInfos[$i]->getEtag(), 'Etag for ' . $oldInfo->getPath()); + } + } +} diff --git a/lib/private/files/cache/updater.php b/lib/private/files/cache/updater.php index 2de0c8fe067..c687d190873 100644 --- a/lib/private/files/cache/updater.php +++ b/lib/private/files/cache/updater.php @@ -24,6 +24,7 @@ */ namespace OC\Files\Cache; +use OC\Files\View; /** * Update the cache and propagate changes @@ -48,11 +49,29 @@ class Updater { protected $propagator; /** + * @var null|View + */ + protected $propagatorView; + + /** * @param \OC\Files\View $view the view the updater works on, usually the view of the logged in user + * @param View | null $userView */ - public function __construct($view) { + public function __construct(View $view, $userView = null) { $this->view = $view; - $this->propagator = new ChangePropagator($view); + + // use the userview if the view is a subfolder + if ($userView && $userView->getRelativePath($view->getRoot())) { + $this->propagatorView = $userView; + $this->propagator = new ChangePropagator($userView); + } else { + $this->propagatorView = $view; + $this->propagator = new ChangePropagator($view); + } + } + + protected function getPropagatorPath($path) { + return $this->propagatorView->getRelativePath($this->view->getAbsolutePath($path)); } /** @@ -88,7 +107,7 @@ class Updater { if (Scanner::isPartialFile($path)) { return; } - $this->propagator->addChange($path); + $this->propagator->addChange($this->getPropagatorPath($path)); $this->propagator->propagateChanges($time); } @@ -108,7 +127,7 @@ class Updater { */ list($storage, $internalPath) = $this->view->resolvePath($path); if ($storage) { - $this->propagator->addChange($path); + $this->propagator->addChange($this->getPropagatorPath($path)); $cache = $storage->getCache($internalPath); $scanner = $storage->getScanner($internalPath); $data = $scanner->scan($internalPath, Scanner::SCAN_SHALLOW, -1, false); @@ -137,7 +156,7 @@ class Updater { if ($parent === '.') { $parent = ''; } - $this->propagator->addChange($path); + $this->propagator->addChange($this->getPropagatorPath($path)); $cache = $storage->getCache($internalPath); $cache->remove($internalPath); $cache->correctFolderSize($parent); @@ -193,8 +212,8 @@ class Updater { $targetCache->correctFolderSize($targetInternalPath); $this->correctParentStorageMtime($sourceStorage, $sourceInternalPath); $this->correctParentStorageMtime($targetStorage, $targetInternalPath); - $this->propagator->addChange($source); - $this->propagator->addChange($target); + $this->propagator->addChange($this->getPropagatorPath($source)); + $this->propagator->addChange($this->getPropagatorPath($target)); $this->propagator->propagateChanges(); } } diff --git a/lib/private/files/view.php b/lib/private/files/view.php index a89f802e3d1..4f3fb5be582 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -95,7 +95,8 @@ class View { } $this->fakeRoot = $root; - $this->updater = new Updater($this); + + $this->updater = new Updater($this, Filesystem::getView()); $this->lockingProvider = \OC::$server->getLockingProvider(); $this->lockingEnabled = !($this->lockingProvider instanceof \OC\Lock\NoopLockingProvider); } |