2012-10-21 04:12:58 +04:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
|
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
|
* later.
|
|
|
|
|
* See the COPYING-README file. */
|
|
|
|
|
|
2012-10-26 14:30:25 +04:00
|
|
|
|
namespace Test\Files;
|
|
|
|
|
|
2014-02-18 19:31:40 +04:00
|
|
|
|
use OC\Files\Cache\Watcher;
|
2014-10-14 19:15:46 +04:00
|
|
|
|
use OC\Files\Storage\Temporary;
|
2014-02-18 19:31:40 +04:00
|
|
|
|
|
2013-02-10 15:44:27 +04:00
|
|
|
|
class TemporaryNoTouch extends \OC\Files\Storage\Temporary {
|
|
|
|
|
public function touch($path, $mtime = null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-07 17:23:15 +03:00
|
|
|
|
class View extends \Test\TestCase {
|
2012-10-21 04:12:58 +04:00
|
|
|
|
/**
|
2013-12-12 18:14:44 +04:00
|
|
|
|
* @var \OC\Files\Storage\Storage[] $storages
|
2012-10-21 04:12:58 +04:00
|
|
|
|
*/
|
|
|
|
|
private $storages = array();
|
2014-05-08 17:19:54 +04:00
|
|
|
|
private $user;
|
2012-10-21 04:12:58 +04:00
|
|
|
|
|
2014-11-12 17:54:41 +03:00
|
|
|
|
/** @var \OC\Files\Storage\Storage */
|
2014-06-06 12:41:49 +04:00
|
|
|
|
private $tempStorage;
|
|
|
|
|
|
2014-11-12 17:54:41 +03:00
|
|
|
|
/** @var \OC\Files\Storage\Storage */
|
|
|
|
|
private $originalStorage;
|
|
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
2013-06-26 22:48:54 +04:00
|
|
|
|
\OC_User::clearBackends();
|
|
|
|
|
\OC_User::useBackend(new \OC_User_Dummy());
|
|
|
|
|
|
|
|
|
|
//login
|
|
|
|
|
\OC_User::createUser('test', 'test');
|
2013-08-29 17:25:38 +04:00
|
|
|
|
$this->user = \OC_User::getUser();
|
2013-06-26 22:48:54 +04:00
|
|
|
|
\OC_User::setUserId('test');
|
|
|
|
|
|
2014-11-12 17:54:41 +03:00
|
|
|
|
$this->originalStorage = \OC\Files\Filesystem::getStorage('/');
|
2012-10-26 20:07:01 +04:00
|
|
|
|
\OC\Files\Filesystem::clearMounts();
|
2014-06-06 12:41:49 +04:00
|
|
|
|
|
|
|
|
|
$this->tempStorage = null;
|
2012-10-21 04:12:58 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-12 17:54:41 +03:00
|
|
|
|
protected function tearDown() {
|
2013-06-26 22:48:54 +04:00
|
|
|
|
\OC_User::setUserId($this->user);
|
2012-10-21 04:12:58 +04:00
|
|
|
|
foreach ($this->storages as $storage) {
|
|
|
|
|
$cache = $storage->getCache();
|
2012-10-28 14:26:31 +04:00
|
|
|
|
$ids = $cache->getAll();
|
2012-10-21 04:12:58 +04:00
|
|
|
|
$cache->clear();
|
|
|
|
|
}
|
2014-06-06 12:41:49 +04:00
|
|
|
|
|
|
|
|
|
if ($this->tempStorage && !\OC_Util::runningOnWindows()) {
|
|
|
|
|
system('rm -rf ' . escapeshellarg($this->tempStorage->getDataDir()));
|
|
|
|
|
}
|
2014-11-12 17:54:41 +03:00
|
|
|
|
|
|
|
|
|
\OC\Files\Filesystem::clearMounts();
|
|
|
|
|
\OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
|
|
|
|
|
|
|
|
|
|
parent::tearDown();
|
2012-10-21 04:12:58 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
|
/**
|
|
|
|
|
* @medium
|
|
|
|
|
*/
|
2012-10-21 04:12:58 +04:00
|
|
|
|
public function testCacheAPI() {
|
|
|
|
|
$storage1 = $this->getTestStorage();
|
|
|
|
|
$storage2 = $this->getTestStorage();
|
|
|
|
|
$storage3 = $this->getTestStorage();
|
2014-06-03 13:34:48 +04:00
|
|
|
|
$root = '/' . uniqid();
|
|
|
|
|
\OC\Files\Filesystem::mount($storage1, array(), $root . '/');
|
|
|
|
|
\OC\Files\Filesystem::mount($storage2, array(), $root . '/substorage');
|
|
|
|
|
\OC\Files\Filesystem::mount($storage3, array(), $root . '/folder/anotherstorage');
|
2012-10-21 04:12:58 +04:00
|
|
|
|
$textSize = strlen("dummy file data\n");
|
|
|
|
|
$imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
|
|
|
|
|
$storageSize = $textSize * 2 + $imageSize;
|
|
|
|
|
|
2014-06-03 13:34:48 +04:00
|
|
|
|
$storageInfo = $storage3->getCache()->get('');
|
|
|
|
|
$this->assertEquals($storageSize, $storageInfo['size']);
|
|
|
|
|
|
|
|
|
|
$rootView = new \OC\Files\View($root);
|
2012-10-26 14:30:25 +04:00
|
|
|
|
|
|
|
|
|
$cachedData = $rootView->getFileInfo('/foo.txt');
|
2012-10-21 04:12:58 +04:00
|
|
|
|
$this->assertEquals($textSize, $cachedData['size']);
|
|
|
|
|
$this->assertEquals('text/plain', $cachedData['mimetype']);
|
2013-01-07 04:03:11 +04:00
|
|
|
|
$this->assertNotEquals(-1, $cachedData['permissions']);
|
2012-10-21 04:12:58 +04:00
|
|
|
|
|
2012-10-26 14:30:25 +04:00
|
|
|
|
$cachedData = $rootView->getFileInfo('/');
|
2012-10-21 04:12:58 +04:00
|
|
|
|
$this->assertEquals($storageSize * 3, $cachedData['size']);
|
|
|
|
|
$this->assertEquals('httpd/unix-directory', $cachedData['mimetype']);
|
|
|
|
|
|
2013-11-18 20:29:30 +04:00
|
|
|
|
// get cached data excluding mount points
|
|
|
|
|
$cachedData = $rootView->getFileInfo('/', false);
|
|
|
|
|
$this->assertEquals($storageSize, $cachedData['size']);
|
|
|
|
|
$this->assertEquals('httpd/unix-directory', $cachedData['mimetype']);
|
|
|
|
|
|
2012-10-26 14:30:25 +04:00
|
|
|
|
$cachedData = $rootView->getFileInfo('/folder');
|
2012-10-21 04:12:58 +04:00
|
|
|
|
$this->assertEquals($storageSize + $textSize, $cachedData['size']);
|
|
|
|
|
$this->assertEquals('httpd/unix-directory', $cachedData['mimetype']);
|
|
|
|
|
|
2012-10-26 14:30:25 +04:00
|
|
|
|
$folderData = $rootView->getDirectoryContent('/');
|
2012-10-21 04:12:58 +04:00
|
|
|
|
/**
|
|
|
|
|
* expected entries:
|
2012-11-25 19:08:35 +04:00
|
|
|
|
* folder
|
2012-10-21 04:12:58 +04:00
|
|
|
|
* foo.png
|
|
|
|
|
* foo.txt
|
|
|
|
|
* substorage
|
|
|
|
|
*/
|
|
|
|
|
$this->assertEquals(4, count($folderData));
|
2012-11-25 19:08:35 +04:00
|
|
|
|
$this->assertEquals('folder', $folderData[0]['name']);
|
|
|
|
|
$this->assertEquals('foo.png', $folderData[1]['name']);
|
|
|
|
|
$this->assertEquals('foo.txt', $folderData[2]['name']);
|
2012-10-21 04:12:58 +04:00
|
|
|
|
$this->assertEquals('substorage', $folderData[3]['name']);
|
|
|
|
|
|
2012-11-25 19:08:35 +04:00
|
|
|
|
$this->assertEquals($storageSize + $textSize, $folderData[0]['size']);
|
|
|
|
|
$this->assertEquals($imageSize, $folderData[1]['size']);
|
|
|
|
|
$this->assertEquals($textSize, $folderData[2]['size']);
|
2012-10-21 04:12:58 +04:00
|
|
|
|
$this->assertEquals($storageSize, $folderData[3]['size']);
|
2012-10-26 14:37:49 +04:00
|
|
|
|
|
2012-11-25 02:41:39 +04:00
|
|
|
|
$folderData = $rootView->getDirectoryContent('/substorage');
|
|
|
|
|
/**
|
|
|
|
|
* expected entries:
|
2012-11-25 19:08:35 +04:00
|
|
|
|
* folder
|
2012-11-25 02:41:39 +04:00
|
|
|
|
* foo.png
|
|
|
|
|
* foo.txt
|
|
|
|
|
*/
|
|
|
|
|
$this->assertEquals(3, count($folderData));
|
2012-11-25 19:08:35 +04:00
|
|
|
|
$this->assertEquals('folder', $folderData[0]['name']);
|
|
|
|
|
$this->assertEquals('foo.png', $folderData[1]['name']);
|
|
|
|
|
$this->assertEquals('foo.txt', $folderData[2]['name']);
|
2012-11-25 02:41:39 +04:00
|
|
|
|
|
2014-06-03 13:34:48 +04:00
|
|
|
|
$folderView = new \OC\Files\View($root . '/folder');
|
2012-10-26 14:37:49 +04:00
|
|
|
|
$this->assertEquals($rootView->getFileInfo('/folder'), $folderView->getFileInfo('/'));
|
2012-10-26 14:43:23 +04:00
|
|
|
|
|
|
|
|
|
$cachedData = $rootView->getFileInfo('/foo.txt');
|
|
|
|
|
$this->assertFalse($cachedData['encrypted']);
|
|
|
|
|
$id = $rootView->putFileInfo('/foo.txt', array('encrypted' => true));
|
|
|
|
|
$cachedData = $rootView->getFileInfo('/foo.txt');
|
|
|
|
|
$this->assertTrue($cachedData['encrypted']);
|
|
|
|
|
$this->assertEquals($cachedData['fileid'], $id);
|
2012-12-11 04:06:21 +04:00
|
|
|
|
|
|
|
|
|
$this->assertFalse($rootView->getFileInfo('/non/existing'));
|
|
|
|
|
$this->assertEquals(array(), $rootView->getDirectoryContent('/non/existing'));
|
2012-10-21 04:12:58 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
|
/**
|
|
|
|
|
* @medium
|
|
|
|
|
*/
|
2013-01-27 03:13:16 +04:00
|
|
|
|
function testGetPath() {
|
|
|
|
|
$storage1 = $this->getTestStorage();
|
|
|
|
|
$storage2 = $this->getTestStorage();
|
|
|
|
|
$storage3 = $this->getTestStorage();
|
|
|
|
|
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
|
|
|
|
\OC\Files\Filesystem::mount($storage2, array(), '/substorage');
|
|
|
|
|
\OC\Files\Filesystem::mount($storage3, array(), '/folder/anotherstorage');
|
|
|
|
|
|
|
|
|
|
$rootView = new \OC\Files\View('');
|
|
|
|
|
|
|
|
|
|
$cachedData = $rootView->getFileInfo('/foo.txt');
|
|
|
|
|
$id1 = $cachedData['fileid'];
|
|
|
|
|
$this->assertEquals('/foo.txt', $rootView->getPath($id1));
|
|
|
|
|
|
|
|
|
|
$cachedData = $rootView->getFileInfo('/substorage/foo.txt');
|
|
|
|
|
$id2 = $cachedData['fileid'];
|
|
|
|
|
$this->assertEquals('/substorage/foo.txt', $rootView->getPath($id2));
|
|
|
|
|
|
|
|
|
|
$folderView = new \OC\Files\View('/substorage');
|
|
|
|
|
$this->assertEquals('/foo.txt', $folderView->getPath($id2));
|
|
|
|
|
$this->assertNull($folderView->getPath($id1));
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
|
/**
|
|
|
|
|
* @medium
|
|
|
|
|
*/
|
2013-01-22 23:57:15 +04:00
|
|
|
|
function testMountPointOverwrite() {
|
|
|
|
|
$storage1 = $this->getTestStorage(false);
|
|
|
|
|
$storage2 = $this->getTestStorage();
|
|
|
|
|
$storage1->mkdir('substorage');
|
|
|
|
|
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
|
|
|
|
\OC\Files\Filesystem::mount($storage2, array(), '/substorage');
|
|
|
|
|
|
|
|
|
|
$rootView = new \OC\Files\View('');
|
|
|
|
|
$folderContent = $rootView->getDirectoryContent('/');
|
|
|
|
|
$this->assertEquals(4, count($folderContent));
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-15 06:20:50 +04:00
|
|
|
|
function testCacheIncompleteFolder() {
|
|
|
|
|
$storage1 = $this->getTestStorage(false);
|
2014-10-16 17:17:36 +04:00
|
|
|
|
\OC\Files\Filesystem::clearMounts();
|
|
|
|
|
\OC\Files\Filesystem::mount($storage1, array(), '/incomplete');
|
|
|
|
|
$rootView = new \OC\Files\View('/incomplete');
|
2012-12-15 06:20:50 +04:00
|
|
|
|
|
|
|
|
|
$entries = $rootView->getDirectoryContent('/');
|
|
|
|
|
$this->assertEquals(3, count($entries));
|
|
|
|
|
|
|
|
|
|
// /folder will already be in the cache but not scanned
|
|
|
|
|
$entries = $rootView->getDirectoryContent('/folder');
|
|
|
|
|
$this->assertEquals(1, count($entries));
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-22 00:05:29 +04:00
|
|
|
|
public function testAutoScan() {
|
|
|
|
|
$storage1 = $this->getTestStorage(false);
|
|
|
|
|
$storage2 = $this->getTestStorage(false);
|
2012-10-26 20:07:01 +04:00
|
|
|
|
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
|
|
|
|
\OC\Files\Filesystem::mount($storage2, array(), '/substorage');
|
2012-10-22 00:05:29 +04:00
|
|
|
|
$textSize = strlen("dummy file data\n");
|
|
|
|
|
|
2012-10-26 14:30:25 +04:00
|
|
|
|
$rootView = new \OC\Files\View('');
|
|
|
|
|
|
|
|
|
|
$cachedData = $rootView->getFileInfo('/');
|
2012-10-22 00:05:29 +04:00
|
|
|
|
$this->assertEquals('httpd/unix-directory', $cachedData['mimetype']);
|
|
|
|
|
$this->assertEquals(-1, $cachedData['size']);
|
|
|
|
|
|
2012-10-26 14:30:25 +04:00
|
|
|
|
$folderData = $rootView->getDirectoryContent('/substorage/folder');
|
2012-10-22 00:05:29 +04:00
|
|
|
|
$this->assertEquals('text/plain', $folderData[0]['mimetype']);
|
|
|
|
|
$this->assertEquals($textSize, $folderData[0]['size']);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
|
/**
|
|
|
|
|
* @medium
|
|
|
|
|
*/
|
2012-10-26 15:23:15 +04:00
|
|
|
|
function testSearch() {
|
|
|
|
|
$storage1 = $this->getTestStorage();
|
|
|
|
|
$storage2 = $this->getTestStorage();
|
|
|
|
|
$storage3 = $this->getTestStorage();
|
2012-10-26 20:07:01 +04:00
|
|
|
|
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
|
|
|
|
\OC\Files\Filesystem::mount($storage2, array(), '/substorage');
|
|
|
|
|
\OC\Files\Filesystem::mount($storage3, array(), '/folder/anotherstorage');
|
2012-10-26 15:23:15 +04:00
|
|
|
|
|
|
|
|
|
$rootView = new \OC\Files\View('');
|
|
|
|
|
|
|
|
|
|
$results = $rootView->search('foo');
|
|
|
|
|
$this->assertEquals(6, count($results));
|
|
|
|
|
$paths = array();
|
|
|
|
|
foreach ($results as $result) {
|
2012-10-26 20:07:01 +04:00
|
|
|
|
$this->assertEquals($result['path'], \OC\Files\Filesystem::normalizePath($result['path']));
|
2012-10-26 15:23:15 +04:00
|
|
|
|
$paths[] = $result['path'];
|
|
|
|
|
}
|
|
|
|
|
$this->assertContains('/foo.txt', $paths);
|
|
|
|
|
$this->assertContains('/foo.png', $paths);
|
|
|
|
|
$this->assertContains('/substorage/foo.txt', $paths);
|
|
|
|
|
$this->assertContains('/substorage/foo.png', $paths);
|
|
|
|
|
$this->assertContains('/folder/anotherstorage/foo.txt', $paths);
|
|
|
|
|
$this->assertContains('/folder/anotherstorage/foo.png', $paths);
|
|
|
|
|
|
|
|
|
|
$folderView = new \OC\Files\View('/folder');
|
|
|
|
|
$results = $folderView->search('bar');
|
|
|
|
|
$this->assertEquals(2, count($results));
|
|
|
|
|
$paths = array();
|
|
|
|
|
foreach ($results as $result) {
|
|
|
|
|
$paths[] = $result['path'];
|
|
|
|
|
}
|
|
|
|
|
$this->assertContains('/anotherstorage/folder/bar.txt', $paths);
|
|
|
|
|
$this->assertContains('/bar.txt', $paths);
|
|
|
|
|
|
|
|
|
|
$results = $folderView->search('foo');
|
|
|
|
|
$this->assertEquals(2, count($results));
|
|
|
|
|
$paths = array();
|
|
|
|
|
foreach ($results as $result) {
|
|
|
|
|
$paths[] = $result['path'];
|
|
|
|
|
}
|
|
|
|
|
$this->assertContains('/anotherstorage/foo.txt', $paths);
|
|
|
|
|
$this->assertContains('/anotherstorage/foo.png', $paths);
|
2012-10-27 12:34:25 +04:00
|
|
|
|
|
|
|
|
|
$this->assertEquals(6, count($rootView->searchByMime('text')));
|
|
|
|
|
$this->assertEquals(3, count($folderView->searchByMime('text')));
|
2012-10-26 15:23:15 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
|
/**
|
|
|
|
|
* @medium
|
|
|
|
|
*/
|
2012-10-28 14:43:45 +04:00
|
|
|
|
function testWatcher() {
|
|
|
|
|
$storage1 = $this->getTestStorage();
|
|
|
|
|
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
2014-02-18 19:31:40 +04:00
|
|
|
|
$storage1->getWatcher()->setPolicy(Watcher::CHECK_ALWAYS);
|
2012-10-28 14:43:45 +04:00
|
|
|
|
|
|
|
|
|
$rootView = new \OC\Files\View('');
|
|
|
|
|
|
|
|
|
|
$cachedData = $rootView->getFileInfo('foo.txt');
|
|
|
|
|
$this->assertEquals(16, $cachedData['size']);
|
|
|
|
|
|
2013-02-10 15:27:35 +04:00
|
|
|
|
$rootView->putFileInfo('foo.txt', array('storage_mtime' => 10));
|
2012-10-28 14:43:45 +04:00
|
|
|
|
$storage1->file_put_contents('foo.txt', 'foo');
|
|
|
|
|
clearstatcache();
|
|
|
|
|
|
|
|
|
|
$cachedData = $rootView->getFileInfo('foo.txt');
|
|
|
|
|
$this->assertEquals(3, $cachedData['size']);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
|
/**
|
|
|
|
|
* @medium
|
|
|
|
|
*/
|
2013-05-19 22:20:46 +04:00
|
|
|
|
function testCopyBetweenStorages() {
|
|
|
|
|
$storage1 = $this->getTestStorage();
|
|
|
|
|
$storage2 = $this->getTestStorage();
|
|
|
|
|
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
|
|
|
|
\OC\Files\Filesystem::mount($storage2, array(), '/substorage');
|
|
|
|
|
|
|
|
|
|
$rootView = new \OC\Files\View('');
|
2013-05-19 23:04:41 +04:00
|
|
|
|
$rootView->mkdir('substorage/emptyfolder');
|
2013-05-19 22:20:46 +04:00
|
|
|
|
$rootView->copy('substorage', 'anotherfolder');
|
|
|
|
|
$this->assertTrue($rootView->is_dir('/anotherfolder'));
|
|
|
|
|
$this->assertTrue($rootView->is_dir('/substorage'));
|
2013-05-19 23:04:41 +04:00
|
|
|
|
$this->assertTrue($rootView->is_dir('/anotherfolder/emptyfolder'));
|
|
|
|
|
$this->assertTrue($rootView->is_dir('/substorage/emptyfolder'));
|
2013-05-19 22:20:46 +04:00
|
|
|
|
$this->assertTrue($rootView->file_exists('/anotherfolder/foo.txt'));
|
|
|
|
|
$this->assertTrue($rootView->file_exists('/anotherfolder/foo.png'));
|
|
|
|
|
$this->assertTrue($rootView->file_exists('/anotherfolder/folder/bar.txt'));
|
|
|
|
|
$this->assertTrue($rootView->file_exists('/substorage/foo.txt'));
|
|
|
|
|
$this->assertTrue($rootView->file_exists('/substorage/foo.png'));
|
|
|
|
|
$this->assertTrue($rootView->file_exists('/substorage/folder/bar.txt'));
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
|
/**
|
|
|
|
|
* @medium
|
|
|
|
|
*/
|
2013-05-19 22:20:46 +04:00
|
|
|
|
function testMoveBetweenStorages() {
|
|
|
|
|
$storage1 = $this->getTestStorage();
|
|
|
|
|
$storage2 = $this->getTestStorage();
|
|
|
|
|
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
|
|
|
|
\OC\Files\Filesystem::mount($storage2, array(), '/substorage');
|
|
|
|
|
|
|
|
|
|
$rootView = new \OC\Files\View('');
|
|
|
|
|
$rootView->rename('foo.txt', 'substorage/folder/foo.txt');
|
|
|
|
|
$this->assertFalse($rootView->file_exists('foo.txt'));
|
|
|
|
|
$this->assertTrue($rootView->file_exists('substorage/folder/foo.txt'));
|
|
|
|
|
$rootView->rename('substorage/folder', 'anotherfolder');
|
|
|
|
|
$this->assertFalse($rootView->is_dir('substorage/folder'));
|
|
|
|
|
$this->assertTrue($rootView->file_exists('anotherfolder/foo.txt'));
|
|
|
|
|
$this->assertTrue($rootView->file_exists('anotherfolder/bar.txt'));
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-08 16:17:36 +04:00
|
|
|
|
/**
|
|
|
|
|
* @medium
|
|
|
|
|
*/
|
|
|
|
|
function testUnlink() {
|
|
|
|
|
$storage1 = $this->getTestStorage();
|
|
|
|
|
$storage2 = $this->getTestStorage();
|
|
|
|
|
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
|
|
|
|
\OC\Files\Filesystem::mount($storage2, array(), '/substorage');
|
|
|
|
|
|
|
|
|
|
$rootView = new \OC\Files\View('');
|
|
|
|
|
$rootView->file_put_contents('/foo.txt', 'asd');
|
|
|
|
|
$rootView->file_put_contents('/substorage/bar.txt', 'asd');
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($rootView->file_exists('foo.txt'));
|
|
|
|
|
$this->assertTrue($rootView->file_exists('substorage/bar.txt'));
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($rootView->unlink('foo.txt'));
|
|
|
|
|
$this->assertTrue($rootView->unlink('substorage/bar.txt'));
|
|
|
|
|
|
|
|
|
|
$this->assertFalse($rootView->file_exists('foo.txt'));
|
|
|
|
|
$this->assertFalse($rootView->file_exists('substorage/bar.txt'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @medium
|
|
|
|
|
*/
|
|
|
|
|
function testUnlinkRootMustFail() {
|
|
|
|
|
$storage1 = $this->getTestStorage();
|
|
|
|
|
$storage2 = $this->getTestStorage();
|
|
|
|
|
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
|
|
|
|
\OC\Files\Filesystem::mount($storage2, array(), '/substorage');
|
|
|
|
|
|
|
|
|
|
$rootView = new \OC\Files\View('');
|
|
|
|
|
$rootView->file_put_contents('/foo.txt', 'asd');
|
|
|
|
|
$rootView->file_put_contents('/substorage/bar.txt', 'asd');
|
|
|
|
|
|
|
|
|
|
$this->assertFalse($rootView->unlink(''));
|
|
|
|
|
$this->assertFalse($rootView->unlink('/'));
|
|
|
|
|
$this->assertFalse($rootView->unlink('substorage'));
|
|
|
|
|
$this->assertFalse($rootView->unlink('/substorage'));
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
|
/**
|
|
|
|
|
* @medium
|
|
|
|
|
*/
|
2013-02-10 15:44:27 +04:00
|
|
|
|
function testTouch() {
|
|
|
|
|
$storage = $this->getTestStorage(true, '\Test\Files\TemporaryNoTouch');
|
|
|
|
|
|
|
|
|
|
\OC\Files\Filesystem::mount($storage, array(), '/');
|
|
|
|
|
|
|
|
|
|
$rootView = new \OC\Files\View('');
|
|
|
|
|
$oldCachedData = $rootView->getFileInfo('foo.txt');
|
|
|
|
|
|
|
|
|
|
$rootView->touch('foo.txt', 500);
|
|
|
|
|
|
|
|
|
|
$cachedData = $rootView->getFileInfo('foo.txt');
|
|
|
|
|
$this->assertEquals(500, $cachedData['mtime']);
|
|
|
|
|
$this->assertEquals($oldCachedData['storage_mtime'], $cachedData['storage_mtime']);
|
|
|
|
|
|
|
|
|
|
$rootView->putFileInfo('foo.txt', array('storage_mtime' => 1000)); //make sure the watcher detects the change
|
|
|
|
|
$rootView->file_put_contents('foo.txt', 'asd');
|
|
|
|
|
$cachedData = $rootView->getFileInfo('foo.txt');
|
2014-08-04 18:17:11 +04:00
|
|
|
|
$this->assertGreaterThanOrEqual($oldCachedData['mtime'], $cachedData['mtime']);
|
2013-02-10 15:44:27 +04:00
|
|
|
|
$this->assertEquals($cachedData['storage_mtime'], $cachedData['mtime']);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-29 17:25:38 +04:00
|
|
|
|
/**
|
|
|
|
|
* @medium
|
|
|
|
|
*/
|
|
|
|
|
function testViewHooks() {
|
|
|
|
|
$storage1 = $this->getTestStorage();
|
|
|
|
|
$storage2 = $this->getTestStorage();
|
|
|
|
|
$defaultRoot = \OC\Files\Filesystem::getRoot();
|
|
|
|
|
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
|
|
|
|
\OC\Files\Filesystem::mount($storage2, array(), $defaultRoot . '/substorage');
|
|
|
|
|
\OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
|
|
|
|
|
|
|
|
|
|
$rootView = new \OC\Files\View('');
|
|
|
|
|
$subView = new \OC\Files\View($defaultRoot . '/substorage');
|
|
|
|
|
$this->hookPath = null;
|
|
|
|
|
|
|
|
|
|
$rootView->file_put_contents('/foo.txt', 'asd');
|
|
|
|
|
$this->assertNull($this->hookPath);
|
|
|
|
|
|
|
|
|
|
$subView->file_put_contents('/foo.txt', 'asd');
|
|
|
|
|
$this->assertEquals('/substorage/foo.txt', $this->hookPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private $hookPath;
|
|
|
|
|
|
2014-04-28 12:49:35 +04:00
|
|
|
|
public function dummyHook($params) {
|
2013-08-29 17:25:38 +04:00
|
|
|
|
$this->hookPath = $params['path'];
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-22 03:23:18 +04:00
|
|
|
|
public function testSearchNotOutsideView() {
|
|
|
|
|
$storage1 = $this->getTestStorage();
|
|
|
|
|
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
|
|
|
|
$storage1->rename('folder', 'foo');
|
|
|
|
|
$scanner = $storage1->getScanner();
|
|
|
|
|
$scanner->scan('');
|
|
|
|
|
|
|
|
|
|
$view = new \OC\Files\View('/foo');
|
|
|
|
|
|
|
|
|
|
$result = $view->search('.txt');
|
|
|
|
|
$this->assertCount(1, $result);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-21 04:12:58 +04:00
|
|
|
|
/**
|
2012-10-22 00:05:29 +04:00
|
|
|
|
* @param bool $scan
|
2013-09-22 03:23:18 +04:00
|
|
|
|
* @param string $class
|
2012-10-26 14:30:25 +04:00
|
|
|
|
* @return \OC\Files\Storage\Storage
|
2012-10-21 04:12:58 +04:00
|
|
|
|
*/
|
2013-02-10 15:44:27 +04:00
|
|
|
|
private function getTestStorage($scan = true, $class = '\OC\Files\Storage\Temporary') {
|
|
|
|
|
/**
|
|
|
|
|
* @var \OC\Files\Storage\Storage $storage
|
|
|
|
|
*/
|
|
|
|
|
$storage = new $class(array());
|
2012-10-21 04:12:58 +04:00
|
|
|
|
$textData = "dummy file data\n";
|
|
|
|
|
$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
|
|
|
|
|
$storage->mkdir('folder');
|
|
|
|
|
$storage->file_put_contents('foo.txt', $textData);
|
|
|
|
|
$storage->file_put_contents('foo.png', $imgData);
|
|
|
|
|
$storage->file_put_contents('folder/bar.txt', $textData);
|
|
|
|
|
|
2012-10-22 00:05:29 +04:00
|
|
|
|
if ($scan) {
|
|
|
|
|
$scanner = $storage->getScanner();
|
|
|
|
|
$scanner->scan('');
|
|
|
|
|
}
|
2012-10-21 04:12:58 +04:00
|
|
|
|
$this->storages[] = $storage;
|
|
|
|
|
return $storage;
|
|
|
|
|
}
|
2013-10-09 22:46:43 +04:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @medium
|
|
|
|
|
*/
|
|
|
|
|
function testViewHooksIfRootStartsTheSame() {
|
|
|
|
|
$storage1 = $this->getTestStorage();
|
|
|
|
|
$storage2 = $this->getTestStorage();
|
|
|
|
|
$defaultRoot = \OC\Files\Filesystem::getRoot();
|
|
|
|
|
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
|
|
|
|
\OC\Files\Filesystem::mount($storage2, array(), $defaultRoot . '_substorage');
|
|
|
|
|
\OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
|
|
|
|
|
|
|
|
|
|
$subView = new \OC\Files\View($defaultRoot . '_substorage');
|
|
|
|
|
$this->hookPath = null;
|
|
|
|
|
|
|
|
|
|
$subView->file_put_contents('/foo.txt', 'asd');
|
|
|
|
|
$this->assertNull($this->hookPath);
|
|
|
|
|
}
|
2013-10-10 13:34:30 +04:00
|
|
|
|
|
2014-04-28 12:49:35 +04:00
|
|
|
|
private $hookWritePath;
|
|
|
|
|
private $hookCreatePath;
|
|
|
|
|
private $hookUpdatePath;
|
|
|
|
|
|
|
|
|
|
public function dummyHookWrite($params) {
|
|
|
|
|
$this->hookWritePath = $params['path'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function dummyHookUpdate($params) {
|
|
|
|
|
$this->hookUpdatePath = $params['path'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function dummyHookCreate($params) {
|
|
|
|
|
$this->hookCreatePath = $params['path'];
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-09 22:34:18 +04:00
|
|
|
|
public function testEditNoCreateHook() {
|
|
|
|
|
$storage1 = $this->getTestStorage();
|
|
|
|
|
$storage2 = $this->getTestStorage();
|
|
|
|
|
$defaultRoot = \OC\Files\Filesystem::getRoot();
|
|
|
|
|
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
|
|
|
|
\OC\Files\Filesystem::mount($storage2, array(), $defaultRoot);
|
2014-04-28 12:49:35 +04:00
|
|
|
|
\OC_Hook::connect('OC_Filesystem', 'post_create', $this, 'dummyHookCreate');
|
|
|
|
|
\OC_Hook::connect('OC_Filesystem', 'post_update', $this, 'dummyHookUpdate');
|
|
|
|
|
\OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHookWrite');
|
2013-10-09 22:34:18 +04:00
|
|
|
|
|
|
|
|
|
$view = new \OC\Files\View($defaultRoot);
|
2014-04-28 12:49:35 +04:00
|
|
|
|
$this->hookWritePath = $this->hookUpdatePath = $this->hookCreatePath = null;
|
2013-10-09 22:34:18 +04:00
|
|
|
|
|
|
|
|
|
$view->file_put_contents('/asd.txt', 'foo');
|
2014-04-28 12:49:35 +04:00
|
|
|
|
$this->assertEquals('/asd.txt', $this->hookCreatePath);
|
|
|
|
|
$this->assertNull($this->hookUpdatePath);
|
|
|
|
|
$this->assertEquals('/asd.txt', $this->hookWritePath);
|
|
|
|
|
|
|
|
|
|
$this->hookWritePath = $this->hookUpdatePath = $this->hookCreatePath = null;
|
2013-10-09 22:34:18 +04:00
|
|
|
|
|
|
|
|
|
$view->file_put_contents('/asd.txt', 'foo');
|
2014-04-28 12:49:35 +04:00
|
|
|
|
$this->assertNull($this->hookCreatePath);
|
|
|
|
|
$this->assertEquals('/asd.txt', $this->hookUpdatePath);
|
|
|
|
|
$this->assertEquals('/asd.txt', $this->hookWritePath);
|
|
|
|
|
|
|
|
|
|
\OC_Hook::clear('OC_Filesystem', 'post_create');
|
|
|
|
|
\OC_Hook::clear('OC_Filesystem', 'post_update');
|
|
|
|
|
\OC_Hook::clear('OC_Filesystem', 'post_write');
|
2013-10-09 22:34:18 +04:00
|
|
|
|
}
|
2013-10-10 18:06:26 +04:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider resolvePathTestProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testResolvePath($expected, $pathToTest) {
|
|
|
|
|
$storage1 = $this->getTestStorage();
|
|
|
|
|
\OC\Files\Filesystem::mount($storage1, array(), '/');
|
|
|
|
|
|
|
|
|
|
$view = new \OC\Files\View('');
|
|
|
|
|
|
|
|
|
|
$result = $view->resolvePath($pathToTest);
|
|
|
|
|
$this->assertEquals($expected, $result[1]);
|
|
|
|
|
|
|
|
|
|
$exists = $view->file_exists($pathToTest);
|
|
|
|
|
$this->assertTrue($exists);
|
|
|
|
|
|
|
|
|
|
$exists = $view->file_exists($result[1]);
|
|
|
|
|
$this->assertTrue($exists);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function resolvePathTestProvider() {
|
|
|
|
|
return array(
|
|
|
|
|
array('foo.txt', 'foo.txt'),
|
|
|
|
|
array('foo.txt', '/foo.txt'),
|
|
|
|
|
array('folder', 'folder'),
|
|
|
|
|
array('folder', '/folder'),
|
|
|
|
|
array('folder', 'folder/'),
|
|
|
|
|
array('folder', '/folder/'),
|
|
|
|
|
array('folder/bar.txt', 'folder/bar.txt'),
|
|
|
|
|
array('folder/bar.txt', '/folder/bar.txt'),
|
|
|
|
|
array('', ''),
|
|
|
|
|
array('', '/'),
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-12-12 16:43:55 +04:00
|
|
|
|
|
|
|
|
|
public function testUTF8Names() {
|
|
|
|
|
$names = array('虚', '和知しゃ和で', 'regular ascii', 'sɨˈrɪlɪk', 'ѨѬ', 'أنا أحب القراءة كثيرا');
|
|
|
|
|
|
|
|
|
|
$storage = new \OC\Files\Storage\Temporary(array());
|
|
|
|
|
\OC\Files\Filesystem::mount($storage, array(), '/');
|
|
|
|
|
|
|
|
|
|
$rootView = new \OC\Files\View('');
|
|
|
|
|
foreach ($names as $name) {
|
|
|
|
|
$rootView->file_put_contents('/' . $name, 'dummy content');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$list = $rootView->getDirectoryContent('/');
|
|
|
|
|
|
|
|
|
|
$this->assertCount(count($names), $list);
|
|
|
|
|
foreach ($list as $item) {
|
|
|
|
|
$this->assertContains($item['name'], $names);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$cache = $storage->getCache();
|
|
|
|
|
$scanner = $storage->getScanner();
|
|
|
|
|
$scanner->scan('');
|
|
|
|
|
|
|
|
|
|
$list = $cache->getFolderContents('');
|
|
|
|
|
|
|
|
|
|
$this->assertCount(count($names), $list);
|
|
|
|
|
foreach ($list as $item) {
|
|
|
|
|
$this->assertContains($item['name'], $names);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-14 18:11:41 +04:00
|
|
|
|
|
2014-05-08 17:19:54 +04:00
|
|
|
|
public function testLongPath() {
|
|
|
|
|
|
|
|
|
|
$storage = new \OC\Files\Storage\Temporary(array());
|
|
|
|
|
\OC\Files\Filesystem::mount($storage, array(), '/');
|
|
|
|
|
|
|
|
|
|
$rootView = new \OC\Files\View('');
|
|
|
|
|
|
|
|
|
|
$longPath = '';
|
2014-09-23 19:17:31 +04:00
|
|
|
|
$ds = DIRECTORY_SEPARATOR;
|
|
|
|
|
/*
|
|
|
|
|
* 4096 is the maximum path length in file_cache.path in *nix
|
|
|
|
|
* 1024 is the max path length in mac
|
|
|
|
|
* 228 is the max path length in windows
|
|
|
|
|
*/
|
2014-05-08 17:19:54 +04:00
|
|
|
|
$folderName = 'abcdefghijklmnopqrstuvwxyz012345678901234567890123456789';
|
2014-09-23 19:17:31 +04:00
|
|
|
|
$tmpdirLength = strlen(\OC_Helper::tmpFolder());
|
|
|
|
|
if (\OC_Util::runningOnWindows()) {
|
2014-11-10 13:01:43 +03:00
|
|
|
|
$this->markTestSkipped('[Windows] ');
|
2014-09-23 19:17:31 +04:00
|
|
|
|
$depth = ((260 - $tmpdirLength) / 57);
|
|
|
|
|
}elseif(\OC_Util::runningOnMac()){
|
|
|
|
|
$depth = ((1024 - $tmpdirLength) / 57);
|
|
|
|
|
} else {
|
|
|
|
|
$depth = ((4000 - $tmpdirLength) / 57);
|
|
|
|
|
}
|
2014-06-03 13:34:48 +04:00
|
|
|
|
foreach (range(0, $depth - 1) as $i) {
|
2014-09-23 19:17:31 +04:00
|
|
|
|
$longPath .= $ds . $folderName;
|
2014-05-08 17:19:54 +04:00
|
|
|
|
$result = $rootView->mkdir($longPath);
|
|
|
|
|
$this->assertTrue($result, "mkdir failed on $i - path length: " . strlen($longPath));
|
|
|
|
|
|
2014-09-23 19:17:31 +04:00
|
|
|
|
$result = $rootView->file_put_contents($longPath . "{$ds}test.txt", 'lorem');
|
2014-05-08 17:19:54 +04:00
|
|
|
|
$this->assertEquals(5, $result, "file_put_contents failed on $i");
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($rootView->file_exists($longPath));
|
2014-09-23 19:17:31 +04:00
|
|
|
|
$this->assertTrue($rootView->file_exists($longPath . "{$ds}test.txt"));
|
2014-05-08 17:19:54 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$cache = $storage->getCache();
|
|
|
|
|
$scanner = $storage->getScanner();
|
|
|
|
|
$scanner->scan('');
|
|
|
|
|
|
|
|
|
|
$longPath = $folderName;
|
2014-06-03 13:34:48 +04:00
|
|
|
|
foreach (range(0, $depth - 1) as $i) {
|
2014-05-08 17:19:54 +04:00
|
|
|
|
$cachedFolder = $cache->get($longPath);
|
|
|
|
|
$this->assertTrue(is_array($cachedFolder), "No cache entry for folder at $i");
|
|
|
|
|
$this->assertEquals($folderName, $cachedFolder['name'], "Wrong cache entry for folder at $i");
|
|
|
|
|
|
|
|
|
|
$cachedFile = $cache->get($longPath . '/test.txt');
|
|
|
|
|
$this->assertTrue(is_array($cachedFile), "No cache entry for file at $i");
|
|
|
|
|
$this->assertEquals('test.txt', $cachedFile['name'], "Wrong cache entry for file at $i");
|
|
|
|
|
|
2014-09-23 19:17:31 +04:00
|
|
|
|
$longPath .= $ds . $folderName;
|
2014-05-08 17:19:54 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-14 18:11:41 +04:00
|
|
|
|
public function testTouchNotSupported() {
|
|
|
|
|
$storage = new TemporaryNoTouch(array());
|
|
|
|
|
$scanner = $storage->getScanner();
|
|
|
|
|
\OC\Files\Filesystem::mount($storage, array(), '/test/');
|
|
|
|
|
$past = time() - 100;
|
|
|
|
|
$storage->file_put_contents('test', 'foobar');
|
|
|
|
|
$scanner->scan('');
|
|
|
|
|
$view = new \OC\Files\View('');
|
|
|
|
|
$info = $view->getFileInfo('/test/test');
|
|
|
|
|
|
|
|
|
|
$view->touch('/test/test', $past);
|
|
|
|
|
$scanner->scanFile('test', \OC\Files\Cache\Scanner::REUSE_ETAG);
|
|
|
|
|
|
|
|
|
|
$info2 = $view->getFileInfo('/test/test');
|
2014-02-27 12:39:34 +04:00
|
|
|
|
$this->assertSame($info['etag'], $info2['etag']);
|
2014-01-14 18:11:41 +04:00
|
|
|
|
}
|
2014-05-13 16:17:51 +04:00
|
|
|
|
|
2014-10-14 19:15:46 +04:00
|
|
|
|
public function testWatcherEtagCrossStorage() {
|
|
|
|
|
$storage1 = new Temporary(array());
|
|
|
|
|
$storage2 = new Temporary(array());
|
|
|
|
|
$scanner1 = $storage1->getScanner();
|
|
|
|
|
$scanner2 = $storage2->getScanner();
|
|
|
|
|
$storage1->mkdir('sub');
|
|
|
|
|
\OC\Files\Filesystem::mount($storage1, array(), '/test/');
|
|
|
|
|
\OC\Files\Filesystem::mount($storage2, array(), '/test/sub/storage');
|
|
|
|
|
|
|
|
|
|
$past = time() - 100;
|
|
|
|
|
$storage2->file_put_contents('test.txt', 'foobar');
|
|
|
|
|
$scanner1->scan('');
|
|
|
|
|
$scanner2->scan('');
|
|
|
|
|
$view = new \OC\Files\View('');
|
|
|
|
|
|
|
|
|
|
$storage2->getWatcher('')->setPolicy(Watcher::CHECK_ALWAYS);
|
|
|
|
|
|
|
|
|
|
$oldFileInfo = $view->getFileInfo('/test/sub/storage/test.txt');
|
|
|
|
|
$oldFolderInfo = $view->getFileInfo('/test');
|
|
|
|
|
|
|
|
|
|
$storage2->getCache()->update($oldFileInfo->getId(), array(
|
|
|
|
|
'storage_mtime' => $past
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
$view->getFileInfo('/test/sub/storage/test.txt');
|
|
|
|
|
$newFolderInfo = $view->getFileInfo('/test');
|
|
|
|
|
|
|
|
|
|
$this->assertNotEquals($newFolderInfo->getEtag(), $oldFolderInfo->getEtag());
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-13 16:17:51 +04:00
|
|
|
|
/**
|
|
|
|
|
* @dataProvider absolutePathProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testGetAbsolutePath($expectedPath, $relativePath) {
|
|
|
|
|
$view = new \OC\Files\View('/files');
|
|
|
|
|
$this->assertEquals($expectedPath, $view->getAbsolutePath($relativePath));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function absolutePathProvider() {
|
|
|
|
|
return array(
|
|
|
|
|
array('/files/', ''),
|
|
|
|
|
array('/files/0', '0'),
|
2014-05-14 00:01:11 +04:00
|
|
|
|
array('/files/false', 'false'),
|
|
|
|
|
array('/files/true', 'true'),
|
2014-05-13 16:17:51 +04:00
|
|
|
|
array('/files/', '/'),
|
|
|
|
|
array('/files/test', 'test'),
|
|
|
|
|
array('/files/test', '/test'),
|
|
|
|
|
);
|
|
|
|
|
}
|
2014-05-08 17:19:54 +04:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider tooLongPathDataProvider
|
|
|
|
|
* @expectedException \OCP\Files\InvalidPathException
|
|
|
|
|
*/
|
2014-06-03 13:34:48 +04:00
|
|
|
|
public function testTooLongPath($operation, $param0 = null) {
|
2014-05-08 17:19:54 +04:00
|
|
|
|
|
|
|
|
|
$longPath = '';
|
|
|
|
|
// 4000 is the maximum path length in file_cache.path
|
|
|
|
|
$folderName = 'abcdefghijklmnopqrstuvwxyz012345678901234567890123456789';
|
2014-06-03 13:34:48 +04:00
|
|
|
|
$depth = (4000 / 57);
|
|
|
|
|
foreach (range(0, $depth + 1) as $i) {
|
|
|
|
|
$longPath .= '/' . $folderName;
|
2014-05-08 17:19:54 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$storage = new \OC\Files\Storage\Temporary(array());
|
2014-06-06 12:41:49 +04:00
|
|
|
|
$this->tempStorage = $storage; // for later hard cleanup
|
2014-05-08 17:19:54 +04:00
|
|
|
|
\OC\Files\Filesystem::mount($storage, array(), '/');
|
|
|
|
|
|
|
|
|
|
$rootView = new \OC\Files\View('');
|
|
|
|
|
|
|
|
|
|
if ($param0 === '@0') {
|
|
|
|
|
$param0 = $longPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($operation === 'hash') {
|
|
|
|
|
$param0 = $longPath;
|
|
|
|
|
$longPath = 'md5';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
call_user_func(array($rootView, $operation), $longPath, $param0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function tooLongPathDataProvider() {
|
|
|
|
|
return array(
|
|
|
|
|
array('getAbsolutePath'),
|
|
|
|
|
array('getRelativePath'),
|
|
|
|
|
array('getMountPoint'),
|
|
|
|
|
array('resolvePath'),
|
|
|
|
|
array('getLocalFile'),
|
|
|
|
|
array('getLocalFolder'),
|
|
|
|
|
array('mkdir'),
|
|
|
|
|
array('rmdir'),
|
|
|
|
|
array('opendir'),
|
|
|
|
|
array('is_dir'),
|
|
|
|
|
array('is_file'),
|
|
|
|
|
array('stat'),
|
|
|
|
|
array('filetype'),
|
|
|
|
|
array('filesize'),
|
|
|
|
|
array('readfile'),
|
|
|
|
|
array('isCreatable'),
|
|
|
|
|
array('isReadable'),
|
|
|
|
|
array('isUpdatable'),
|
|
|
|
|
array('isDeletable'),
|
|
|
|
|
array('isSharable'),
|
|
|
|
|
array('file_exists'),
|
|
|
|
|
array('filemtime'),
|
|
|
|
|
array('touch'),
|
|
|
|
|
array('file_get_contents'),
|
|
|
|
|
array('unlink'),
|
|
|
|
|
array('deleteAll'),
|
|
|
|
|
array('toTmpFile'),
|
|
|
|
|
array('getMimeType'),
|
|
|
|
|
array('free_space'),
|
|
|
|
|
array('getFileInfo'),
|
|
|
|
|
array('getDirectoryContent'),
|
|
|
|
|
array('getOwner'),
|
|
|
|
|
array('getETag'),
|
|
|
|
|
array('file_put_contents', 'ipsum'),
|
|
|
|
|
array('rename', '@0'),
|
|
|
|
|
array('copy', '@0'),
|
|
|
|
|
array('fopen', 'r'),
|
|
|
|
|
array('fromTmpFile', '@0'),
|
|
|
|
|
array('hash'),
|
|
|
|
|
array('hasUpdated', 0),
|
|
|
|
|
array('putFileInfo', array()),
|
|
|
|
|
);
|
|
|
|
|
}
|
2012-10-21 04:12:58 +04:00
|
|
|
|
}
|