added helper function to escape glob pattern

Conflicts:

	apps/files_encryption/lib/helper.php
This commit is contained in:
Björn Schießle 2013-07-05 14:58:33 +02:00
parent ec6350079f
commit 9575c2f37c
3 changed files with 15 additions and 5 deletions

View File

@ -497,7 +497,7 @@ class Hooks {
// handle share-keys // handle share-keys
$localKeyPath = $view->getLocalFile($baseDir . 'share-keys/' . $params['oldpath']); $localKeyPath = $view->getLocalFile($baseDir . 'share-keys/' . $params['oldpath']);
$escapedPath = preg_replace('/(\*|\?|\[)/', '[$1]', $localKeyPath); $escapedPath = Helper::escapeGlobPattern($localKeyPath);
$matches = glob($escapedPath . '*.shareKey'); $matches = glob($escapedPath . '*.shareKey');
foreach ($matches as $src) { foreach ($matches as $src) {
$dst = \OC\Files\Filesystem::normalizePath(str_replace($params['oldpath'], $params['newpath'], $src)); $dst = \OC\Files\Filesystem::normalizePath(str_replace($params['oldpath'], $params['newpath'], $src));

View File

@ -218,7 +218,6 @@ class Helper {
exit(); exit();
} }
/** /**
* check requirements for encryption app. * check requirements for encryption app.
* @return bool true if requirements are met * @return bool true if requirements are met
@ -234,3 +233,14 @@ class Helper {
return (bool) $result; return (bool) $result;
} }
} }
/**
* @brief glob uses different pattern than regular expressions, escape glob pattern only
* @param unescaped path
* @return escaped path
*/
public static function escapeGlobPattern($path) {
return preg_replace('/(\*|\?|\[)/', '[$1]', $path);
}
}

View File

@ -488,7 +488,7 @@ class Keymanager {
$view->unlink($baseDir . $filePath); $view->unlink($baseDir . $filePath);
} else { } else {
$localKeyPath = $view->getLocalFile($baseDir . $filePath); $localKeyPath = $view->getLocalFile($baseDir . $filePath);
$escapedPath = preg_replace('/(\*|\?|\[)/', '[$1]', $localKeyPath); $escapedPath = Helper::escapeGlobPattern($localKeyPath);
$matches = glob($escapedPath . '*.shareKey'); $matches = glob($escapedPath . '*.shareKey');
foreach ($matches as $ma) { foreach ($matches as $ma) {
$result = unlink($ma); $result = unlink($ma);
@ -549,8 +549,8 @@ class Keymanager {
private static function recursiveDelShareKeys($dir, $userIds) { private static function recursiveDelShareKeys($dir, $userIds) {
foreach ($userIds as $userId) { foreach ($userIds as $userId) {
$extension = '.' . $userId . '.shareKey'; $extension = '.' . $userId . '.shareKey';
$escapedDir = preg_replace('/(\*|\?|\[)/', '[$1]', $dir); $escapedDir = Helper::escapeGlobPattern($dir);
$escapedExtension = preg_replace('/(\*|\?|\[)/', '[$1]', $extension); $escapedExtension = Helper::escapeGlobPattern($extension);
$matches = glob($escapedDir . '/*' . $escapedExtension); $matches = glob($escapedDir . '/*' . $escapedExtension);
} }
/** @var $matches array */ /** @var $matches array */