improved error handling
This commit is contained in:
parent
b6fa0e4eef
commit
a7a7ef2b3a
|
@ -661,7 +661,7 @@ class Util {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Decrypt all files
|
* @brief Decrypt all files
|
||||||
* @return bool
|
* @return bool
|
||||||
|
@ -670,6 +670,8 @@ class Util {
|
||||||
|
|
||||||
$found = $this->findEncFiles($this->userId . '/files');
|
$found = $this->findEncFiles($this->userId . '/files');
|
||||||
|
|
||||||
|
$successful = true;
|
||||||
|
|
||||||
if ($found) {
|
if ($found) {
|
||||||
|
|
||||||
// Disable proxy to prevent file being encrypted twice
|
// Disable proxy to prevent file being encrypted twice
|
||||||
|
@ -687,11 +689,28 @@ class Util {
|
||||||
// Open enc file handle for binary reading
|
// Open enc file handle for binary reading
|
||||||
$encHandle = fopen('crypt://' . $rawPath, 'rb');
|
$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
|
// Open plain file handle for binary writing, with same filename as original plain file
|
||||||
$plainHandle = $this->view->fopen($rawPath . '.part', 'wb');
|
$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
|
// Move plain file to a temporary location
|
||||||
$size = stream_copy_to_stream($encHandle, $plainHandle);
|
$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($encHandle);
|
||||||
fclose($plainHandle);
|
fclose($plainHandle);
|
||||||
|
@ -711,18 +730,15 @@ class Util {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->view->deleteAll($this->keyfilesPath);
|
if ($successful) {
|
||||||
$this->view->deleteAll($this->shareKeysPath);
|
$this->view->deleteAll($this->keyfilesPath);
|
||||||
|
$this->view->deleteAll($this->shareKeysPath);
|
||||||
|
}
|
||||||
|
|
||||||
\OC_FileProxy::$enabled = true;
|
\OC_FileProxy::$enabled = true;
|
||||||
|
|
||||||
// If files were found, return true
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// If no files were found, return false
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $successful;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
sleep(10);
|
|
||||||
//encryption app needs to be loaded
|
//encryption app needs to be loaded
|
||||||
OC_App::loadApp('files_encryption');
|
OC_App::loadApp('files_encryption');
|
||||||
|
|
||||||
|
@ -13,9 +13,13 @@ $util = new \OCA\Encryption\Util($view, \OCP\User::getUser());
|
||||||
$result = $util->initEncryption($params);
|
$result = $util->initEncryption($params);
|
||||||
|
|
||||||
if ($result !== false) {
|
if ($result !== false) {
|
||||||
$util->decryptAll();
|
$successful = $util->decryptAll();
|
||||||
\OCP\JSON::success(array('data' => array('message' => 'Files decrypted successfully')));
|
if ($successful === true) {
|
||||||
|
\OCP\JSON::success(array('data' => array('message' => 'Files decrypted successfully')));
|
||||||
|
} else {
|
||||||
|
\OCP\JSON::error(array('data' => array('message' => 'Couldn\'t decrypt your files, please check your owncloud.log or ask your administrator')));
|
||||||
|
}
|
||||||
} else {
|
} 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, check your password and try again')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue