check for dir in deleteFileKey() and delShareKey(), to always handle all share keys and file keys on delete
This commit is contained in:
parent
73157133e8
commit
e717f7150e
2 changed files with 43 additions and 44 deletions
|
@ -178,21 +178,27 @@ class Keymanager {
|
|||
public static function deleteFileKey( \OC_FilesystemView $view, $userId, $path ) {
|
||||
|
||||
$trimmed = ltrim( $path, '/' );
|
||||
$keyPath = '/' . $userId . '/files_encryption/keyfiles/' . $trimmed . '.key';
|
||||
|
||||
// Unlink doesn't tell us if file was deleted (not found returns
|
||||
// true), so we perform our own test
|
||||
if ( $view->file_exists( $keyPath ) ) {
|
||||
|
||||
return $view->unlink( $keyPath );
|
||||
|
||||
} else {
|
||||
$keyPath = '/' . $userId . '/files_encryption/keyfiles/' . $trimmed;
|
||||
|
||||
$result = false;
|
||||
|
||||
if ( $view->is_dir($keyPath) ) {
|
||||
|
||||
$result = $view->unlink($keyPath);
|
||||
|
||||
} else if ( $view->file_exists( $keyPath.'.key' ) ) {
|
||||
|
||||
$result = $view->unlink( $keyPath.'.key' );
|
||||
|
||||
}
|
||||
|
||||
if ( !$result ) {
|
||||
|
||||
\OC_Log::write( 'Encryption library', 'Could not delete keyfile; does not exist: "' . $keyPath, \OC_Log::ERROR );
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
|
@ -365,22 +371,28 @@ class Keymanager {
|
|||
|
||||
$shareKeyPath = '/' . $userId . '/files_encryption/share-keys/' . $filePath;
|
||||
|
||||
$absPath = $view->getLocalFile($shareKeyPath);
|
||||
$result = false;
|
||||
|
||||
$matches = glob(preg_quote($absPath).'.*.shareKey' );
|
||||
if ( $view->is_dir($shareKeyPath) ) {
|
||||
$result = $view->unlink($shareKeyPath);
|
||||
} else {
|
||||
$absPath = $view->getLocalFile($shareKeyPath);
|
||||
|
||||
if ( $matches ) {
|
||||
$matches = glob(preg_quote($absPath).'.*.shareKey' );
|
||||
|
||||
if ( $matches ) {
|
||||
|
||||
foreach ( $matches as $ma ) {
|
||||
unlink($ma);
|
||||
}
|
||||
|
||||
foreach ( $matches as $ma ) {
|
||||
unlink($ma);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$result = true;
|
||||
}
|
||||
|
||||
if ( !result ) {
|
||||
\OC_Log::write( 'Encryption library', 'Could not delete shareKey; does not exist: "' . $shareKeyPath, \OC_Log::ERROR );
|
||||
|
||||
$result = false;
|
||||
|
||||
}
|
||||
|
||||
\OC_FileProxy::$enabled = false;
|
||||
|
|
|
@ -302,30 +302,17 @@ class Proxy extends \OC_FileProxy {
|
|||
list($owner, $ownerPath) = $util->getUidAndFilename($relPath);
|
||||
|
||||
$filePath = $owner . '/' . 'files_encryption' . '/' . 'keyfiles' . '/'. $ownerPath;
|
||||
|
||||
// Delete keyfile & shareKey so it isn't orphaned
|
||||
if (
|
||||
! (
|
||||
Keymanager::deleteFileKey( $view, $owner, $ownerPath )
|
||||
&& Keymanager::delShareKey( $view, $owner, $ownerPath )
|
||||
)
|
||||
) {
|
||||
|
||||
if ( $view->is_dir( $ownerPath ) ) {
|
||||
|
||||
// Dirs must be handled separately as deleteFileKey
|
||||
// doesn't handle them
|
||||
$view->unlink( $filePath );
|
||||
|
||||
} else {
|
||||
|
||||
// Delete keyfile & shareKey so it isn't orphaned
|
||||
if (
|
||||
! (
|
||||
Keymanager::deleteFileKey( $view, $owner, $ownerPath )
|
||||
&& Keymanager::delShareKey( $view, $owner, $ownerPath )
|
||||
)
|
||||
) {
|
||||
|
||||
\OC_Log::write( 'Encryption library', 'Keyfile or shareKey could not be deleted for file "'.$filePath.'"', \OC_Log::ERROR );
|
||||
\OC_Log::write( 'Encryption library', 'Keyfile or shareKey could not be deleted for file "'.$filePath.'"', \OC_Log::ERROR );
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
\OC_FileProxy::$enabled = true;
|
||||
|
|
Loading…
Reference in a new issue