when a file is locked use old cache data

This commit is contained in:
Robin Appelman 2015-11-04 14:45:10 +01:00
parent 0a56313ca4
commit c487f0f138
1 changed files with 37 additions and 29 deletions

View File

@ -1194,23 +1194,27 @@ class View {
$data = $cache->get($internalPath); $data = $cache->get($internalPath);
$watcher = $storage->getWatcher($internalPath); $watcher = $storage->getWatcher($internalPath);
// if the file is not in the cache or needs to be updated, trigger the scanner and reload the data try {
if (!$data) { // if the file is not in the cache or needs to be updated, trigger the scanner and reload the data
$this->lockFile($relativePath, ILockingProvider::LOCK_SHARED); if (!$data) {
if (!$storage->file_exists($internalPath)) { $this->lockFile($relativePath, ILockingProvider::LOCK_SHARED);
if (!$storage->file_exists($internalPath)) {
$this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
return false;
}
$scanner = $storage->getScanner($internalPath);
$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
$data = $cache->get($internalPath);
$this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
} else if (!Cache\Scanner::isPartialFile($internalPath) && $watcher->needsUpdate($internalPath, $data)) {
$this->lockFile($relativePath, ILockingProvider::LOCK_SHARED);
$watcher->update($internalPath, $data);
$this->updater->propagate($path);
$data = $cache->get($internalPath);
$this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED); $this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
return false;
} }
$scanner = $storage->getScanner($internalPath); } catch (LockedException $e) {
$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW); // if the file is locked we just use the old cache info
$data = $cache->get($internalPath);
$this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
} else if (!Cache\Scanner::isPartialFile($internalPath) && $watcher->needsUpdate($internalPath, $data)) {
$this->lockFile($relativePath, ILockingProvider::LOCK_SHARED);
$watcher->update($internalPath, $data);
$this->updater->propagate($path);
$data = $cache->get($internalPath);
$this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
} }
if ($data and isset($data['fileid'])) { if ($data and isset($data['fileid'])) {
@ -1278,22 +1282,26 @@ class View {
$data = $cache->get($internalPath); $data = $cache->get($internalPath);
$watcher = $storage->getWatcher($internalPath); $watcher = $storage->getWatcher($internalPath);
if (!$data or $data['size'] === -1) { try {
$this->lockFile($directory, ILockingProvider::LOCK_SHARED); if (!$data or $data['size'] === -1) {
if (!$storage->file_exists($internalPath)) { $this->lockFile($directory, ILockingProvider::LOCK_SHARED);
if (!$storage->file_exists($internalPath)) {
$this->unlockFile($directory, ILockingProvider::LOCK_SHARED);
return array();
}
$scanner = $storage->getScanner($internalPath);
$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
$data = $cache->get($internalPath);
$this->unlockFile($directory, ILockingProvider::LOCK_SHARED);
} else if ($watcher->needsUpdate($internalPath, $data)) {
$this->lockFile($directory, ILockingProvider::LOCK_SHARED);
$watcher->update($internalPath, $data);
$this->updater->propagate($path);
$data = $cache->get($internalPath);
$this->unlockFile($directory, ILockingProvider::LOCK_SHARED); $this->unlockFile($directory, ILockingProvider::LOCK_SHARED);
return array();
} }
$scanner = $storage->getScanner($internalPath); } catch (LockedException $e) {
$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW); // if the file is locked we just use the old cache info
$data = $cache->get($internalPath);
$this->unlockFile($directory, ILockingProvider::LOCK_SHARED);
} else if ($watcher->needsUpdate($internalPath, $data)) {
$this->lockFile($directory, ILockingProvider::LOCK_SHARED);
$watcher->update($internalPath, $data);
$this->updater->propagate($path);
$data = $cache->get($internalPath);
$this->unlockFile($directory, ILockingProvider::LOCK_SHARED);
} }
$folderId = $data['fileid']; $folderId = $data['fileid'];