make sure that we always find all versions

This commit is contained in:
Bjoern Schiessle 2014-07-24 18:54:12 +02:00
parent c738f71657
commit dba2574c52
1 changed files with 38 additions and 23 deletions

View File

@ -191,8 +191,6 @@ class Storage {
return self::store($new_path); return self::store($new_path);
} }
self::expire($newpath);
if ( $files_view->is_dir($oldpath) && $versions_view->is_dir($oldpath) ) { if ( $files_view->is_dir($oldpath) && $versions_view->is_dir($oldpath) ) {
$versions_view->$operation($oldpath, $newpath); $versions_view->$operation($oldpath, $newpath);
} else if ( ($versions = Storage::getVersions($uid, $oldpath)) ) { } else if ( ($versions = Storage::getVersions($uid, $oldpath)) ) {
@ -203,6 +201,11 @@ class Storage {
$versions_view->$operation($oldpath.'.v'.$v['version'], $newpath.'.v'.$v['version']); $versions_view->$operation($oldpath.'.v'.$v['version'], $newpath.'.v'.$v['version']);
} }
} }
if (!$files_view->is_dir($newpath)) {
self::expire($newpath);
}
} }
/** /**
@ -257,35 +260,47 @@ class Storage {
public static function getVersions($uid, $filename, $userFullPath = '') { public static function getVersions($uid, $filename, $userFullPath = '') {
$versions = array(); $versions = array();
// fetch for old versions // fetch for old versions
$view = new \OC\Files\View('/' . $uid . '/' . self::VERSIONS_ROOT); $view = new \OC\Files\View('/' . $uid . '/');
$pathinfo = pathinfo($filename); $pathinfo = pathinfo($filename);
$files = $view->getDirectoryContent($pathinfo['dirname']);
$versionedFile = $pathinfo['basename']; $versionedFile = $pathinfo['basename'];
foreach ($files as $file) { $dir = self::VERSIONS_ROOT . '/' . $pathinfo['dirname'];
if ($file['type'] === 'file') {
$pos = strrpos($file['path'], '.v'); $dirContent = false;
$currentFile = substr($file['name'], 0, strrpos($file['name'], '.v')); if ($view->is_dir($dir)) {
if ($currentFile === $versionedFile) { $dirContent = $view->opendir($dir);
$version = substr($file['path'], $pos + 2); }
$key = $version . '#' . $filename;
$versions[$key]['cur'] = 0; if ($dirContent === false) {
$versions[$key]['version'] = $version; return $versions;
$versions[$key]['humanReadableTimestamp'] = self::getHumanReadableTimestamp($version); }
if (is_resource($dirContent)) {
while (($entryName = readdir($dirContent)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($entryName)) {
$pathparts = pathinfo($entryName);
$filename = $pathparts['filename'];
if ($filename === $versionedFile) {
$pathparts = pathinfo($entryName);
$timestamp = substr($pathparts['extension'], 1);
$filename = $pathparts['filename'];
$key = $timestamp . '#' . $filename;
$versions[$key]['version'] = $timestamp;
$versions[$key]['humanReadableTimestamp'] = self::getHumanReadableTimestamp($timestamp);
if (empty($userFullPath)) { if (empty($userFullPath)) {
$versions[$key]['preview'] = ''; $versions[$key]['preview'] = '';
} else { } else {
$versions[$key]['preview'] = \OCP\Util::linkToRoute('core_ajax_versions_preview', array('file' => $userFullPath, 'version' => $version)); $versions[$key]['preview'] = \OCP\Util::linkToRoute('core_ajax_versions_preview', array('file' => $userFullPath, 'version' => $timestamp));
} }
$versions[$key]['path'] = $filename; $versions[$key]['path'] = $filename;
$versions[$key]['name'] = $versionedFile; $versions[$key]['name'] = $versionedFile;
$versions[$key]['size'] = $file['size']; $versions[$key]['size'] = $view->filesize($dir . '/' . $entryName);
} }
} }
} }
closedir($dirContent);
}
// sort with newest version first // sort with newest version first
krsort($versions); krsort($versions);