summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-06-22 20:11:17 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-06-22 20:11:17 +0200
commit1bdd3f7dc3026226ff6757188e13640d611321ff (patch)
tree03edaa889745e706ed37615b641168869c1088c2
parent6464f6b25b537cdc181e18d571ab4417c0759342 (diff)
parentf81ba63a52549a7fc8cd38f64b40ab2c8d184398 (diff)
downloadnextcloud-server-1bdd3f7dc3026226ff6757188e13640d611321ff.tar.gz
nextcloud-server-1bdd3f7dc3026226ff6757188e13640d611321ff.zip
Merge pull request #16734 from owncloud/stable8-dav-getremoteetag
[stable8] Get etag from remote OC server
-rw-r--r--lib/private/files/storage/dav.php20
-rw-r--r--tests/lib/files/storage/storage.php18
2 files changed, 35 insertions, 3 deletions
diff --git a/lib/private/files/storage/dav.php b/lib/private/files/storage/dav.php
index 9734d36f37d..1385c08e906 100644
--- a/lib/private/files/storage/dav.php
+++ b/lib/private/files/storage/dav.php
@@ -468,7 +468,7 @@ class DAV extends \OC\Files\Storage\Common {
public function getPermissions($path) {
$this->init();
$path = $this->cleanPath($path);
- $response = $this->client->propfind($this->encodePath($path), array('{http://owncloud.org/ns}permissions'));
+ $response = $this->propfind($path);
if (isset($response['{http://owncloud.org/ns}permissions'])) {
return $this->parsePermissions($response['{http://owncloud.org/ns}permissions']);
} else if ($this->is_dir($path)) {
@@ -480,6 +480,17 @@ class DAV extends \OC\Files\Storage\Common {
}
}
+ /** {@inheritdoc} */
+ public function getETag($path) {
+ $this->init();
+ $path = $this->cleanPath($path);
+ $response = $this->propfind($path);
+ if (isset($response['{DAV:}getetag'])) {
+ return trim($response['{DAV:}getetag'], '"');
+ }
+ return parent::getEtag($path);
+ }
+
/**
* @param string $permissionsString
* @return int
@@ -521,8 +532,11 @@ class DAV extends \OC\Files\Storage\Common {
));
if (isset($response['{DAV:}getetag'])) {
$cachedData = $this->getCache()->get($path);
- $etag = trim($response['{DAV:}getetag'], '"');
- if ($cachedData['etag'] !== $etag) {
+ $etag = null;
+ if (isset($response['{DAV:}getetag'])) {
+ $etag = trim($response['{DAV:}getetag'], '"');
+ }
+ if (!empty($etag) && $cachedData['etag'] !== $etag) {
return true;
} else if (isset($response['{http://owncloud.org/ns}permissions'])) {
$permissions = $this->parsePermissions($response['{http://owncloud.org/ns}permissions']);
diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php
index 30f403d60df..7f1900aca25 100644
--- a/tests/lib/files/storage/storage.php
+++ b/tests/lib/files/storage/storage.php
@@ -22,6 +22,8 @@
namespace Test\Files\Storage;
+use OC\Files\Cache\Watcher;
+
abstract class Storage extends \Test\TestCase {
/**
* @var \OC\Files\Storage\Storage instance
@@ -307,6 +309,22 @@ abstract class Storage extends \Test\TestCase {
$this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 5));
}
+ /**
+ * Test whether checkUpdate properly returns false when there was
+ * no change.
+ */
+ public function testCheckUpdate() {
+ if ($this->instance instanceof \OC\Files\Storage\Wrapper\Wrapper) {
+ $this->markTestSkipped('Cannot test update check on wrappers');
+ }
+ $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $watcher = $this->instance->getWatcher();
+ $watcher->setPolicy(Watcher::CHECK_ALWAYS);
+ $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));
+ $this->assertTrue($watcher->checkUpdate('/lorem.txt'), 'Update detected');
+ $this->assertFalse($watcher->checkUpdate('/lorem.txt'), 'No update');
+ }
+
public function testUnlink() {
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));