From d498282e12934ddcf7dc2649699f9be94cdc1a7c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 16 Mar 2016 13:15:54 +0100 Subject: [PATCH] handle connection errors as storage not available in smb --- apps/files_external/lib/smb.php | 54 ++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php index 67d1a23f5a..25acae95fa 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); } }