summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files/templates/part.breadcrumb.php2
-rw-r--r--lib/files/cache/scanner.php14
-rw-r--r--lib/files/filesystem.php13
-rw-r--r--lib/files/storage/common.php18
-rw-r--r--lib/files/view.php33
-rw-r--r--tests/lib/files/view.php37
6 files changed, 83 insertions, 34 deletions
diff --git a/apps/files/templates/part.breadcrumb.php b/apps/files/templates/part.breadcrumb.php
index 7ea1755d1d7..9886b42e424 100644
--- a/apps/files/templates/part.breadcrumb.php
+++ b/apps/files/templates/part.breadcrumb.php
@@ -1,5 +1,5 @@
<?php if(count($_["breadcrumb"])):?>
- <div class="crumb">
+ <div class="crumb" data-dir=''>
<a href="<?php print_unescaped($_['baseURL']); ?>">
<img src="<?php print_unescaped(OCP\image_path('core', 'places/home.svg'));?>" class="svg" />
</a>
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index a98953b42aa..46122221dc2 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -116,7 +116,7 @@ class Scanner {
\OC_DB::beginTransaction();
while ($file = readdir($dh)) {
$child = ($path) ? $path . '/' . $file : $file;
- if (!$this->isIgnoredDir($file)) {
+ if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
$data = $this->scanFile($child, $recursive === self::SCAN_SHALLOW);
if ($data) {
if ($data['size'] === -1) {
@@ -151,18 +151,6 @@ class Scanner {
}
/**
- * @brief check if the directory should be ignored when scanning
- * NOTE: the special directories . and .. would cause never ending recursion
- * @param String $dir
- * @return boolean
- */
- private function isIgnoredDir($dir) {
- if ($dir === '.' || $dir === '..') {
- return true;
- }
- return false;
- }
- /**
* @brief check if the file should be ignored when scanning
* NOTE: files with a '.part' extension are ignored as well!
* prevents unfinished put requests to be scanned
diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php
index d60d430d77c..99d87011df2 100644
--- a/lib/files/filesystem.php
+++ b/lib/files/filesystem.php
@@ -454,6 +454,19 @@ class Filesystem {
}
/**
+ * @brief check if the directory should be ignored when scanning
+ * NOTE: the special directories . and .. would cause never ending recursion
+ * @param String $dir
+ * @return boolean
+ */
+ static public function isIgnoredDir($dir) {
+ if ($dir === '.' || $dir === '..') {
+ return true;
+ }
+ return false;
+ }
+
+ /**
* following functions are equivalent to their php builtin equivalents for arguments/return values.
*/
static public function mkdir($path) {
diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php
index e87fe3b5239..3da13ac4df0 100644
--- a/lib/files/storage/common.php
+++ b/lib/files/storage/common.php
@@ -138,27 +138,21 @@ abstract class Common implements \OC\Files\Storage\Storage {
*/
public function deleteAll($directory, $empty = false) {
$directory = trim($directory, '/');
-
- if (!$this->file_exists(\OCP\USER::getUser() . '/' . $directory)
- || !$this->is_dir(\OCP\USER::getUser() . '/' . $directory)
- ) {
- return false;
- } elseif (!$this->isReadable(\OCP\USER::getUser() . '/' . $directory)) {
+ if (!$this->is_dir($directory) || !$this->isReadable($directory)) {
return false;
} else {
- $directoryHandle = $this->opendir(\OCP\USER::getUser() . '/' . $directory);
+ $directoryHandle = $this->opendir($directory);
while ($contents = readdir($directoryHandle)) {
- if ($contents != '.' && $contents != '..') {
- $path = $directory . "/" . $contents;
+ if (!\OC\Files\Filesystem::isIgnoredDir($contents)) {
+ $path = $directory . '/' . $contents;
if ($this->is_dir($path)) {
$this->deleteAll($path);
} else {
- $this->unlink(\OCP\USER::getUser() . '/' . $path); // TODO: make unlink use same system path as is_dir
+ $this->unlink($path);
}
}
}
- //$this->closedir( $directoryHandle ); // TODO: implement closedir in OC_FSV
- if ($empty == false) {
+ if ($empty === false) {
if (!$this->rmdir($directory)) {
return false;
}
diff --git a/lib/files/view.php b/lib/files/view.php
index bc6b80c505a..168d781d62c 100644
--- a/lib/files/view.php
+++ b/lib/files/view.php
@@ -375,11 +375,19 @@ class View {
$result = false;
}
} else {
- $source = $this->fopen($path1 . $postFix1, 'r');
- $target = $this->fopen($path2 . $postFix2, 'w');
- list($count, $result) = \OC_Helper::streamCopy($source, $target);
- list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1);
- $storage1->unlink($internalPath1);
+ if ($this->is_dir($path1)) {
+ $result = $this->copy($path1, $path2);
+ if ($result === true) {
+ list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1);
+ $result = $storage1->deleteAll($internalPath1);
+ }
+ } else {
+ $source = $this->fopen($path1 . $postFix1, 'r');
+ $target = $this->fopen($path2 . $postFix2, 'w');
+ list($count, $result) = \OC_Helper::streamCopy($source, $target);
+ list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1);
+ $storage1->unlink($internalPath1);
+ }
}
if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isPartialFile($path1)) {
\OC_Hook::emit(
@@ -462,9 +470,18 @@ class View {
$result = false;
}
} else {
- $source = $this->fopen($path1 . $postFix1, 'r');
- $target = $this->fopen($path2 . $postFix2, 'w');
- list($count, $result) = \OC_Helper::streamCopy($source, $target);
+ if ($this->is_dir($path1) && ($dh = $this->opendir($path1))) {
+ $result = $this->mkdir($path2);
+ while ($file = readdir($dh)) {
+ if (!Filesystem::isIgnoredDir($file)) {
+ $result = $this->copy($path1 . '/' . $file, $path2 . '/' . $file);
+ }
+ }
+ } else {
+ $source = $this->fopen($path1 . $postFix1, 'r');
+ $target = $this->fopen($path2 . $postFix2, 'w');
+ list($count, $result) = \OC_Helper::streamCopy($source, $target);
+ }
}
if ($this->fakeRoot == Filesystem::getRoot()) {
\OC_Hook::emit(
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index af97761bbb7..01f9a9cca11 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -234,6 +234,43 @@ 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->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'));
+ $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'));
+ }
+
function testTouch() {
$storage = $this->getTestStorage(true, '\Test\Files\TemporaryNoTouch');