summaryrefslogtreecommitdiffstats
path: root/lib/private/files
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2015-11-10 13:32:05 +0100
committerRobin Appelman <icewind@owncloud.com>2015-11-19 13:29:12 +0100
commit02be8a3a12fbd63384f3dd79653ac94b05e646e6 (patch)
tree23aa0499586937dc963e5a193e2812a4ef73fc78 /lib/private/files
parent58eaeb267c60ed2aed4b5592a28d16f5453bb773 (diff)
downloadnextcloud-server-02be8a3a12fbd63384f3dd79653ac94b05e646e6.tar.gz
nextcloud-server-02be8a3a12fbd63384f3dd79653ac94b05e646e6.zip
Split getting cache entry and checking update to a seperate method
Diffstat (limited to 'lib/private/files')
-rw-r--r--lib/private/files/view.php104
1 files changed, 46 insertions, 58 deletions
diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index cee4b182425..2bac35cb18b 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -1179,6 +1179,43 @@ class View {
}
/**
+ * @param \OC\Files\Storage\Storage $storage
+ * @param string $internalPath
+ * @param string $relativePath
+ * @return array|bool
+ */
+ private function getCacheEntry($storage, $internalPath, $relativePath) {
+ $cache = $storage->getCache($internalPath);
+ $data = $cache->get($internalPath);
+ $watcher = $storage->getWatcher($internalPath);
+
+ try {
+ // if the file is not in the cache or needs to be updated, trigger the scanner and reload the data
+ if (!$data) {
+ $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);
+ }
+ } catch (LockedException $e) {
+ // if the file is locked we just use the old cache info
+ }
+
+ return $data;
+ }
+
+ /**
* get the filesystem info
*
* @param string $path
@@ -1204,46 +1241,15 @@ class View {
$internalPath = $mount->getInternalPath($path);
$data = null;
if ($storage) {
- $cache = $storage->getCache($internalPath);
-
- $data = $cache->get($internalPath);
- $watcher = $storage->getWatcher($internalPath);
-
- try {
- // if the file is not in the cache or needs to be updated, trigger the scanner and reload the data
- if (!$data) {
- $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);
- }
- } catch (LockedException $e) {
- // if the file is locked we just use the old cache info
- }
+ $data = $this->getCacheEntry($storage, $internalPath, $relativePath);
if ($data and isset($data['fileid'])) {
- // upgrades from oc6 or lower might not have the permissions set in the file cache
- if ($data['permissions'] === 0) {
- $data['permissions'] = $storage->getPermissions($data['path']);
- $cache->update($data['fileid'], array('permissions' => $data['permissions']));
- }
if ($includeMountPoints and $data['mimetype'] === 'httpd/unix-directory') {
//add the sizes of other mount points to the folder
$extOnly = ($includeMountPoints === 'ext');
- $mountPoints = Filesystem::getMountPoints($path);
- foreach ($mountPoints as $mountPoint) {
- $subStorage = Filesystem::getStorage($mountPoint);
+ $mounts = Filesystem::getMountManager()->findIn($path);
+ foreach ($mounts as $mount) {
+ $subStorage = $mount->getStorage();
if ($subStorage) {
// exclude shared storage ?
if ($extOnly && $subStorage instanceof \OC\Files\Storage\Shared) {
@@ -1294,30 +1300,12 @@ class View {
/**
* @var \OC\Files\FileInfo[] $files
*/
- $files = array();
+ $files = [];
- $data = $cache->get($internalPath);
- $watcher = $storage->getWatcher($internalPath);
- try {
- if (!$data or $data['size'] === -1) {
- $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);
- }
- } catch (LockedException $e) {
- // if the file is locked we just use the old cache info
+ $data = $this->getCacheEntry($storage, $internalPath, $directory);
+
+ if (!is_array($data) || !isset($data['fileid'])) {
+ return [];
}
$folderId = $data['fileid'];