diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-06-23 17:13:56 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-06-25 12:27:30 +0200 |
commit | 3d0805f27d1d84399ed87403f33cfbde556ae69a (patch) | |
tree | b368d3a1c70a63bc505583b688a25720566b80c6 /apps/files_encryption/lib | |
parent | 709691548dbf72c5763879136f3a0ba4e8a0c135 (diff) | |
download | nextcloud-server-3d0805f27d1d84399ed87403f33cfbde556ae69a.tar.gz nextcloud-server-3d0805f27d1d84399ed87403f33cfbde556ae69a.zip |
always use a \OC\Files\View
Diffstat (limited to 'apps/files_encryption/lib')
-rwxr-xr-x | apps/files_encryption/lib/helper.php | 10 | ||||
-rwxr-xr-x | apps/files_encryption/lib/keymanager.php | 59 |
2 files changed, 25 insertions, 44 deletions
diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php index c6f18602b2b..fed0788028f 100755 --- a/apps/files_encryption/lib/helper.php +++ b/apps/files_encryption/lib/helper.php @@ -430,18 +430,10 @@ class Helper { } /** - * glob uses different pattern than regular expressions, escape glob pattern only - * @param string $path unescaped path - * @return string path - */ - public static function escapeGlobPattern($path) { - return preg_replace('/(\*|\?|\[)/', '[$1]', $path); - } - - /** * find all share keys for a given file * @param string $path to the file * @param \OC\Files\View $view view, relative to data/ + * @return array list of files, path relative to data/ */ public static function findShareKeys($path, $view) { $result = array(); diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 98986d1486f..e71fec56854 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -133,20 +133,7 @@ class Keymanager { $basePath = '/' . $owner . '/files_encryption/keyfiles'; } - $targetPath = self::keySetPreparation($view, $filename, $basePath, $owner); - - if (!$view->is_dir($basePath . '/' . $targetPath)) { - - // create all parent folders - $info = pathinfo($basePath . '/' . $targetPath); - $keyfileFolderName = $view->getLocalFolder($info['dirname']); - - if (!file_exists($keyfileFolderName)) { - - mkdir($keyfileFolderName, 0750, true); - - } - } + $targetPath = self::keySetPreparation($view, $filename, $basePath); // try reusing key file if part file if (Helper::isPartialFilePath($targetPath)) { @@ -281,8 +268,9 @@ class Keymanager { $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; - if (!$view->file_exists('')) + if (!$view->file_exists('')) { $view->mkdir(''); + } $result = $view->file_put_contents($user . '.private.key', $key); @@ -340,7 +328,7 @@ class Keymanager { $basePath = '/' . $owner . '/files_encryption/share-keys'; } - $shareKeyPath = self::keySetPreparation($view, $filename, $basePath, $owner); + $shareKeyPath = self::keySetPreparation($view, $filename, $basePath); $result = true; @@ -466,8 +454,7 @@ class Keymanager { if ($view->is_dir($shareKeyPath)) { - $localPath = \OC\Files\Filesystem::normalizePath($view->getLocalFolder($shareKeyPath)); - self::recursiveDelShareKeys($localPath, $userIds); + self::recursiveDelShareKeys($shareKeyPath, $userIds, $view); } else { @@ -491,23 +478,25 @@ class Keymanager { * @param string $dir directory * @param array $userIds user ids for which the share keys should be deleted */ - private static function recursiveDelShareKeys($dir, $userIds) { - foreach ($userIds as $userId) { - $extension = '.' . $userId . '.shareKey'; - $escapedDir = Helper::escapeGlobPattern($dir); - $escapedExtension = Helper::escapeGlobPattern($extension); - $matches = glob($escapedDir . '/*' . $escapedExtension); - } - /** @var $matches array */ - foreach ($matches as $ma) { - if (!unlink($ma)) { - \OCP\Util::writeLog('Encryption library', - 'Could not delete shareKey; does not exist: "' . $ma . '"', \OCP\Util::ERROR); + private static function recursiveDelShareKeys($dir, $userIds, $view) { + + $dirContent = $view->opendir($dir); + + if (is_resource($dirContent)) { + while (($file = readdir($dirContent)) !== false) { + if (!\OC\Files\Filesystem::isIgnoredDir($file)) { + if ($view->is_dir($dir . '/' . $file)) { + self::recursiveDelShareKeys($dir . '/' . $file, $userIds, $view); + } else { + foreach ($userIds as $userId) { + if (preg_match("/(.*)." . $userId . ".shareKey/", $file)) { + $view->unlink($dir . '/' . $file); + } + } + } + } } - } - $subdirs = glob($escapedDir . '/*', GLOB_ONLYDIR); - foreach ($subdirs as $subdir) { - self::recursiveDelShareKeys($subdir, $userIds); + closedir($dirContent); } } @@ -516,7 +505,7 @@ class Keymanager { * @param string|boolean $path * @param string $basePath */ - protected static function keySetPreparation(\OC\Files\View $view, $path, $basePath, $userId) { + protected static function keySetPreparation(\OC\Files\View $view, $path, $basePath) { $targetPath = ltrim($path, '/'); |