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

Commit

Permalink
Fix S3 : add to core composer, look for a fake mtime for directories.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Sep 3, 2016
1 parent f856159 commit fc40146
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 17 deletions.
3 changes: 2 additions & 1 deletion core/src/core/composer.json
Expand Up @@ -16,7 +16,8 @@
"nikic/fast-route":"~1.0",
"symfony/console":"^3.0",
"davegardnerisme/nsqphp": "dev-master",
"sabre/dav":"1.8.10"
"sabre/dav":"1.8.10",
"aws/aws-sdk-php": "^3.19.4"
}

}
58 changes: 44 additions & 14 deletions core/src/plugins/access.s3/S3AccessWrapper.php
Expand Up @@ -24,6 +24,7 @@
use Pydio\Access\Core\Model\AJXP_Node;

use Pydio\Access\Driver\StreamProvider\FS\FsAccessWrapper;
use Pydio\Core\Model\Context;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Services\ConfService;
use Pydio\Core\Utils\ApplicationState;
Expand Down Expand Up @@ -70,12 +71,10 @@ public static function getResolvedOptionsForNode($node)
/**
* @param ContextInterface $ctx
* @param boolean $registerStream
* @return PydioS3Client
* @return S3Client
*/
protected static function getClientForContext(ContextInterface $ctx, $registerStream = true)
{
require_once(dirname(__FILE__)."/aws.phar");

$repoObject = $ctx->getRepository();
if (!isSet(self::$clients[$repoObject->getId()])) {
// Get a client
Expand Down Expand Up @@ -105,13 +104,13 @@ protected static function getClientForContext(ContextInterface $ctx, $registerSt
}
//SDK_VERSION IS A GLOBAL PARAM
ConfService::getConfStorageImpl()->_loadPluginConfig("access.s3", $globalOptions);
$sdkVersion = $globalOptions["SDK_VERSION"]; //$repoObject->driverInstance->driverConf['SDK_VERSION'];
$sdkVersion = $globalOptions["SDK_VERSION"];
if ($sdkVersion !== "v2" && $sdkVersion !== "v3") {
$sdkVersion = "v2";
}
if ($sdkVersion === "v3") {
require_once("PydioS3Client.php");
$s3Client = new PydioS3Client([
require_once("S3Client.php");
$s3Client = new S3Client([
"version" => $apiVersion,
"region" => $region,
"credentials" => $options
Expand Down Expand Up @@ -156,7 +155,7 @@ protected static function initPath($path, $streamType, $storeOpenContext = false
// Make sure to register s3:// wrapper
$client = self::getClientForContext($node->getContext(), true);
$protocol = "s3://";
if ($client instanceof PydioS3Client) {
if ($client instanceof S3Client) {
$protocol = "s3." . $repoId . "://";
}
$basePath = $repoObject->getContextOption($node->getContext(), "PATH");
Expand Down Expand Up @@ -213,15 +212,43 @@ public function url_stat($path, $flags)
if ($stat["mode"] == 0666) {
$stat[2] = $stat["mode"] |= 0100000; // S_ISREG
}
if($stat["mode"] === 0040777){
$node = new AJXP_Node($path);
$ctx = $node->getContext();
$repoObject = $node->getRepository();
$result = $this->getClientForContext($ctx)->listObjects([
'Bucket' => $repoObject->getContextOption($ctx, "CONTAINER"),
'Prefix' => ltrim($node->getPath(), "/"). '/',
'MaxKeys' => 1
]);
if (isSet($result['Contents']) && isSet($result['Contents'][0]['LastModified'])) {
$stat = $this->statForDir($result['Contents'][0]['LastModified']);
}

$parsed = parse_url($path);
if ($stat["mtime"] == $stat["ctime"] && $stat["ctime"] == $stat["atime"] && $stat["atime"] == 0 && $parsed["path"] != "/") {
//AJXP_Logger::debug(__CLASS__,__FUNCTION__,"Nullifying stats");
//return null;
}
return $stat;
}

protected function statForDir($lastModified){
$time = strtotime($lastModified);
return [
0 => 0, 'dev' => 0,
1 => 0, 'ino' => 0,
2 => 0040777, 'mode' => 0040777,
3 => 0, 'nlink' => 0,
4 => 0, 'uid' => 0,
5 => 0, 'gid' => 0,
6 => -1, 'rdev' => -1,
7 => 0, 'size' => 0,
8 => $time, 'atime' => $time,
9 => $time, 'mtime' => $time,
10 => $time, 'ctime' => $time,
11 => -1, 'blksize' => -1,
12 => -1, 'blocks' => -1,
];

}

/**
* Opens a handle to the dir
* Fix PEAR by being sure it ends up with "/", to avoid
Expand All @@ -246,9 +273,12 @@ public function dir_opendir($path, $options)
}


// DUPBLICATE STATIC FUNCTIONS TO BE SURE
// NOT TO MESS WITH self:: CALLS

/**
* DUPLICATE STATIC FUNCTIONS TO BE SURE
* NOT TO MESS WITH self:: CALLS
* @param $tmpDir
* @param $tmpFile
*/
public static function removeTmpFile($tmpDir, $tmpFile)
{
if (is_file($tmpFile)) unlink($tmpFile);
Expand Down
Expand Up @@ -26,7 +26,7 @@
require_once __DIR__ . DIRECTORY_SEPARATOR . "S3CacheService.php";
defined('AJXP_EXEC') or die( 'Access not allowed');

class PydioS3Client extends AwsS3Client
class S3Client extends AwsS3Client
{
/**
* Register a new stream wrapper who overwrite the Amazon S3 stream wrapper with this client instance.
Expand All @@ -35,7 +35,6 @@ class PydioS3Client extends AwsS3Client
*/
public function registerStreamWrapper($repositoryId)
{
/* S3Client + s3 protocol + cacheInterface */
StreamWrapper::register($this, "s3.".$repositoryId, new S3CacheService());
}
}

0 comments on commit fc40146

Please sign in to comment.