diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-07-02 13:02:20 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-07-02 13:02:20 +0200 |
commit | f5c57e076ecf7b897a6f6bbea8f4de32e57cfba2 (patch) | |
tree | 31d4ca594624f780881dde3c50aa9e8dd0731c38 | |
parent | aedf4848f7100360d1f6695ebf23733e85b3a729 (diff) | |
parent | 8a2ef26b5e8f2f8b4235263fb25c4d94d2f06647 (diff) | |
download | nextcloud-server-f5c57e076ecf7b897a6f6bbea8f4de32e57cfba2.tar.gz nextcloud-server-f5c57e076ecf7b897a6f6bbea8f4de32e57cfba2.zip |
Merge pull request #17077 from owncloud/files-scan-absolute-path
fix getting mount points when passing a path to the files:scan command
-rw-r--r-- | apps/files_sharing/tests/unsharechildren.php | 8 | ||||
-rw-r--r-- | lib/private/files/config/mountprovidercollection.php | 10 | ||||
-rw-r--r-- | lib/private/files/utils/scanner.php | 5 | ||||
-rw-r--r-- | tests/lib/files/utils/scanner.php | 43 |
4 files changed, 58 insertions, 8 deletions
diff --git a/apps/files_sharing/tests/unsharechildren.php b/apps/files_sharing/tests/unsharechildren.php index 0cf551c0500..c57070ba641 100644 --- a/apps/files_sharing/tests/unsharechildren.php +++ b/apps/files_sharing/tests/unsharechildren.php @@ -40,7 +40,7 @@ class UnshareChildren extends TestCase { \OCP\Util::connectHook('OC_Filesystem', 'post_delete', '\OCA\Files_Sharing\Hooks', 'unshareChildren'); $this->folder = self::TEST_FOLDER_NAME; - $this->subfolder = '/subfolder_share_api_test'; + $this->subfolder = '/subfolder_share_api_test'; $this->subsubfolder = '/subsubfolder_share_api_test'; $this->filename = '/share-api-test'; @@ -49,12 +49,14 @@ class UnshareChildren extends TestCase { $this->view->mkdir($this->folder); $this->view->mkdir($this->folder . $this->subfolder); $this->view->mkdir($this->folder . $this->subfolder . $this->subsubfolder); - $this->view->file_put_contents($this->folder.$this->filename, $this->data); + $this->view->file_put_contents($this->folder . $this->filename, $this->data); $this->view->file_put_contents($this->folder . $this->subfolder . $this->filename, $this->data); } protected function tearDown() { - $this->view->deleteAll($this->folder); + if ($this->view) { + $this->view->deleteAll($this->folder); + } self::$tempStorage = null; diff --git a/lib/private/files/config/mountprovidercollection.php b/lib/private/files/config/mountprovidercollection.php index a14a6ef796f..c75c64ae445 100644 --- a/lib/private/files/config/mountprovidercollection.php +++ b/lib/private/files/config/mountprovidercollection.php @@ -57,8 +57,14 @@ class MountProviderCollection implements IMountProviderCollection, Emitter { */ public function getMountsForUser(IUser $user) { $loader = $this->loader; - return array_reduce($this->providers, function ($mounts, IMountProvider $provider) use ($user, $loader) { - return array_merge($mounts, $provider->getMountsForUser($user, $loader)); + $mounts = array_map(function (IMountProvider $provider) use ($user, $loader) { + return $provider->getMountsForUser($user, $loader); + }, $this->providers); + $mounts = array_filter($mounts, function ($result) { + return is_array($result); + }); + return array_reduce($mounts, function (array $mounts, array $providerMounts) { + return array_merge($mounts, $providerMounts); }, array()); } diff --git a/lib/private/files/utils/scanner.php b/lib/private/files/utils/scanner.php index 23a9e26b3bc..3d68eb530a2 100644 --- a/lib/private/files/utils/scanner.php +++ b/lib/private/files/utils/scanner.php @@ -76,11 +76,10 @@ class Scanner extends PublicEmitter { //TODO: move to the node based fileapi once that's done \OC_Util::tearDownFS(); \OC_Util::setupFS($this->user); - $absolutePath = Filesystem::getView()->getAbsolutePath($dir); $mountManager = Filesystem::getMountManager(); - $mounts = $mountManager->findIn($absolutePath); - $mounts[] = $mountManager->find($absolutePath); + $mounts = $mountManager->findIn($dir); + $mounts[] = $mountManager->find($dir); $mounts = array_reverse($mounts); //start with the mount of $dir return $mounts; diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php index dfc683c1bcf..ca64b1db72e 100644 --- a/tests/lib/files/utils/scanner.php +++ b/tests/lib/files/utils/scanner.php @@ -11,6 +11,8 @@ namespace Test\Files\Utils; use OC\Files\Filesystem; use OC\Files\Mount\MountPoint; use OC\Files\Storage\Temporary; +use OCP\Files\Storage\IStorageFactory; +use OCP\IUser; class TestScanner extends \OC\Files\Utils\Scanner { /** @@ -39,14 +41,22 @@ class TestScanner extends \OC\Files\Utils\Scanner { } class Scanner extends \Test\TestCase { + /** + * @var \OC_User_Dummy + */ + private $userBackend; + protected function setUp() { parent::setUp(); + $this->userBackend = new \OC_User_Dummy(); + \OC::$server->getUserManager()->registerBackend($this->userBackend); $this->loginAsUser(); } protected function tearDown() { $this->logout(); + \OC::$server->getUserManager()->removeBackend($this->userBackend); parent::tearDown(); } @@ -94,6 +104,39 @@ class Scanner extends \Test\TestCase { $this->assertEquals($old, $new); } + public function testScanSubMount() { + $uid = $this->getUniqueID(); + $this->userBackend->createUser($uid, 'test'); + + $mountProvider = $this->getMock('\OCP\Files\Config\IMountProvider'); + + $storage = new Temporary(array()); + $mount = new MountPoint($storage, '/' . $uid . '/files/foo'); + + $mountProvider->expects($this->any()) + ->method('getMountsForUser') + ->will($this->returnCallback(function (IUser $user, IStorageFactory $storageFactory) use ($mount, $uid) { + if ($user->getUID() === $uid) { + return [$mount]; + } else { + return []; + } + })); + + \OC::$server->getMountProviderCollection()->registerProvider($mountProvider); + $cache = $storage->getCache(); + + $storage->mkdir('folder'); + $storage->file_put_contents('foo.txt', 'qwerty'); + $storage->file_put_contents('folder/bar.txt', 'qwerty'); + + $scanner = new \OC\Files\Utils\Scanner($uid, \OC::$server->getDatabaseConnection()); + + $this->assertFalse($cache->inCache('folder/bar.txt')); + $scanner->scan('/' . $uid . '/files/foo'); + $this->assertTrue($cache->inCache('folder/bar.txt')); + } + public function testChangePropagator() { /** * @var \OC\Files\Cache\ChangePropagator $propagator |