aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files/ajax/list.php5
-rw-r--r--apps/files/index.php5
-rw-r--r--apps/files/lib/helper.php22
-rw-r--r--lib/private/files/cache/watcher.php46
-rw-r--r--lib/private/files/filesystem.php9
-rw-r--r--tests/lib/files/cache/watcher.php56
-rw-r--r--tests/lib/files/view.php3
7 files changed, 98 insertions, 48 deletions
diff --git a/apps/files/ajax/list.php b/apps/files/ajax/list.php
index 0be38c3b96f..c8286bc15ca 100644
--- a/apps/files/ajax/list.php
+++ b/apps/files/ajax/list.php
@@ -11,7 +11,8 @@ OCP\JSON::checkLoggedIn();
// Load the files
$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
$dir = \OC\Files\Filesystem::normalizePath($dir);
-if (!\OC\Files\Filesystem::is_dir($dir . '/')) {
+$dirInfo = \OC\Files\Filesystem::getFileInfo($dir);
+if (!$dirInfo->getType() === 'dir') {
header("HTTP/1.0 404 Not Found");
exit();
}
@@ -20,7 +21,7 @@ $doBreadcrumb = isset($_GET['breadcrumb']);
$data = array();
$baseUrl = OCP\Util::linkTo('files', 'index.php') . '?dir=';
-$permissions = \OCA\Files\Helper::getDirPermissions($dir);
+$permissions = $dirInfo->getPermissions();
// Make breadcrumb
if($doBreadcrumb) {
diff --git a/apps/files/index.php b/apps/files/index.php
index c9eea6a4174..ad7a2e210ed 100644
--- a/apps/files/index.php
+++ b/apps/files/index.php
@@ -37,8 +37,9 @@ OCP\App::setActiveNavigationEntry('files_index');
// Load the files
$dir = isset($_GET['dir']) ? stripslashes($_GET['dir']) : '';
$dir = \OC\Files\Filesystem::normalizePath($dir);
+$dirInfo = \OC\Files\Filesystem::getFileInfo($dir);
// Redirect if directory does not exist
-if (!\OC\Files\Filesystem::is_dir($dir . '/')) {
+if (!$dirInfo->getType() === 'dir') {
header('Location: ' . OCP\Util::getScriptName() . '');
exit();
}
@@ -94,7 +95,7 @@ $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
$breadcrumbNav->assign('breadcrumb', $breadcrumb);
$breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '?dir=');
-$permissions = \OCA\Files\Helper::getDirPermissions($dir);
+$permissions = $dirInfo->getPermissions();
if ($needUpgrade) {
OCP\Util::addscript('files', 'upgrade');
diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php
index 01fc65d76b7..ac8a2ad3200 100644
--- a/apps/files/lib/helper.php
+++ b/apps/files/lib/helper.php
@@ -112,26 +112,4 @@ class Helper
}
return $breadcrumb;
}
-
- /**
- * Returns the numeric permissions for the given directory.
- * @param string $dir directory without trailing slash
- * @return numeric permissions
- */
- public static function getDirPermissions($dir){
- $permissions = \OCP\PERMISSION_READ;
- if (\OC\Files\Filesystem::isCreatable($dir . '/')) {
- $permissions |= \OCP\PERMISSION_CREATE;
- }
- if (\OC\Files\Filesystem::isUpdatable($dir . '/')) {
- $permissions |= \OCP\PERMISSION_UPDATE;
- }
- if (\OC\Files\Filesystem::isDeletable($dir . '/')) {
- $permissions |= \OCP\PERMISSION_DELETE;
- }
- if (\OC\Files\Filesystem::isSharable($dir . '/')) {
- $permissions |= \OCP\PERMISSION_SHARE;
- }
- return $permissions;
- }
}
diff --git a/lib/private/files/cache/watcher.php b/lib/private/files/cache/watcher.php
index 251ecbe7071..48aa6f853ce 100644
--- a/lib/private/files/cache/watcher.php
+++ b/lib/private/files/cache/watcher.php
@@ -12,6 +12,14 @@ namespace OC\Files\Cache;
* check the storage backends for updates and change the cache accordingly
*/
class Watcher {
+ const CHECK_NEVER = 0; // never check the underlying filesystem for updates
+ const CHECK_ONCE = 1; // check the underlying filesystem for updates once every request for each file
+ const CHECK_ALWAYS = 2; // always check the underlying filesystem for updates
+
+ protected $watchPolicy = self::CHECK_ONCE;
+
+ protected $checkedPaths = array();
+
/**
* @var \OC\Files\Storage\Storage $storage
*/
@@ -23,7 +31,7 @@ class Watcher {
protected $cache;
/**
- * @var Scanner $scanner;
+ * @var Scanner $scanner ;
*/
protected $scanner;
@@ -37,26 +45,38 @@ class Watcher {
}
/**
+ * @param int $policy either \OC\Files\Cache\Watcher::UPDATE_NEVER, \OC\Files\Cache\Watcher::UPDATE_ONCE, \OC\Files\Cache\Watcher::UPDATE_ALWAYS
+ */
+ public function setPolicy($policy) {
+ $this->watchPolicy = $policy;
+ }
+
+ /**
* check $path for updates
*
* @param string $path
* @return boolean | array true if path was updated, otherwise the cached data is returned
*/
public function checkUpdate($path) {
- $cachedEntry = $this->cache->get($path);
- if ($this->storage->hasUpdated($path, $cachedEntry['storage_mtime'])) {
- if ($this->storage->is_dir($path)) {
- $this->scanner->scan($path, Scanner::SCAN_SHALLOW);
- } else {
- $this->scanner->scanFile($path);
- }
- if ($cachedEntry['mimetype'] === 'httpd/unix-directory') {
- $this->cleanFolder($path);
+ if ($this->watchPolicy === self::CHECK_ALWAYS or ($this->watchPolicy === self::CHECK_ONCE and array_search($path, $this->checkedPaths) === false)) {
+ $cachedEntry = $this->cache->get($path);
+ $this->checkedPaths[] = $path;
+ if ($this->storage->hasUpdated($path, $cachedEntry['storage_mtime'])) {
+ if ($this->storage->is_dir($path)) {
+ $this->scanner->scan($path, Scanner::SCAN_SHALLOW);
+ } else {
+ $this->scanner->scanFile($path);
+ }
+ if ($cachedEntry['mimetype'] === 'httpd/unix-directory') {
+ $this->cleanFolder($path);
+ }
+ $this->cache->correctFolderSize($path);
+ return true;
}
- $this->cache->correctFolderSize($path);
- return true;
+ return $cachedEntry;
+ } else {
+ return false;
}
- return $cachedEntry;
}
/**
diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php
index 0face6aa3bb..b6102f5c245 100644
--- a/lib/private/files/filesystem.php
+++ b/lib/private/files/filesystem.php
@@ -736,14 +736,7 @@ class Filesystem {
* @param string $path
* @param boolean $includeMountPoints whether to add mountpoint sizes,
* defaults to true
- * @return array
- *
- * returns an associative array with the following keys:
- * - size
- * - mtime
- * - mimetype
- * - encrypted
- * - versioned
+ * @return \OC\Files\FileInfo
*/
public static function getFileInfo($path, $includeMountPoints = true) {
return self::$defaultInstance->getFileInfo($path, $includeMountPoints);
diff --git a/tests/lib/files/cache/watcher.php b/tests/lib/files/cache/watcher.php
index 1920c276907..7f4f3c5ee98 100644
--- a/tests/lib/files/cache/watcher.php
+++ b/tests/lib/files/cache/watcher.php
@@ -11,7 +11,7 @@ namespace Test\Files\Cache;
class Watcher extends \PHPUnit_Framework_TestCase {
/**
- * @var \OC\Files\Storage\Storage[] $storages;
+ * @var \OC\Files\Storage\Storage[] $storages
*/
private $storages = array();
@@ -105,6 +105,60 @@ class Watcher extends \PHPUnit_Framework_TestCase {
$this->assertTrue($cache->inCache('foo.txt/bar.txt'));
}
+ public function testPolicyNever() {
+ $storage = $this->getTestStorage();
+ $cache = $storage->getCache();
+ $updater = $storage->getWatcher();
+
+ //set the mtime to the past so it can detect an mtime change
+ $cache->put('foo.txt', array('storage_mtime' => 10));
+
+ $updater->setPolicy(\OC\Files\Cache\Watcher::CHECK_NEVER);
+
+ $storage->file_put_contents('foo.txt', 'q');
+ $this->assertFalse($updater->checkUpdate('foo.txt'));
+
+ $cache->put('foo.txt', array('storage_mtime' => 20));
+ $storage->file_put_contents('foo.txt', 'w');
+ $this->assertFalse($updater->checkUpdate('foo.txt'));
+ }
+
+ public function testPolicyOnce() {
+ $storage = $this->getTestStorage();
+ $cache = $storage->getCache();
+ $updater = $storage->getWatcher();
+
+ //set the mtime to the past so it can detect an mtime change
+ $cache->put('foo.txt', array('storage_mtime' => 10));
+
+ $updater->setPolicy(\OC\Files\Cache\Watcher::CHECK_ONCE);
+
+ $storage->file_put_contents('foo.txt', 'q');
+ $this->assertTrue($updater->checkUpdate('foo.txt'));
+
+ $cache->put('foo.txt', array('storage_mtime' => 20));
+ $storage->file_put_contents('foo.txt', 'w');
+ $this->assertFalse($updater->checkUpdate('foo.txt'));
+ }
+
+ public function testPolicyAlways() {
+ $storage = $this->getTestStorage();
+ $cache = $storage->getCache();
+ $updater = $storage->getWatcher();
+
+ //set the mtime to the past so it can detect an mtime change
+ $cache->put('foo.txt', array('storage_mtime' => 10));
+
+ $updater->setPolicy(\OC\Files\Cache\Watcher::CHECK_ALWAYS);
+
+ $storage->file_put_contents('foo.txt', 'q');
+ $this->assertTrue($updater->checkUpdate('foo.txt'));
+
+ $cache->put('foo.txt', array('storage_mtime' => 20));
+ $storage->file_put_contents('foo.txt', 'w');
+ $this->assertTrue($updater->checkUpdate('foo.txt'));
+ }
+
/**
* @param bool $scan
* @return \OC\Files\Storage\Storage
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index 72a2f854cb2..371d1ed1798 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -7,6 +7,8 @@
namespace Test\Files;
+use OC\Files\Cache\Watcher;
+
class TemporaryNoTouch extends \OC\Files\Storage\Temporary {
public function touch($path, $mtime = null) {
return false;
@@ -249,6 +251,7 @@ class View extends \PHPUnit_Framework_TestCase {
function testWatcher() {
$storage1 = $this->getTestStorage();
\OC\Files\Filesystem::mount($storage1, array(), '/');
+ $storage1->getWatcher()->setPolicy(Watcher::CHECK_ALWAYS);
$rootView = new \OC\Files\View('');