summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMichael Gapczynski <mtgap@owncloud.com>2013-05-23 17:35:11 -0700
committerMichael Gapczynski <mtgap@owncloud.com>2013-05-23 17:35:11 -0700
commita98d6c4be6fc9a8a456141033f166e26807cf907 (patch)
tree5410f16030df78b964dd69cc21cec85446749f84 /lib
parentb47729c5fc6586f6fc5f51cbca967b1ced76b24e (diff)
parent30330b4343b5bca82b95d9df4a13651c8e91063d (diff)
downloadnextcloud-server-a98d6c4be6fc9a8a456141033f166e26807cf907.tar.gz
nextcloud-server-a98d6c4be6fc9a8a456141033f166e26807cf907.zip
Merge pull request #3425 from owncloud/move-storages
Support for moving/copying folders between storages
Diffstat (limited to 'lib')
-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
4 files changed, 45 insertions, 33 deletions
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(