Merge pull request #3727 from owncloud/fix_glob_escaping

only escape glob pattern
This commit is contained in:
Björn Schießle 2013-06-17 06:35:47 -07:00
commit 0089437c25
3 changed files with 317 additions and 323 deletions

@ -1 +1 @@
Subproject commit 3ef9f738a9107879dddc7d97842cf4d2198fae4c
Subproject commit e312294ef62873df2b8c02e774f9dfe1b7fbc38d

View File

@ -24,6 +24,7 @@ namespace OCA\Files_Trashbin;
class Trashbin {
// how long do we keep files in the trash bin if no other value is defined in the config file (unit: days)
const DEFAULT_RETENTION_OBLIGATION = 180;
// unit: percentage; 50% of available disk space/quota
@ -96,13 +97,11 @@ class Trashbin {
\OC_Log::write('files_trashbin', 'trash bin database couldn\'t be updated', \OC_log::ERROR);
return;
}
\OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_moveToTrash',
array('filePath' => \OC\Files\Filesystem::normalizePath($file_path),
\OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_moveToTrash', array('filePath' => \OC\Files\Filesystem::normalizePath($file_path),
'trashPath' => \OC\Files\Filesystem::normalizePath($filename . '.d' . $timestamp)));
$trashbinSize += self::retainVersions($view, $file_path, $filename, $timestamp);
$trashbinSize += self::retainEncryptionKeys($view, $file_path, $filename, $timestamp);
} else {
\OC_Log::write('files_trashbin', 'Couldn\'t move ' . $file_path . ' to the trash bin', \OC_log::ERROR);
}
@ -110,7 +109,6 @@ class Trashbin {
$trashbinSize -= self::expire($trashbinSize);
self::setTrashbinSize($user, $trashbinSize);
}
/**
@ -201,9 +199,10 @@ class Trashbin {
} else {
// get local path to share-keys
$localShareKeysPath = $rootView->getLocalFile($sharekeys);
$escapedLocalShareKeysPath = preg_replace('/(\*|\?|\[)/', '[$1]', $localShareKeysPath);
// handle share-keys
$matches = glob(preg_quote($localShareKeysPath).'*.shareKey');
$matches = glob($escapedLocalShareKeysPath . '*.shareKey');
foreach ($matches as $src) {
// get source file parts
$pathinfo = pathinfo($src);
@ -228,7 +227,6 @@ class Trashbin {
unlink($src);
}
}
}
// enable proxy
@ -299,8 +297,7 @@ class Trashbin {
$view->chroot('/' . $user . '/files');
$view->touch('/' . $location . '/' . $filename . $ext, $mtime);
$view->chroot($fakeRoot);
\OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_restore',
array('filePath' => \OC\Files\Filesystem::normalizePath('/'.$location.'/'.$filename.$ext),
\OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', array('filePath' => \OC\Files\Filesystem::normalizePath('/' . $location . '/' . $filename . $ext),
'trashPath' => \OC\Files\Filesystem::normalizePath($file)));
if ($view->is_dir($target . $ext)) {
$trashbinSize -= self::calculateSize(new \OC\Files\View('/' . $user . '/' . $target . $ext));
@ -383,7 +380,6 @@ class Trashbin {
return $size;
}
/**
* @brief restore encryption keys from trash bin
*
@ -444,7 +440,6 @@ class Trashbin {
}
$size += self::calculateSize(new \OC\Files\View($sharekey));
$rootView->rename($sharekey, $owner . '/files_encryption/share-keys/' . $ownerPath);
} else {
// handle keyfiles
$size += $rootView->filesize($keyfile);
@ -672,8 +667,7 @@ class Trashbin {
$query = \OC_DB::prepare('SELECT `location`,`type`,`id`,`timestamp` FROM `*PREFIX*files_trash` WHERE `user`=?');
$result = $query->execute(array($user))->fetchAll();
$retention_obligation = \OC_Config::getValue('trashbin_retention_obligation',
self::DEFAULT_RETENTION_OBLIGATION);
$retention_obligation = \OC_Config::getValue('trashbin_retention_obligation', self::DEFAULT_RETENTION_OBLIGATION);
$limit = time() - ($retention_obligation * 86400);
@ -700,8 +694,6 @@ class Trashbin {
$size += $tmp;
$i++;
}
}
return $size;
@ -744,14 +736,15 @@ class Trashbin {
*/
private static function getVersionsFromTrash($filename, $timestamp) {
$view = new \OC\Files\View('/' . \OCP\User::getUser() . '/files_trashbin/versions');
$versionsName = $view->getLocalFile($filename);
$versionsName = $view->getLocalFile($filename) . '.v';
$escapedVersionsName = preg_replace('/(\*|\?|\[)/', '[$1]', $versionsName);
$versions = array();
if ($timestamp) {
// fetch for old versions
$matches = glob( $versionsName.'.v*.d'.$timestamp );
$matches = glob($escapedVersionsName . '*.d' . $timestamp);
$offset = -strlen($timestamp) - 2;
} else {
$matches = glob( $versionsName.'.v*' );
$matches = glob($escapedVersionsName . '*');
}
foreach ($matches as $ma) {
@ -797,8 +790,7 @@ class Trashbin {
if (!file_exists($root)) {
return 0;
}
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($root),
\RecursiveIteratorIterator::CHILD_FIRST);
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($root), \RecursiveIteratorIterator::CHILD_FIRST);
$size = 0;
foreach ($iterator as $path) {
@ -850,4 +842,5 @@ class Trashbin {
//Listen to delete user signal
\OCP\Util::connectHook('OC_User', 'pre_deleteUser', "OCA\Files_Trashbin\Hooks", "deleteUser_hook");
}
}

View File

@ -241,11 +241,12 @@ class Storage {
public static function getVersions($uid, $filename, $count = 0 ) {
if( \OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' ) {
$versions_fileview = new \OC\Files\View('/' . $uid . '/files_versions');
$versionsName = $versions_fileview->getLocalFile($filename);
$versionsName = $versions_fileview->getLocalFile($filename).'.v';
$escapedVersionName = preg_replace('/(\*|\?|\[)/', '[$1]', $versionsName);
$versions = array();
// fetch for old versions
$matches = glob(preg_quote($versionsName).'.v*' );
$matches = glob($escapedVersionName.'*');
if ( !$matches ) {
return $versions;