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

@ -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;

View File

@ -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());
}

View File

@ -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;

View File

@ -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