Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions lib/private/Files/Storage/DAV.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
use Icewind\Streams\CallbackWrapper;
use Icewind\Streams\IteratorDirectory;
use OC\Files\Filesystem;
use OC\MemCache\ArrayCache;
use OC\Memcache\ArrayCache;
use OCP\AppFramework\Http;
use OCP\Constants;
use OCP\Diagnostics\IEventLogger;
Expand Down Expand Up @@ -86,6 +86,8 @@ class DAV extends Common {
protected $client;
/** @var ArrayCache */
protected $statCache;
/** @var ArrayCache */
protected $propfindCache;
/** @var IClientService */
protected $httpClientService;
/** @var ICertificateManager */
Expand All @@ -99,6 +101,7 @@ class DAV extends Common {
*/
public function __construct($params) {
$this->statCache = new ArrayCache();
$this->propfindCache = new ArrayCache();
$this->httpClientService = \OC::$server->getHTTPClientService();
if (isset($params['host']) && isset($params['user']) && isset($params['password'])) {
$host = $params['host'];
Expand Down Expand Up @@ -225,6 +228,7 @@ public function rmdir($path) {
$result = $this->simpleResponse('DELETE', $path . '/', null, 204);
$this->statCache->clear($path . '/');
$this->statCache->remove($path);
$this->propfindCache->remove($path);
return $result;
}

Expand All @@ -235,7 +239,16 @@ public function opendir($path) {
try {
$response = $this->client->propFind(
$this->encodePath($path),
['{DAV:}getetag'],
[
'{DAV:}getlastmodified',
'{DAV:}getcontentlength',
'{DAV:}getcontenttype',
'{http://owncloud.org/ns}permissions',
'{http://open-collaboration-services.org/ns}share-permissions',
'{DAV:}resourcetype',
'{DAV:}getetag',
'{DAV:}quota-available-bytes',
],
1
);
if ($response === false) {
Expand All @@ -249,12 +262,14 @@ public function opendir($path) {
$this->statCache->set($path, true);
}
foreach ($files as $file) {
$fileDetail = $response[$file];
$file = urldecode($file);
// do not store the real entry, we might not have all properties
if (!$this->statCache->hasKey($path)) {
$this->statCache->set($file, true);
}
$file = basename($file);
$this->propfindCache->set($this->encodePath($file), $fileDetail);
$content[] = $file;
}
return IteratorDirectory::wrap($content);
Expand All @@ -278,6 +293,10 @@ public function opendir($path) {
*/
protected function propfind($path) {
$path = $this->cleanPath($path);
$propfindCacheResponse = $this->propfindCache->get($this->encodePath($path));
if (!is_null($propfindCacheResponse)) {
return $propfindCacheResponse;
}
$cachedResponse = $this->statCache->get($path);
// we either don't know it, or we know it exists but need more details
if (is_null($cachedResponse) || $cachedResponse === true) {
Expand All @@ -297,6 +316,7 @@ protected function propfind($path) {
]
);
$this->statCache->set($path, $response);
$this->propfindCache->set($path, $response);
} catch (ClientHttpException $e) {
if ($e->getHttpStatus() === 404 || $e->getHttpStatus() === 405) {
$this->statCache->clear($path . '/');
Expand Down Expand Up @@ -358,6 +378,7 @@ public function unlink($path) {
$result = $this->simpleResponse('DELETE', $path, null, 204);
$this->statCache->clear($path . '/');
$this->statCache->remove($path);
$this->propfindCache->remove($path);
return $result;
}

Expand Down Expand Up @@ -473,6 +494,7 @@ public function touch($path, $mtime = null) {
if ($this->file_exists($path)) {
try {
$this->statCache->remove($path);
$this->propfindCache->remove($path);
$this->client->proppatch($this->encodePath($path), ['{DAV:}lastmodified' => $mtime]);
// non-owncloud clients might not have accepted the property, need to recheck it
$response = $this->client->propfind($this->encodePath($path), ['{DAV:}getlastmodified'], 0);
Expand Down Expand Up @@ -511,6 +533,7 @@ public function file_put_contents($path, $data) {
$path = $this->cleanPath($path);
$result = parent::file_put_contents($path, $data);
$this->statCache->remove($path);
$this->propfindCache->remove($path);
return $result;
}

Expand All @@ -524,6 +547,7 @@ protected function uploadFile($path, $target) {
// invalidate
$target = $this->cleanPath($target);
$this->statCache->remove($target);
$this->propfindCache->remove($target);
$source = fopen($path, 'r');

$this->httpClientService
Expand Down Expand Up @@ -800,6 +824,7 @@ public function hasUpdated($path, $time) {
try {
// force refresh for $path
$this->statCache->remove($path);
$this->propfindCache->remove($path);
$response = $this->propfind($path);
if ($response === false) {
if ($path === '') {
Expand Down