Merge pull request #9263 from owncloud/remote-share-update
Better detecting of remote changes for external shares
This commit is contained in:
commit
1a3e698294
|
@ -33,6 +33,8 @@ class Storage extends DAV implements ISharedStorage {
|
|||
*/
|
||||
private $token;
|
||||
|
||||
private $updateChecked = false;
|
||||
|
||||
public function __construct($options) {
|
||||
$this->remote = $options['remote'];
|
||||
$this->remoteUser = $options['owner'];
|
||||
|
@ -100,4 +102,21 @@ class Storage extends DAV implements ISharedStorage {
|
|||
}
|
||||
return $this->scanner;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if a file or folder has been updated since $time
|
||||
*
|
||||
* @param string $path
|
||||
* @param int $time
|
||||
* @return bool
|
||||
*/
|
||||
public function hasUpdated($path, $time) {
|
||||
// since for owncloud webdav servers we can rely on etag propagation we only need to check the root of the storage
|
||||
// because of that we only do one check for the entire storage per request
|
||||
if ($this->updateChecked) {
|
||||
return false;
|
||||
}
|
||||
$this->updateChecked = true;
|
||||
return parent::hasUpdated('', $time);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -426,8 +426,22 @@ class DAV extends \OC\Files\Storage\Common {
|
|||
$this->init();
|
||||
$response = $this->client->propfind($this->encodePath($path), array('{http://owncloud.org/ns}permissions'));
|
||||
if (isset($response['{http://owncloud.org/ns}permissions'])) {
|
||||
return $this->parsePermissions($response['{http://owncloud.org/ns}permissions']);
|
||||
} else if ($this->is_dir($path)) {
|
||||
return \OCP\PERMISSION_ALL;
|
||||
} else if ($this->file_exists($path)) {
|
||||
return \OCP\PERMISSION_ALL - \OCP\PERMISSION_CREATE;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $permissionsString
|
||||
* @return int
|
||||
*/
|
||||
protected function parsePermissions($permissionsString) {
|
||||
$permissions = \OCP\PERMISSION_READ;
|
||||
$permissionsString = $response['{http://owncloud.org/ns}permissions'];
|
||||
if (strpos($permissionsString, 'R') !== false) {
|
||||
$permissions |= \OCP\PERMISSION_SHARE;
|
||||
}
|
||||
|
@ -437,16 +451,41 @@ class DAV extends \OC\Files\Storage\Common {
|
|||
if (strpos($permissionsString, 'W') !== false) {
|
||||
$permissions |= \OCP\PERMISSION_UPDATE;
|
||||
}
|
||||
if (strpos($permissionsString, 'C') !== false) {
|
||||
if (strpos($permissionsString, 'CK') !== false) {
|
||||
$permissions |= \OCP\PERMISSION_CREATE;
|
||||
$permissions |= \OCP\PERMISSION_UPDATE;
|
||||
}
|
||||
return $permissions;
|
||||
} else if ($this->is_dir($path)) {
|
||||
return \OCP\PERMISSION_ALL;
|
||||
} else if ($this->file_exists($path)) {
|
||||
return \OCP\PERMISSION_ALL - \OCP\PERMISSION_CREATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if a file or folder has been updated since $time
|
||||
*
|
||||
* @param string $path
|
||||
* @param int $time
|
||||
* @return bool
|
||||
*/
|
||||
public function hasUpdated($path, $time) {
|
||||
$this->init();
|
||||
$response = $this->client->propfind($this->encodePath($path), array(
|
||||
'{DAV:}getlastmodified',
|
||||
'{DAV:}getetag',
|
||||
'{http://owncloud.org/ns}permissions'
|
||||
));
|
||||
if (isset($response['{DAV:}getetag'])) {
|
||||
$cachedData = $this->getCache()->get($path);
|
||||
$etag = trim($response['{DAV:}getetag'], '"');
|
||||
if ($cachedData['etag'] !== $etag) {
|
||||
return true;
|
||||
} else if (isset($response['{http://owncloud.org/ns}permissions'])) {
|
||||
$permissions = $this->parsePermissions($response['{http://owncloud.org/ns}permissions']);
|
||||
return $permissions !== $cachedData['permissions'];
|
||||
} else {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$remoteMtime = strtotime($response['{DAV:}getlastmodified']);
|
||||
return $remoteMtime > $time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue