improved error handling

This commit is contained in:
Bjoern Schiessle 2013-07-30 09:48:30 +02:00
parent b6fa0e4eef
commit a7a7ef2b3a
2 changed files with 34 additions and 14 deletions

View File

@ -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 {
));
}
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;
}
/**

View File

@ -1,5 +1,5 @@
<?php
sleep(10);
//encryption app needs to be loaded
OC_App::loadApp('files_encryption');
@ -13,9 +13,13 @@ $util = new \OCA\Encryption\Util($view, \OCP\User::getUser());
$result = $util->initEncryption($params);
if ($result !== false) {
$util->decryptAll();
$successful = $util->decryptAll();
if ($successful === true) {
\OCP\JSON::success(array('data' => array('message' => 'Files decrypted successfully')));
} else {
\OCP\JSON::error(array('data' => array('message' => 'Couldn\'t decrypt files, check your password and try again')));
\OCP\JSON::error(array('data' => array('message' => 'Couldn\'t decrypt your files, please check your owncloud.log or ask your administrator')));
}
} else {
\OCP\JSON::error(array('data' => array('message' => 'Couldn\'t decrypt your files, check your password and try again')));
}