Skip to content
Snippets Groups Projects
Commit 9b605969 authored by Michael Gapczynski's avatar Michael Gapczynski
Browse files

Fixes in Dropbox API, try to catch Dropbox exceptions, implement rename and...

Fixes in Dropbox API, try to catch Dropbox exceptions, implement rename and copy in Dropbox storage backend
parent 77c66e8c
Branches
No related tags found
No related merge requests found
...@@ -139,7 +139,7 @@ class Dropbox_API { ...@@ -139,7 +139,7 @@ class Dropbox_API {
public function copy($from, $to, $root = null) { public function copy($from, $to, $root = null) {
if (is_null($root)) $root = $this->root; if (is_null($root)) $root = $this->root;
$response = $this->oauth->fetch($this->api_url . 'fileops/copy', array('from_path' => $from, 'to_path' => $to, 'root' => $root)); $response = $this->oauth->fetch($this->api_url . 'fileops/copy', array('from_path' => $from, 'to_path' => $to, 'root' => $root), 'POST');
return json_decode($response['body'],true); return json_decode($response['body'],true);
...@@ -178,7 +178,7 @@ class Dropbox_API { ...@@ -178,7 +178,7 @@ class Dropbox_API {
public function delete($path, $root = null) { public function delete($path, $root = null) {
if (is_null($root)) $root = $this->root; if (is_null($root)) $root = $this->root;
$response = $this->oauth->fetch($this->api_url . 'fileops/delete', array('path' => $path, 'root' => $root)); $response = $this->oauth->fetch($this->api_url . 'fileops/delete', array('path' => $path, 'root' => $root), 'POST');
return json_decode($response['body']); return json_decode($response['body']);
} }
...@@ -196,7 +196,7 @@ class Dropbox_API { ...@@ -196,7 +196,7 @@ class Dropbox_API {
public function move($from, $to, $root = null) { public function move($from, $to, $root = null) {
if (is_null($root)) $root = $this->root; if (is_null($root)) $root = $this->root;
$response = $this->oauth->fetch($this->api_url . 'fileops/move', array('from_path' => rawurldecode($from), 'to_path' => rawurldecode($to), 'root' => $root)); $response = $this->oauth->fetch($this->api_url . 'fileops/move', array('from_path' => rawurldecode($from), 'to_path' => rawurldecode($to), 'root' => $root), 'POST');
return json_decode($response['body'],true); return json_decode($response['body'],true);
......
...@@ -70,11 +70,16 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { ...@@ -70,11 +70,16 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
} }
public function mkdir($path) { public function mkdir($path) {
return $this->dropbox->createFolder($path); try {
$this->dropbox->createFolder($path);
return true;
} catch (Exception $exception) {
return false;
}
} }
public function rmdir($path) { public function rmdir($path) {
return $this->dropbox->delete($path); return $this->unlink($path);
} }
public function opendir($path) { public function opendir($path) {
...@@ -114,11 +119,11 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { ...@@ -114,11 +119,11 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
} }
public function is_readable($path) { public function is_readable($path) {
return self::file_exists($path); return $this->file_exists($path);
} }
public function is_writable($path) { public function is_writable($path) {
return self::file_exists($path); return $this->file_exists($path);
} }
public function file_exists($path) { public function file_exists($path) {
...@@ -132,7 +137,30 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { ...@@ -132,7 +137,30 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
} }
public function unlink($path) { public function unlink($path) {
return $this->dropbox->delete($path); try {
$this->dropbox->delete($path);
return true;
} catch (Exception $exception) {
return false;
}
}
public function rename($path1, $path2) {
try {
$this->dropbox->move($path1, $path2);
return true;
} catch (Exception $exception) {
return false;
}
}
public function copy($path1, $path2) {
try {
$this->dropbox->copy($path1, $path2);
return true;
} catch (Exception $exception) {
return false;
}
} }
public function fopen($path, $mode) { public function fopen($path, $mode) {
...@@ -140,8 +168,13 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { ...@@ -140,8 +168,13 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
case 'r': case 'r':
case 'rb': case 'rb':
$tmpFile = OC_Helper::tmpFile(); $tmpFile = OC_Helper::tmpFile();
file_put_contents($tmpFile, $this->dropbox->getFile($path)); try {
$data = $this->dropbox->getFile($path);
file_put_contents($tmpFile, $data);
return fopen($tmpFile, 'r'); return fopen($tmpFile, 'r');
} catch (Exception $exception) {
return false;
}
case 'w': case 'w':
case 'wb': case 'wb':
case 'a': case 'a':
...@@ -174,9 +207,11 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { ...@@ -174,9 +207,11 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
public function writeBack($tmpFile) { public function writeBack($tmpFile) {
if (isset(self::$tempFiles[$tmpFile])) { if (isset(self::$tempFiles[$tmpFile])) {
$handle = fopen($tmpFile, 'r'); $handle = fopen($tmpFile, 'r');
try {
$response = $this->dropbox->putFile(self::$tempFiles[$tmpFile], $handle); $response = $this->dropbox->putFile(self::$tempFiles[$tmpFile], $handle);
if ($response) {
unlink($tmpFile); unlink($tmpFile);
} catch (Exception $exception) {
} }
} }
} }
...@@ -191,11 +226,13 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { ...@@ -191,11 +226,13 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
} }
public function free_space($path) { public function free_space($path) {
if ($info = $this->dropbox->getAccountInfo()) { try {
$info = $this->dropbox->getAccountInfo();
return $info['quota_info']['quota'] - $info['quota_info']['normal']; return $info['quota_info']['quota'] - $info['quota_info']['normal'];
} } catch (Exception $exception) {
return false; return false;
} }
}
public function touch($path, $mtime = null) { public function touch($path, $mtime = null) {
return false; return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment