aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external')
-rw-r--r--apps/files_external/3rdparty/smb4php/smb.php16
-rwxr-xr-xapps/files_external/lib/dropbox.php56
-rw-r--r--apps/files_external/lib/sftp.php3
-rw-r--r--apps/files_external/lib/streamwrapper.php3
-rw-r--r--apps/files_external/tests/dropbox.php16
-rw-r--r--apps/files_external/tests/smb.php5
6 files changed, 85 insertions, 14 deletions
diff --git a/apps/files_external/3rdparty/smb4php/smb.php b/apps/files_external/3rdparty/smb4php/smb.php
index 9650f809041..87638271f0e 100644
--- a/apps/files_external/3rdparty/smb4php/smb.php
+++ b/apps/files_external/3rdparty/smb4php/smb.php
@@ -302,6 +302,7 @@ class smb {
}
function rename ($url_from, $url_to) {
+ $replace = false;
list ($from, $to) = array (smb::parse_url($url_from), smb::parse_url($url_to));
if ($from['host'] <> $to['host'] ||
$from['share'] <> $to['share'] ||
@@ -314,7 +315,20 @@ class smb {
trigger_error('rename(): error in URL', E_USER_ERROR);
}
smb::clearstatcache ($url_from);
- $result = smb::execute ('rename "'.$from['path'].'" "'.$to['path'].'"', $to);
+ $cmd = '';
+ // check if target file exists
+ if (smb::url_stat($url_to)) {
+ // delete target file first
+ $cmd = 'del "' . $to['path'] . '"; ';
+ $replace = true;
+ }
+ $cmd .= 'rename "' . $from['path'] . '" "' . $to['path'] . '"';
+ $result = smb::execute($cmd, $to);
+ if ($replace) {
+ // clear again, else the cache will return the info
+ // from the old file
+ smb::clearstatcache ($url_to);
+ }
return $result !== false;
}
diff --git a/apps/files_external/lib/dropbox.php b/apps/files_external/lib/dropbox.php
index 5f603b7fe43..f7d8d98cf03 100755
--- a/apps/files_external/lib/dropbox.php
+++ b/apps/files_external/lib/dropbox.php
@@ -50,6 +50,22 @@ class Dropbox extends \OC\Files\Storage\Common {
}
}
+ private function deleteMetaData($path) {
+ $path = $this->root.$path;
+ if (isset($this->metaData[$path])) {
+ unset($this->metaData[$path]);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @brief Returns the path's metadata
+ * @param $path path for which to return the metadata
+ * @param $list if true, also return the directory's contents
+ * @return directory contents if $list is true, file metadata if $list is
+ * false, null if the file doesn't exist or "false" if the operation failed
+ */
private function getMetaData($path, $list = false) {
$path = $this->root.$path;
if ( ! $list && isset($this->metaData[$path])) {
@@ -62,24 +78,35 @@ class Dropbox extends \OC\Files\Storage\Common {
\OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
return false;
}
+ $contents = array();
if ($response && isset($response['contents'])) {
- $contents = $response['contents'];
// Cache folder's contents
- foreach ($contents as $file) {
- $this->metaData[$path.'/'.basename($file['path'])] = $file;
+ foreach ($response['contents'] as $file) {
+ if (!isset($file['is_deleted']) || !$file['is_deleted']) {
+ $this->metaData[$path.'/'.basename($file['path'])] = $file;
+ $contents[] = $file;
+ }
}
unset($response['contents']);
+ }
+ if (!isset($response['is_deleted']) || !$response['is_deleted']) {
$this->metaData[$path] = $response;
}
- $this->metaData[$path] = $response;
// Return contents of folder only
return $contents;
} else {
try {
$response = $this->dropbox->getMetaData($path, 'false');
- $this->metaData[$path] = $response;
- return $response;
+ if (!isset($response['is_deleted']) || !$response['is_deleted']) {
+ $this->metaData[$path] = $response;
+ return $response;
+ }
+ return null;
} catch (\Exception $exception) {
+ if ($exception instanceof \Dropbox_Exception_NotFound) {
+ // don't log, might be a file_exist check
+ return false;
+ }
\OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
return false;
}
@@ -108,7 +135,7 @@ class Dropbox extends \OC\Files\Storage\Common {
public function opendir($path) {
$contents = $this->getMetaData($path, true);
- if ($contents) {
+ if ($contents !== false) {
$files = array();
foreach ($contents as $file) {
$files[] = basename($file['path']);
@@ -157,9 +184,9 @@ class Dropbox extends \OC\Files\Storage\Common {
}
public function unlink($path) {
- $path = $this->root.$path;
try {
- $this->dropbox->delete($path);
+ $this->dropbox->delete($this->root.$path);
+ $this->deleteMetaData($path);
return true;
} catch (\Exception $exception) {
\OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
@@ -168,10 +195,14 @@ class Dropbox extends \OC\Files\Storage\Common {
}
public function rename($path1, $path2) {
- $path1 = $this->root.$path1;
- $path2 = $this->root.$path2;
try {
- $this->dropbox->move($path1, $path2);
+ // overwrite if target file exists and is not a directory
+ $destMetaData = $this->getMetaData($path2);
+ if (isset($destMetaData) && $destMetaData !== false && !$destMetaData['is_dir']) {
+ $this->unlink($path2);
+ }
+ $this->dropbox->move($this->root.$path1, $this->root.$path2);
+ $this->deleteMetaData($path1);
return true;
} catch (\Exception $exception) {
\OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
@@ -274,6 +305,7 @@ class Dropbox extends \OC\Files\Storage\Common {
} else {
$this->file_put_contents($path, '');
}
+ return true;
}
}
diff --git a/apps/files_external/lib/sftp.php b/apps/files_external/lib/sftp.php
index bcc4c5eafd5..95e0cefa398 100644
--- a/apps/files_external/lib/sftp.php
+++ b/apps/files_external/lib/sftp.php
@@ -285,6 +285,9 @@ class SFTP extends \OC\Files\Storage\Common {
public function rename($source, $target) {
try {
+ if (!$this->is_dir($target) && $this->file_exists($target)) {
+ $this->unlink($target);
+ }
return $this->client->rename(
$this->absPath($source),
$this->absPath($target)
diff --git a/apps/files_external/lib/streamwrapper.php b/apps/files_external/lib/streamwrapper.php
index 23c5f91a2f3..7a1991d4f04 100644
--- a/apps/files_external/lib/streamwrapper.php
+++ b/apps/files_external/lib/streamwrapper.php
@@ -38,7 +38,7 @@ abstract class StreamWrapper extends Common {
}
public function filetype($path) {
- return filetype($this->constructUrl($path));
+ return @filetype($this->constructUrl($path));
}
public function file_exists($path) {
@@ -68,6 +68,7 @@ abstract class StreamWrapper extends Common {
}
} else {
$this->file_put_contents($path, '');
+ return true;
}
}
diff --git a/apps/files_external/tests/dropbox.php b/apps/files_external/tests/dropbox.php
index e4e598b06b0..4b052282019 100644
--- a/apps/files_external/tests/dropbox.php
+++ b/apps/files_external/tests/dropbox.php
@@ -21,6 +21,22 @@ class Dropbox extends Storage {
$this->instance = new \OC\Files\Storage\Dropbox($this->config['dropbox']);
}
+ public function directoryProvider() {
+ // doesn't support leading/trailing spaces
+ return array(array('folder'));
+ }
+
+ public function testDropboxTouchReturnValue() {
+ $this->assertFalse($this->instance->file_exists('foo'));
+
+ // true because succeeded
+ $this->assertTrue($this->instance->touch('foo'));
+ $this->assertTrue($this->instance->file_exists('foo'));
+
+ // false because not supported
+ $this->assertFalse($this->instance->touch('foo'));
+ }
+
public function tearDown() {
if ($this->instance) {
$this->instance->unlink('/');
diff --git a/apps/files_external/tests/smb.php b/apps/files_external/tests/smb.php
index 0291f293fa6..199e35af676 100644
--- a/apps/files_external/tests/smb.php
+++ b/apps/files_external/tests/smb.php
@@ -29,6 +29,11 @@ class SMB extends Storage {
}
}
+ public function directoryProvider() {
+ // doesn't support leading/trailing spaces
+ return array(array('folder'));
+ }
+
public function testRenameWithSpaces() {
$this->instance->mkdir('with spaces');
$result = $this->instance->rename('with spaces', 'foo bar');