make trashbin compatible with objectstore, replace glob with search in cache, make unknown free space work like unlimited free space

This commit is contained in:
Jörn Friedrich Dreyer 2014-10-10 18:26:43 +02:00
parent c8d8578d1a
commit 0254a3c406
2 changed files with 23 additions and 5 deletions

View File

@ -745,6 +745,9 @@ class Trashbin {
if ($quota === null || $quota === 'none') { if ($quota === null || $quota === 'none') {
$quota = \OC\Files\Filesystem::free_space('/'); $quota = \OC\Files\Filesystem::free_space('/');
$softQuota = false; $softQuota = false;
if ($quota === \OC\Files\SPACE_UNKNOWN) {
$quota = 0;
}
} else { } else {
$quota = \OCP\Util::computerFileSize($quota); $quota = \OCP\Util::computerFileSize($quota);
} }
@ -911,24 +914,29 @@ class Trashbin {
* *
* @param string $filename name of the file which should be restored * @param string $filename name of the file which should be restored
* @param int $timestamp timestamp when the file was deleted * @param int $timestamp timestamp when the file was deleted
* @return array
*/ */
private static function getVersionsFromTrash($filename, $timestamp) { private static function getVersionsFromTrash($filename, $timestamp) {
$view = new \OC\Files\View('/' . \OCP\User::getUser() . '/files_trashbin/versions'); $view = new \OC\Files\View('/' . \OCP\User::getUser() . '/files_trashbin/versions');
$versionsName = $view->getLocalFile($filename) . '.v';
$escapedVersionsName = preg_replace('/(\*|\?|\[)/', '[$1]', $versionsName);
$versions = array(); $versions = array();
//force rescan of versions, local storage may not have updated the cache
/** @var \OC\Files\Storage\Storage $storage */
list($storage, ) = $view->resolvePath('/');
$storage->getScanner()->scan('');
if ($timestamp) { if ($timestamp) {
// fetch for old versions // fetch for old versions
$matches = glob($escapedVersionsName . '*.d' . $timestamp); $matches = $view->searchRaw($filename . '.v%.d' . $timestamp);
$offset = -strlen($timestamp) - 2; $offset = -strlen($timestamp) - 2;
} else { } else {
$matches = glob($escapedVersionsName . '*'); $matches = $view->searchRaw($filename . '.v%');
} }
if (is_array($matches)) { if (is_array($matches)) {
foreach ($matches as $ma) { foreach ($matches as $ma) {
if ($timestamp) { if ($timestamp) {
$parts = explode('.v', substr($ma, 0, $offset)); $parts = explode('.v', substr($ma['path'], 0, $offset));
$versions[] = (end($parts)); $versions[] = (end($parts));
} else { } else {
$parts = explode('.v', $ma); $parts = explode('.v', $ma);

View File

@ -1109,6 +1109,16 @@ class View {
return $this->searchCommon('%' . $query . '%', 'search'); return $this->searchCommon('%' . $query . '%', 'search');
} }
/**
* search for files with the name matching $query
*
* @param string $query
* @return FileInfo[]
*/
public function searchRaw($query) {
return $this->searchCommon($query, 'search');
}
/** /**
* search for files by mimetype * search for files by mimetype
* *