Skip to content

Commit

Permalink
make trashbin compatible with objectstore, replace glob with search i…
Browse files Browse the repository at this point in the history
…n cache, make unknown free space work like unlimited free space
  • Loading branch information
butonic committed Oct 16, 2014
1 parent c8d8578 commit 0254a3c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
18 changes: 13 additions & 5 deletions apps/files_trashbin/lib/trashbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,9 @@ private static function calculateFreeSpace($trashbinSize, $user) {
if ($quota === null || $quota === 'none') {
$quota = \OC\Files\Filesystem::free_space('/');
$softQuota = false;
if ($quota === \OC\Files\SPACE_UNKNOWN) {
$quota = 0;
}
} else {
$quota = \OCP\Util::computerFileSize($quota);
}
Expand Down Expand Up @@ -911,24 +914,29 @@ private static function copy_recursive($source, $destination, $view) {
*
* @param string $filename name of the file which should be restored
* @param int $timestamp timestamp when the file was deleted
* @return array
*/
private static function getVersionsFromTrash($filename, $timestamp) {
$view = new \OC\Files\View('/' . \OCP\User::getUser() . '/files_trashbin/versions');
$versionsName = $view->getLocalFile($filename) . '.v';
$escapedVersionsName = preg_replace('/(\*|\?|\[)/', '[$1]', $versionsName);
$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) {
// fetch for old versions
$matches = glob($escapedVersionsName . '*.d' . $timestamp);
$matches = $view->searchRaw($filename . '.v%.d' . $timestamp);
$offset = -strlen($timestamp) - 2;
} else {
$matches = glob($escapedVersionsName . '*');
$matches = $view->searchRaw($filename . '.v%');
}

if (is_array($matches)) {
foreach ($matches as $ma) {
if ($timestamp) {
$parts = explode('.v', substr($ma, 0, $offset));
$parts = explode('.v', substr($ma['path'], 0, $offset));
$versions[] = (end($parts));
} else {
$parts = explode('.v', $ma);
Expand Down
10 changes: 10 additions & 0 deletions lib/private/files/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,16 @@ public function search($query) {
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
*
Expand Down

0 comments on commit 0254a3c

Please sign in to comment.