summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-05-23 12:46:12 +0200
committerRobin Appelman <icewind@owncloud.com>2014-05-28 18:16:24 +0200
commit467e9c2bb0dadb58e6cdb03830318b725123c7aa (patch)
treed07ad47ef8629684e66117966c59d10724de825e
parentaf35b6ad9db6490f5bfd25143d214f5b1d8dfd34 (diff)
downloadnextcloud-server-467e9c2bb0dadb58e6cdb03830318b725123c7aa.tar.gz
nextcloud-server-467e9c2bb0dadb58e6cdb03830318b725123c7aa.zip
Remove code duplication
-rw-r--r--lib/private/files/storage/common.php41
1 files changed, 21 insertions, 20 deletions
diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php
index 8ebc0bcddb5..1ed0d79817b 100644
--- a/lib/private/files/storage/common.php
+++ b/lib/private/files/storage/common.php
@@ -7,6 +7,7 @@
*/
namespace OC\Files\Storage;
+use OC\Files\Filesystem;
use OC\Files\Cache\Watcher;
/**
@@ -36,6 +37,22 @@ abstract class Common implements \OC\Files\Storage\Storage {
public function __construct($parameters) {
}
+ /**
+ * Remove a file of folder
+ *
+ * @param string $path
+ * @return bool
+ */
+ protected function remove($path) {
+ if ($this->is_dir($path)) {
+ return $this->rmdir($path);
+ } else if($this->is_file($path)) {
+ return $this->unlink($path);
+ } else {
+ return false;
+ }
+ }
+
public function is_dir($path) {
return $this->filetype($path) == 'dir';
}
@@ -137,35 +154,19 @@ abstract class Common implements \OC\Files\Storage\Storage {
}
public function rename($path1, $path2) {
- if ($this->file_exists($path2)) {
- if ($this->is_dir($path2)) {
- $this->rmdir($path2);
- } else {
- $this->unlink($path2);
- }
- }
+ $this->remove($path2);
$this->removeCachedFile($path1);
- if ($this->is_dir($path1)) {
- return $this->copy($path1, $path2) and $this->rmdir($path1);
- } else {
- return $this->copy($path1, $path2) and $this->unlink($path1);
- }
+ return $this->copy($path1, $path2) and $this->remove($path1);
}
public function copy($path1, $path2) {
if ($this->is_dir($path1)) {
- if ($this->file_exists($path2)) {
- if ($this->is_dir($path2)) {
- $this->rmdir($path2);
- } else {
- $this->unlink($path2);
- }
- }
+ $this->remove($path2);
$dir = $this->opendir($path1);
$this->mkdir($path2);
while ($file = readdir($dir)) {
- if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
+ if (!Filesystem::isIgnoredDir($file)) {
if (!$this->copy($path1 . '/' . $file, $path2 . '/' . $file)) {
return false;
}