From b1d620300e0671d5a7f24e994b62be310688d13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Tue, 26 Mar 2013 14:22:18 +0100 Subject: [PATCH] delete share keys if file gets deleted --- apps/files_encryption/lib/keymanager.php | 27 +++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 23c061b8e6..9022ed2cac 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -362,16 +362,23 @@ class Keymanager { public static function delShareKey( \OC_FilesystemView $view, $userId, $filePath ) { \OC_FileProxy::$enabled = false; - - $trimmed = ltrim( $filePath, '/' ); - $shareKeyPath = '/' . $userId . '/files_encryption/share-keys/' . $trimmed . '.shareKey'; - - // Unlink doesn't tell us if file was deleted (not found returns - // true), so we perform our own test - if ( $view->file_exists( $shareKeyPath ) ) { - - $result = $view->unlink( $shareKeyPath ); - + + $util = new Util( $view, $userId ); + + list($owner, $filename) = $util->getUidAndFilename($filePath); + + $shareKeyPath = '/' . $owner . '/files_encryption/share-keys/' . $filename; + + $absPath = $view->getLocalFile($shareKeyPath); + + $matches = glob(preg_quote($absPath).'.*.shareKey' ); + + if ( $matches ) { + + foreach ( $matches as $ma ) { + unlink($ma); + } + } else { \OC_Log::write( 'Encryption library', 'Could not delete shareKey; does not exist: "' . $shareKeyPath, \OC_Log::ERROR );