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

Commit

Permalink
Fixing S3 and webdav access
Browse files Browse the repository at this point in the history
  • Loading branch information
ghecquet committed Apr 8, 2016
1 parent 7ed8c22 commit 9410964
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
3 changes: 3 additions & 0 deletions core/src/plugins/access.s3/class.s3AccessDriver.php
Expand Up @@ -20,6 +20,9 @@
*
*/
defined('AJXP_EXEC') or die( 'Access not allowed');

require_once(AJXP_BIN_FOLDER . '/guzzle/vendor/autoload.php');

/**
* AJXP_Plugin to access a webdav enabled server
* @package AjaXplorer_Plugins
Expand Down
40 changes: 37 additions & 3 deletions core/src/plugins/core.access/src/Stream/StreamWrapper.php
Expand Up @@ -81,6 +81,12 @@ class StreamWrapper
*/
protected static $nextStat = array();

/**
* @var array The list of files not found received as response
* If we receive a 404 once, we should be able to tell if we created the file after that
*/
protected static $filesNotFound = array();

/**
* Register the stream wrapper
*
Expand Down Expand Up @@ -174,6 +180,8 @@ public function stream_flush()
return false;
}

$this->clearStatInfo($params['path/key']);

return true;
}

Expand Down Expand Up @@ -241,6 +249,8 @@ public function unlink($path)
$this->triggerError("Unable to delete item : " . $e->getMessage());
return false;
}

return true;
}

/**
Expand All @@ -258,6 +268,21 @@ public function stream_stat()
return $stat;
}

/*
* Wrapper around stat
*/
public function file_exists($path) {
$params = $this->getParams($path);

$key = $params['path/key'];

if (isset(static::$filesNotFound[$key])) {
return false;
}

return file_exists($path);
}

/**
* Provides information for is_dir, is_file, filesize, etc. Works on buckets, keys, and prefixes
*
Expand Down Expand Up @@ -288,12 +313,10 @@ public function url_stat($path, $flags)
} catch (ClientException $e) {
if ($e->getCode() == 404) {
static::$nextStat[$key] = false;

return false;
}
} catch (\Exception $e) {
static::$nextStat[$key] = false;

return $this->triggerError('Cannot access file ' . $e->getMessage(), $flags);
}

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

$key = $params['path/key'];

$this->clearStatInfo($key);

try {
$result = $this->getClient()->mkdir($params);
} catch (\Exception $e) {
Expand All @@ -338,6 +365,10 @@ public function rmdir($path, $options)
{
$params = $this->getParams($path);

$key = $params['path/key'];

$this->clearStatInfo($key);

try {
$result = $this->getClient()->rmdir($params);
} catch (\Exception $e) {
Expand Down Expand Up @@ -587,9 +618,12 @@ protected function triggerError($errors, $flags = null)
*/
protected function clearStatInfo($path = null)
{
static::$nextStat = array();
if ($path) {
unset(static::$nextStat[$path]);
clearstatcache(true, $path);
} else {
static::$nextStat = array();
clearstatcache(true);
}
}

Expand Down
6 changes: 2 additions & 4 deletions core/src/plugins/core.ocs/src/Client/OCSClient.php
Expand Up @@ -46,7 +46,6 @@ public function sendInvitation(ShareInvitation $invitation)
{
$url = $invitation->getTargetHost();
$client = self::getClient($url);
$path = self::getPath($url);

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

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

$response = $client->post(ltrim($path.$endpoints['share'], '/'), [
$response = $client->post(ltrim($endpoints['share'], '/'), [
'body' => $body
]);

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

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

$response = $client->post(ltrim($path.$endpoints['share'] . '/' . $invitation->getId() . '/unshare', '/'), [
$response = $client->post(ltrim($endpoints['share'] . '/' . $invitation->getId() . '/unshare', '/'), [
'body' => [
'token' => $invitation->getLinkHash()
]
Expand Down

0 comments on commit 9410964

Please sign in to comment.