summaryrefslogtreecommitdiffstats
path: root/lib/private/files/view.php
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-06-18 18:27:20 +0200
committerVincent Petry <pvince81@owncloud.com>2015-06-18 18:27:20 +0200
commit6697f9524c0f65047afdb27de75d62eb58c5f458 (patch)
treefcf77fcb48cb0f707940e37d05ae5eb7207479a8 /lib/private/files/view.php
parent0b34d888e64c967d1322792fb62c8e7518b5ed6d (diff)
parent17be0993b404d22e74caf89a578eebfc0b706ff7 (diff)
downloadnextcloud-server-6697f9524c0f65047afdb27de75d62eb58c5f458.tar.gz
nextcloud-server-6697f9524c0f65047afdb27de75d62eb58c5f458.zip
Merge pull request #16963 from owncloud/fileinfo-lock
Acquire read lock when getting file or directory info
Diffstat (limited to 'lib/private/files/view.php')
-rw-r--r--lib/private/files/view.php77
1 files changed, 49 insertions, 28 deletions
diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index 2297221408b..47cbf35836c 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -988,7 +988,7 @@ class View {
return false;
}
- if(in_array('write', $hooks) || in_array('delete', $hooks) || in_array('read', $hooks)) {
+ if (in_array('write', $hooks) || in_array('delete', $hooks) || in_array('read', $hooks)) {
// always a shared lock during pre-hooks so the hook can read the file
$this->lockFile($path, ILockingProvider::LOCK_SHARED);
}
@@ -1148,6 +1148,7 @@ class View {
if (Cache\Scanner::isPartialFile($path)) {
return $this->getPartFileInfo($path);
}
+ $relativePath = $path;
$path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
$mount = Filesystem::getMountManager()->find($path);
@@ -1157,19 +1158,27 @@ class View {
if ($storage) {
$cache = $storage->getCache($internalPath);
- $data = $cache->get($internalPath);
- $watcher = $storage->getWatcher($internalPath);
+ try {
+ $this->lockFile($relativePath, ILockingProvider::LOCK_SHARED);
+ $data = $cache->get($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
- if (!$data) {
- if (!$storage->file_exists($internalPath)) {
- return false;
+ // if the file is not in the cache or needs to be updated, trigger the scanner and reload the data
+ if (!$data) {
+ 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);
+ } else if (!Cache\Scanner::isPartialFile($internalPath) && $watcher->checkUpdate($internalPath, $data)) {
+ $this->updater->propagate($path);
+ $data = $cache->get($internalPath);
}
- $scanner = $storage->getScanner($internalPath);
- $scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
- $data = $cache->get($internalPath);
- } else if (!Cache\Scanner::isPartialFile($internalPath) && $watcher->checkUpdate($internalPath, $data)) {
- $this->updater->propagate($path);
+ $this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
+ } catch (LockedException $e) {
+ // dont try to update the cache when the file is locked
$data = $cache->get($internalPath);
}
@@ -1231,26 +1240,38 @@ class View {
$cache = $storage->getCache($internalPath);
$user = \OC_User::getUser();
- $data = $cache->get($internalPath);
- $watcher = $storage->getWatcher($internalPath);
- if (!$data or $data['size'] === -1) {
- if (!$storage->file_exists($internalPath)) {
- return array();
- }
- $scanner = $storage->getScanner($internalPath);
- $scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
- $data = $cache->get($internalPath);
- } else if ($watcher->checkUpdate($internalPath, $data)) {
- $this->updater->propagate($path);
- $data = $cache->get($internalPath);
- }
-
- $folderId = $data['fileid'];
/**
* @var \OC\Files\FileInfo[] $files
*/
$files = array();
- $contents = $cache->getFolderContentsById($folderId); //TODO: mimetype_filter
+
+ try {
+ $this->lockFile($directory, ILockingProvider::LOCK_SHARED);
+
+ $data = $cache->get($internalPath);
+ $watcher = $storage->getWatcher($internalPath);
+ if (!$data or $data['size'] === -1) {
+ 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);
+ } else if ($watcher->checkUpdate($internalPath, $data)) {
+ $this->updater->propagate($path);
+ $data = $cache->get($internalPath);
+ }
+
+ $folderId = $data['fileid'];
+ $contents = $cache->getFolderContentsById($folderId); //TODO: mimetype_filter
+
+ $this->unlockFile($directory, ILockingProvider::LOCK_SHARED);
+ } catch (LockedException $e) {
+ // dont try to update the cache when the file is locked
+ $contents = $cache->getFolderContents($internalPath);
+ }
+
foreach ($contents as $content) {
if ($content['permissions'] === 0) {
$content['permissions'] = $storage->getPermissions($content['path']);