Merge pull request #17077 from owncloud/files-scan-absolute-path

fix getting mount points when passing a path to the files:scan command
This commit is contained in:
Morris Jobke 2015-07-02 13:02:20 +02:00
commit f5c57e076e
4 changed files with 58 additions and 8 deletions

View File

@ -49,12 +49,14 @@ class UnshareChildren extends TestCase {
$this->view->mkdir($this->folder); $this->view->mkdir($this->folder);
$this->view->mkdir($this->folder . $this->subfolder); $this->view->mkdir($this->folder . $this->subfolder);
$this->view->mkdir($this->folder . $this->subfolder . $this->subsubfolder); $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); $this->view->file_put_contents($this->folder . $this->subfolder . $this->filename, $this->data);
} }
protected function tearDown() { protected function tearDown() {
if ($this->view) {
$this->view->deleteAll($this->folder); $this->view->deleteAll($this->folder);
}
self::$tempStorage = null; self::$tempStorage = null;

View File

@ -57,8 +57,14 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
*/ */
public function getMountsForUser(IUser $user) { public function getMountsForUser(IUser $user) {
$loader = $this->loader; $loader = $this->loader;
return array_reduce($this->providers, function ($mounts, IMountProvider $provider) use ($user, $loader) { $mounts = array_map(function (IMountProvider $provider) use ($user, $loader) {
return array_merge($mounts, $provider->getMountsForUser($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()); }, array());
} }

View File

@ -76,11 +76,10 @@ class Scanner extends PublicEmitter {
//TODO: move to the node based fileapi once that's done //TODO: move to the node based fileapi once that's done
\OC_Util::tearDownFS(); \OC_Util::tearDownFS();
\OC_Util::setupFS($this->user); \OC_Util::setupFS($this->user);
$absolutePath = Filesystem::getView()->getAbsolutePath($dir);
$mountManager = Filesystem::getMountManager(); $mountManager = Filesystem::getMountManager();
$mounts = $mountManager->findIn($absolutePath); $mounts = $mountManager->findIn($dir);
$mounts[] = $mountManager->find($absolutePath); $mounts[] = $mountManager->find($dir);
$mounts = array_reverse($mounts); //start with the mount of $dir $mounts = array_reverse($mounts); //start with the mount of $dir
return $mounts; return $mounts;

View File

@ -11,6 +11,8 @@ namespace Test\Files\Utils;
use OC\Files\Filesystem; use OC\Files\Filesystem;
use OC\Files\Mount\MountPoint; use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Temporary; use OC\Files\Storage\Temporary;
use OCP\Files\Storage\IStorageFactory;
use OCP\IUser;
class TestScanner extends \OC\Files\Utils\Scanner { class TestScanner extends \OC\Files\Utils\Scanner {
/** /**
@ -39,14 +41,22 @@ class TestScanner extends \OC\Files\Utils\Scanner {
} }
class Scanner extends \Test\TestCase { class Scanner extends \Test\TestCase {
/**
* @var \OC_User_Dummy
*/
private $userBackend;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$this->userBackend = new \OC_User_Dummy();
\OC::$server->getUserManager()->registerBackend($this->userBackend);
$this->loginAsUser(); $this->loginAsUser();
} }
protected function tearDown() { protected function tearDown() {
$this->logout(); $this->logout();
\OC::$server->getUserManager()->removeBackend($this->userBackend);
parent::tearDown(); parent::tearDown();
} }
@ -94,6 +104,39 @@ class Scanner extends \Test\TestCase {
$this->assertEquals($old, $new); $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() { public function testChangePropagator() {
/** /**
* @var \OC\Files\Cache\ChangePropagator $propagator * @var \OC\Files\Cache\ChangePropagator $propagator