Merge pull request #15895 from owncloud/dav-getremoteetag

Get etag from remote OC server
This commit is contained in:
Joas Schilling 2015-06-03 17:20:25 +02:00
commit bb0cb0aaec
2 changed files with 35 additions and 3 deletions

View File

@ -682,7 +682,7 @@ class DAV extends Common {
public function getPermissions($path) { public function getPermissions($path) {
$this->init(); $this->init();
$path = $this->cleanPath($path); $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'])) { if (isset($response['{http://owncloud.org/ns}permissions'])) {
return $this->parsePermissions($response['{http://owncloud.org/ns}permissions']); return $this->parsePermissions($response['{http://owncloud.org/ns}permissions']);
} else if ($this->is_dir($path)) { } else if ($this->is_dir($path)) {
@ -694,6 +694,17 @@ class DAV extends 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 * @param string $permissionsString
* @return int * @return int
@ -733,8 +744,11 @@ class DAV extends Common {
$response = $this->propfind($path); $response = $this->propfind($path);
if (isset($response['{DAV:}getetag'])) { if (isset($response['{DAV:}getetag'])) {
$cachedData = $this->getCache()->get($path); $cachedData = $this->getCache()->get($path);
$etag = trim($response['{DAV:}getetag'], '"'); $etag = null;
if ($cachedData['etag'] !== $etag) { if (isset($response['{DAV:}getetag'])) {
$etag = trim($response['{DAV:}getetag'], '"');
}
if (!empty($etag) && $cachedData['etag'] !== $etag) {
return true; return true;
} else if (isset($response['{http://owncloud.org/ns}permissions'])) { } else if (isset($response['{http://owncloud.org/ns}permissions'])) {
$permissions = $this->parsePermissions($response['{http://owncloud.org/ns}permissions']); $permissions = $this->parsePermissions($response['{http://owncloud.org/ns}permissions']);

View File

@ -22,6 +22,8 @@
namespace Test\Files\Storage; namespace Test\Files\Storage;
use OC\Files\Cache\Watcher;
abstract class Storage extends \Test\TestCase { abstract class Storage extends \Test\TestCase {
/** /**
* @var \OC\Files\Storage\Storage instance * @var \OC\Files\Storage\Storage instance
@ -309,6 +311,22 @@ abstract class Storage extends \Test\TestCase {
$this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 5)); $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() { public function testUnlink() {
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));