From 3e70d563a6774567ec77e9d9adf6b9ccb1e9619d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 10 Feb 2013 12:27:35 +0100 Subject: Cache: bookkeeping of storage_mtime --- tests/lib/files/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/lib/files/view.php') diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index a064e44f3ef..c9a8a0fb081 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -220,7 +220,7 @@ class View extends \PHPUnit_Framework_TestCase { $cachedData = $rootView->getFileInfo('foo.txt'); $this->assertEquals(16, $cachedData['size']); - $rootView->putFileInfo('foo.txt', array('mtime' => 10)); + $rootView->putFileInfo('foo.txt', array('storage_mtime' => 10)); $storage1->file_put_contents('foo.txt', 'foo'); clearstatcache(); -- cgit v1.2.3 From 9738fae3cf1ad18593d21eb62e138e00c01f5f36 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 10 Feb 2013 12:44:27 +0100 Subject: Emulate touch() for backends that don't support it --- lib/files/view.php | 16 ++++++++++------ tests/lib/files/view.php | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 8 deletions(-) (limited to 'tests/lib/files/view.php') diff --git a/lib/files/view.php b/lib/files/view.php index 1a234228eab..69e2f1ad349 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -242,7 +242,11 @@ class View { if (!is_null($mtime) and !is_numeric($mtime)) { $mtime = strtotime($mtime); } - return $this->basicOperation('touch', $path, array('write'), $mtime); + $result = $this->basicOperation('touch', $path, array('write'), $mtime); + if (!$result) { //if native touch fails, we emulate it by changing the mtime in the cache + $this->putFileInfo($path, array('mtime' => $mtime)); + } + return true; } public function file_get_contents($path) { @@ -917,11 +921,11 @@ class View { } /** - * Get the owner for a file or folder - * - * @param string $path - * @return string - */ + * Get the owner for a file or folder + * + * @param string $path + * @return string + */ public function getOwner($path) { return $this->basicOperation('getOwner', $path); } diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index c9a8a0fb081..af97761bbb7 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -7,6 +7,12 @@ namespace Test\Files; +class TemporaryNoTouch extends \OC\Files\Storage\Temporary { + public function touch($path, $mtime = null) { + return false; + } +} + class View extends \PHPUnit_Framework_TestCase { /** * @var \OC\Files\Storage\Storage[] $storages; @@ -228,12 +234,36 @@ class View extends \PHPUnit_Framework_TestCase { $this->assertEquals(3, $cachedData['size']); } + 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'); + $this->assertGreaterThanOrEqual($cachedData['mtime'], $oldCachedData['mtime']); + $this->assertEquals($cachedData['storage_mtime'], $cachedData['mtime']); + } + /** * @param bool $scan * @return \OC\Files\Storage\Storage */ - private function getTestStorage($scan = true) { - $storage = new \OC\Files\Storage\Temporary(array()); + private function getTestStorage($scan = true, $class = '\OC\Files\Storage\Temporary') { + /** + * @var \OC\Files\Storage\Storage $storage + */ + $storage = new $class(array()); $textData = "dummy file data\n"; $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png'); $storage->mkdir('folder'); -- cgit v1.2.3 From e9b71eed691050e23d78910abdd8bf313f2f83cb Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 19 May 2013 14:20:46 -0400 Subject: Add tests for copying/moving between storages --- tests/lib/files/view.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests/lib/files/view.php') diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index a064e44f3ef..554bc7291ad 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -228,6 +228,40 @@ class View extends \PHPUnit_Framework_TestCase { $this->assertEquals(3, $cachedData['size']); } + 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(''); + $rootView->copy('substorage', 'anotherfolder'); + $this->assertTrue($rootView->is_dir('/anotherfolder')); + $this->assertTrue($rootView->is_dir('/substorage')); + $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')); + } + + 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')); + } + /** * @param bool $scan * @return \OC\Files\Storage\Storage -- cgit v1.2.3 From fc5bce1f76a3a67a4ac9095d15441e363dfd03d1 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 19 May 2013 15:04:41 -0400 Subject: Fix undefined variable for copying empty folders --- lib/files/view.php | 2 +- tests/lib/files/view.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'tests/lib/files/view.php') diff --git a/lib/files/view.php b/lib/files/view.php index 875a6c1a1f8..8a37a0bcc62 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -467,7 +467,7 @@ class View { } } else { if ($this->is_dir($path1) && ($dh = $this->opendir($path1))) { - $this->mkdir($path2); + $result = $this->mkdir($path2); while ($file = readdir($dh)) { if (!Filesystem::isIgnoredDir($file)) { $result = $this->copy($path1 . '/' . $file, $path2 . '/' . $file); diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index 554bc7291ad..a51d99e793d 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -235,9 +235,12 @@ class View extends \PHPUnit_Framework_TestCase { \OC\Files\Filesystem::mount($storage2, array(), '/substorage'); $rootView = new \OC\Files\View(''); + $rootView->mkdir('substorage/emptyfolder'); $rootView->copy('substorage', 'anotherfolder'); $this->assertTrue($rootView->is_dir('/anotherfolder')); $this->assertTrue($rootView->is_dir('/substorage')); + $this->assertTrue($rootView->is_dir('/anotherfolder/emptyfolder')); + $this->assertTrue($rootView->is_dir('/substorage/emptyfolder')); $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')); -- cgit v1.2.3