summaryrefslogtreecommitdiffstats
path: root/apps/files_external
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2016-03-16 13:15:54 +0100
committerRobin Appelman <icewind@owncloud.com>2016-03-16 13:15:54 +0100
commitd498282e12934ddcf7dc2649699f9be94cdc1a7c (patch)
treed7e8d40a1b106b8be33a78056c49ff5ea5a0c6d7 /apps/files_external
parent225eebd8f91c19666e453527ebfa457ee10a811a (diff)
downloadnextcloud-server-d498282e12934ddcf7dc2649699f9be94cdc1a7c.tar.gz
nextcloud-server-d498282e12934ddcf7dc2649699f9be94cdc1a7c.zip
handle connection errors as storage not available in smb
Diffstat (limited to 'apps/files_external')
-rw-r--r--apps/files_external/lib/smb.php54
1 files changed, 40 insertions, 14 deletions
diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php
index 67d1a23f5a7..25acae95fa3 100644
--- a/apps/files_external/lib/smb.php
+++ b/apps/files_external/lib/smb.php
@@ -30,6 +30,7 @@
namespace OC\Files\Storage;
+use Icewind\SMB\Exception\ConnectException;
use Icewind\SMB\Exception\Exception;
use Icewind\SMB\Exception\ForbiddenException;
use Icewind\SMB\Exception\NotFoundException;
@@ -39,6 +40,7 @@ use Icewind\Streams\CallbackWrapper;
use Icewind\Streams\IteratorDirectory;
use OC\Cache\CappedMemoryCache;
use OC\Files\Filesystem;
+use OCP\Files\StorageNotAvailableException;
class SMB extends Common {
/**
@@ -104,26 +106,36 @@ class SMB extends Common {
/**
* @param string $path
* @return \Icewind\SMB\IFileInfo
+ * @throws StorageNotAvailableException
*/
protected function getFileInfo($path) {
- $path = $this->buildPath($path);
- if (!isset($this->statCache[$path])) {
- $this->statCache[$path] = $this->share->stat($path);
+ try {
+ $path = $this->buildPath($path);
+ if (!isset($this->statCache[$path])) {
+ $this->statCache[$path] = $this->share->stat($path);
+ }
+ return $this->statCache[$path];
+ } catch (ConnectException $e) {
+ throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
}
- return $this->statCache[$path];
}
/**
* @param string $path
* @return \Icewind\SMB\IFileInfo[]
+ * @throws StorageNotAvailableException
*/
protected function getFolderContents($path) {
- $path = $this->buildPath($path);
- $files = $this->share->dir($path);
- foreach ($files as $file) {
- $this->statCache[$path . '/' . $file->getName()] = $file;
+ try {
+ $path = $this->buildPath($path);
+ $files = $this->share->dir($path);
+ foreach ($files as $file) {
+ $this->statCache[$path . '/' . $file->getName()] = $file;
+ }
+ return $files;
+ } catch (ConnectException $e) {
+ throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
}
- return $files;
}
/**
@@ -163,6 +175,8 @@ class SMB extends Common {
return false;
} catch (ForbiddenException $e) {
return false;
+ } catch (ConnectException $e) {
+ throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -245,6 +259,8 @@ class SMB extends Common {
return false;
} catch (ForbiddenException $e) {
return false;
+ } catch (ConnectException $e) {
+ throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -265,16 +281,22 @@ class SMB extends Common {
return false;
} catch (ForbiddenException $e) {
return false;
+ } catch (ConnectException $e) {
+ throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
}
}
public function touch($path, $time = null) {
- if (!$this->file_exists($path)) {
- $fh = $this->share->write($this->buildPath($path));
- fclose($fh);
- return true;
+ try {
+ if (!$this->file_exists($path)) {
+ $fh = $this->share->write($this->buildPath($path));
+ fclose($fh);
+ return true;
+ }
+ return false;
+ } catch (ConnectException $e) {
+ throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
}
- return false;
}
public function opendir($path) {
@@ -307,6 +329,8 @@ class SMB extends Common {
try {
$this->share->mkdir($path);
return true;
+ } catch (ConnectException $e) {
+ throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
} catch (Exception $e) {
return false;
}
@@ -320,6 +344,8 @@ class SMB extends Common {
return false;
} catch (ForbiddenException $e) {
return false;
+ } catch (ConnectException $e) {
+ throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
}
}