summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-10-29 16:38:16 +0100
committerVincent Petry <pvince81@owncloud.com>2014-10-29 16:38:16 +0100
commit106b9eb55c154c6ef4fac47fb62f70dbbd98a126 (patch)
treeccdc5e17701226e8f0d15106fdd36c764f9e636d /lib
parent7d10ec41e6817472eb831c3891f7d0a0d514037c (diff)
parent16cfca6a5fb3db897246e6ac9ccb7420cf256240 (diff)
downloadnextcloud-server-106b9eb55c154c6ef4fac47fb62f70dbbd98a126.tar.gz
nextcloud-server-106b9eb55c154c6ef4fac47fb62f70dbbd98a126.zip
Merge pull request #11409 from owncloud/watcher-reuse
Pass the cached data to the filesystem watcher
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/cache/watcher.php11
-rw-r--r--lib/private/files/view.php43
2 files changed, 32 insertions, 22 deletions
diff --git a/lib/private/files/cache/watcher.php b/lib/private/files/cache/watcher.php
index 5a4f53fb73d..f4572895b09 100644
--- a/lib/private/files/cache/watcher.php
+++ b/lib/private/files/cache/watcher.php
@@ -55,11 +55,14 @@ class Watcher {
* check $path for updates
*
* @param string $path
- * @return boolean|array true if path was updated, otherwise the cached data is returned
+ * @param array $cachedEntry
+ * @return boolean true if path was updated
*/
- public function checkUpdate($path) {
+ public function checkUpdate($path, $cachedEntry = null) {
if ($this->watchPolicy === self::CHECK_ALWAYS or ($this->watchPolicy === self::CHECK_ONCE and array_search($path, $this->checkedPaths) === false)) {
- $cachedEntry = $this->cache->get($path);
+ if (is_null($cachedEntry)) {
+ $cachedEntry = $this->cache->get($path);
+ }
$this->checkedPaths[] = $path;
if ($this->storage->hasUpdated($path, $cachedEntry['storage_mtime'])) {
if ($this->storage->is_dir($path)) {
@@ -73,7 +76,7 @@ class Watcher {
$this->cache->correctFolderSize($path);
return true;
}
- return $cachedEntry;
+ return false;
} else {
return false;
}
diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index 3d3406af94e..5f5f29ded4f 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -313,7 +313,7 @@ class View {
if (!$result) {
// If create file fails because of permissions on external storage like SMB folders,
// check file exists and return false if not.
- if(!$this->file_exists($path)){
+ if (!$this->file_exists($path)) {
return false;
}
if (is_null($mtime)) {
@@ -891,22 +891,23 @@ class View {
if ($storage) {
$cache = $storage->getCache($internalPath);
- if (!$cache->inCache($internalPath)) {
+ $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;
}
$scanner = $storage->getScanner($internalPath);
$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
- } else {
- $watcher = $storage->getWatcher($internalPath);
- $data = $watcher->checkUpdate($internalPath);
- }
-
- if (!is_array($data)) {
+ $data = $cache->get($internalPath);
+ } else if ($watcher->checkUpdate($internalPath, $data)) {
$data = $cache->get($internalPath);
}
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']));
@@ -956,26 +957,32 @@ class View {
if (!Filesystem::isValidPath($directory)) {
return $result;
}
- $path = Filesystem::normalizePath($this->fakeRoot . '/' . $directory);
- list($storage, $internalPath) = Filesystem::resolvePath($path);
+ $path = $this->getAbsolutePath($directory);
+ /** @var \OC\Files\Storage\Storage $storage */
+ list($storage, $internalPath) = $this->resolvePath($directory);
if ($storage) {
$cache = $storage->getCache($internalPath);
$user = \OC_User::getUser();
- if ($cache->getStatus($internalPath) < Cache\Cache::COMPLETE) {
+ $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);
- } else {
- $watcher = $storage->getWatcher($internalPath);
- $watcher->checkUpdate($internalPath);
+ $data = $cache->get($internalPath);
+ } else if ($watcher->checkUpdate($internalPath, $data)) {
+ $data = $cache->get($internalPath);
}
- $folderId = $cache->getId($internalPath);
+ $folderId = $data['fileid'];
/**
* @var \OC\Files\FileInfo[] $files
*/
$files = array();
- $contents = $cache->getFolderContents($internalPath, $folderId); //TODO: mimetype_filter
+ $contents = $cache->getFolderContentsById($folderId); //TODO: mimetype_filter
foreach ($contents as $content) {
if ($content['permissions'] === 0) {
$content['permissions'] = $storage->getPermissions($content['path']);
@@ -1032,7 +1039,7 @@ class View {
break;
}
}
- $rootEntry['path'] = substr($path . '/' . $rootEntry['name'], strlen($user) + 2); // full path without /$user/
+ $rootEntry['path'] = substr(Filesystem::normalizePath($path . '/' . $rootEntry['name']), strlen($user) + 2); // full path without /$user/
// if sharing was disabled for the user we remove the share permissions
if (\OCP\Util::isSharingDisabledForUser()) {
@@ -1213,7 +1220,7 @@ class View {
* @return string|null
*/
public function getPath($id) {
- $id = (int) $id;
+ $id = (int)$id;
$manager = Filesystem::getMountManager();
$mounts = $manager->findIn($this->fakeRoot);
$mounts[] = $manager->find($this->fakeRoot);