Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit 9410964

Browse files
committed
Fixing S3 and webdav access
1 parent 7ed8c22 commit 9410964

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

core/src/plugins/access.s3/class.s3AccessDriver.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
*
2121
*/
2222
defined('AJXP_EXEC') or die( 'Access not allowed');
23+
24+
require_once(AJXP_BIN_FOLDER . '/guzzle/vendor/autoload.php');
25+
2326
/**
2427
* AJXP_Plugin to access a webdav enabled server
2528
* @package AjaXplorer_Plugins

core/src/plugins/core.access/src/Stream/StreamWrapper.php

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ class StreamWrapper
8181
*/
8282
protected static $nextStat = array();
8383

84+
/**
85+
* @var array The list of files not found received as response
86+
* If we receive a 404 once, we should be able to tell if we created the file after that
87+
*/
88+
protected static $filesNotFound = array();
89+
8490
/**
8591
* Register the stream wrapper
8692
*
@@ -174,6 +180,8 @@ public function stream_flush()
174180
return false;
175181
}
176182

183+
$this->clearStatInfo($params['path/key']);
184+
177185
return true;
178186
}
179187

@@ -241,6 +249,8 @@ public function unlink($path)
241249
$this->triggerError("Unable to delete item : " . $e->getMessage());
242250
return false;
243251
}
252+
253+
return true;
244254
}
245255

246256
/**
@@ -258,6 +268,21 @@ public function stream_stat()
258268
return $stat;
259269
}
260270

271+
/*
272+
* Wrapper around stat
273+
*/
274+
public function file_exists($path) {
275+
$params = $this->getParams($path);
276+
277+
$key = $params['path/key'];
278+
279+
if (isset(static::$filesNotFound[$key])) {
280+
return false;
281+
}
282+
283+
return file_exists($path);
284+
}
285+
261286
/**
262287
* Provides information for is_dir, is_file, filesize, etc. Works on buckets, keys, and prefixes
263288
*
@@ -288,12 +313,10 @@ public function url_stat($path, $flags)
288313
} catch (ClientException $e) {
289314
if ($e->getCode() == 404) {
290315
static::$nextStat[$key] = false;
291-
292316
return false;
293317
}
294318
} catch (\Exception $e) {
295319
static::$nextStat[$key] = false;
296-
297320
return $this->triggerError('Cannot access file ' . $e->getMessage(), $flags);
298321
}
299322

@@ -315,6 +338,10 @@ public function mkdir($path, $mode, $options)
315338
{
316339
$params = $this->getParams($path);
317340

341+
$key = $params['path/key'];
342+
343+
$this->clearStatInfo($key);
344+
318345
try {
319346
$result = $this->getClient()->mkdir($params);
320347
} catch (\Exception $e) {
@@ -338,6 +365,10 @@ public function rmdir($path, $options)
338365
{
339366
$params = $this->getParams($path);
340367

368+
$key = $params['path/key'];
369+
370+
$this->clearStatInfo($key);
371+
341372
try {
342373
$result = $this->getClient()->rmdir($params);
343374
} catch (\Exception $e) {
@@ -587,9 +618,12 @@ protected function triggerError($errors, $flags = null)
587618
*/
588619
protected function clearStatInfo($path = null)
589620
{
590-
static::$nextStat = array();
591621
if ($path) {
622+
unset(static::$nextStat[$path]);
592623
clearstatcache(true, $path);
624+
} else {
625+
static::$nextStat = array();
626+
clearstatcache(true);
593627
}
594628
}
595629

core/src/plugins/core.ocs/src/Client/OCSClient.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public function sendInvitation(ShareInvitation $invitation)
4646
{
4747
$url = $invitation->getTargetHost();
4848
$client = self::getClient($url);
49-
$path = self::getPath($url);
5049

5150
$endpoints = self::findEndpointsForClient($client);
5251

@@ -59,7 +58,7 @@ public function sendInvitation(ShareInvitation $invitation)
5958
'remote' => AJXP_Utils::detectServerUrl(true)
6059
];
6160

62-
$response = $client->post(ltrim($path.$endpoints['share'], '/'), [
61+
$response = $client->post(ltrim($endpoints['share'], '/'), [
6362
'body' => $body
6463
]);
6564

@@ -82,11 +81,10 @@ public function cancelInvitation(ShareInvitation $invitation)
8281
{
8382
$url = $invitation->getTargetHost();
8483
$client = self::getClient($url);
85-
$path = self::getPath($url);
8684

8785
$endpoints = self::findEndpointsForClient($client);
8886

89-
$response = $client->post(ltrim($path.$endpoints['share'] . '/' . $invitation->getId() . '/unshare', '/'), [
87+
$response = $client->post(ltrim($endpoints['share'] . '/' . $invitation->getId() . '/unshare', '/'), [
9088
'body' => [
9189
'token' => $invitation->getLinkHash()
9290
]

0 commit comments

Comments
 (0)