diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2013-07-30 09:48:30 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2013-07-30 09:48:30 +0200 |
commit | a7a7ef2b3a79607677679ea96212a20a633065e3 (patch) | |
tree | 20c40d23395fcd256e8eaa4b7df63d7b406f6c3f /apps | |
parent | b6fa0e4eefb332dc1fb9b45df50de4621ed8e6bd (diff) | |
download | nextcloud-server-a7a7ef2b3a79607677679ea96212a20a633065e3.tar.gz nextcloud-server-a7a7ef2b3a79607677679ea96212a20a633065e3.zip |
improved error handling
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_encryption/lib/util.php | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 03e2fae4c65..5649472e0b5 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -661,7 +661,7 @@ class Util { } } - + /** * @brief Decrypt all files * @return bool @@ -670,6 +670,8 @@ class Util { $found = $this->findEncFiles($this->userId . '/files'); + $successful = true; + if ($found) { // Disable proxy to prevent file being encrypted twice @@ -687,11 +689,28 @@ class Util { // Open enc file handle for binary reading $encHandle = fopen('crypt://' . $rawPath, 'rb'); + if ($encHandle === false) { + \OCP\Util::writeLog('Encryption library', 'couldn\'t open "' . $rawPath . '", decryption failed!', \OCP\Util::FATAL); + $successful = false; + continue; + } + // Open plain file handle for binary writing, with same filename as original plain file $plainHandle = $this->view->fopen($rawPath . '.part', 'wb'); + if ($plainHandle === false) { + \OCP\Util::writeLog('Encryption library', 'couldn\'t open "' . $rawPath . '.part", decryption failed!', \OCP\Util::FATAL); + $successful = false; + continue; + } // Move plain file to a temporary location $size = stream_copy_to_stream($encHandle, $plainHandle); + if ($size === 0) { + \OCP\Util::writeLog('Encryption library', 'Zero bytes copied of "' . $rawPath . '", decryption failed!', \OCP\Util::FATAL); + $successful = false; + continue; + } + fclose($encHandle); fclose($plainHandle); @@ -711,18 +730,15 @@ class Util { )); } - $this->view->deleteAll($this->keyfilesPath); - $this->view->deleteAll($this->shareKeysPath); + if ($successful) { + $this->view->deleteAll($this->keyfilesPath); + $this->view->deleteAll($this->shareKeysPath); + } \OC_FileProxy::$enabled = true; - - // If files were found, return true - return true; - } else { - - // If no files were found, return false - return false; } + + return $successful; } /** |