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

Commit 7f89b53

Browse files
committed
Merge pull request #925 from FireFoxIXI/develop
Added minor tweaks for getting the S3 driver working with EMC ViPR
2 parents 8030468 + 25597ff commit 7f89b53

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ public function detectStreamWrapper($register = false){
6666
}else{
6767
$options["region"] = $this->repository->getOption("REGION");
6868
}
69+
$proxy = $this->repository->getOption("PROXY");
70+
if(!empty($proxy)){
71+
$options['request.options'] = array('proxy' => $proxy);
72+
}
6973
$this->s3Client = S3Client::factory($options);
7074
$this->s3Client->registerStreamWrapper();
7175
}
@@ -86,6 +90,16 @@ public function initRepository()
8690
ConfService::setConf("PROBE_REAL_SIZE", false);
8791
$this->wrapperClassName = $wrapperData["classname"];
8892
$this->urlBase = $wrapperData["protocol"]."://".$this->repository->getId();
93+
94+
if ($recycle!= "" && !is_dir($this->urlBase. "/" . $recycle . "/")) {
95+
@mkdir($this->urlBase. "/" . $recycle . "/", 0777, true);
96+
if(!is_dir($this->urlBase. "/" . $recycle . "/")) {
97+
throw new AJXP_Exception("Cannot create recycle bin folder. Please check repository configuration or that your folder is writeable!");
98+
} else {
99+
$this->setHiddenAttribute(new AJXP_Node($this->urlBase. "/" . $recycle . "/"));
100+
}
101+
}
102+
89103
if ($recycle != "") {
90104
RecycleBinManager::init($this->urlBase, "/".$recycle);
91105
}

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,21 @@ public static function copyFileInStream($path, $stream)
192192
public static function changeMode($path, $chmodValue){}
193193

194194
public function rename($from, $to){
195-
if(is_dir($from)){
195+
196+
$fromUrl = parse_url($from);
197+
$repoId = $fromUrl["host"];
198+
$repoObject = ConfService::getRepositoryById($repoId);
199+
$isViPR = $repoObject->getOption("IS_VIPR");
200+
$isDir = false;
201+
if($isViPR === true) {
202+
if(is_dir($from . "/")) {
203+
$from .= '/';
204+
$to .= '/';
205+
$isDir = true;
206+
}
207+
}
208+
209+
if($isDir === true || is_dir($from)){
196210
AJXP_Logger::debug(__CLASS__, __FUNCTION__, "S3 Renaming dir $from to $to");
197211
require_once("aws.phar");
198212

@@ -215,12 +229,24 @@ public function rename($from, $to){
215229
}else{
216230
$options["region"] = $repoObject->getOption("REGION");
217231
}
232+
$proxy = $repoObject->getOption("PROXY");
233+
if(!empty($proxy)){
234+
$options['request.options'] = array('proxy' => $proxy);
235+
}
218236
$s3Client = S3Client::factory($options);
219237

220238
$bucket = $repoObject->getOption("CONTAINER");
221239
$basePath = $repoObject->getOption("PATH");
222240
$fromKeyname = trim(str_replace("//", "/", $basePath.parse_url($from, PHP_URL_PATH)),'/');
223241
$toKeyname = trim(str_replace("//", "/", $basePath.parse_url($to, PHP_URL_PATH)), '/');
242+
if($isViPR) {
243+
$toKeyname .= '/';
244+
$parts = explode('/', $bucket);
245+
$bucket = $parts[0];
246+
if(isset($parts[1])) {
247+
$fromKeyname = $parts[1] . "/" . $fromKeyname;
248+
}
249+
}
224250

225251
// Perform a batch of CopyObject operations.
226252
$batch = array();
@@ -234,6 +260,11 @@ public function rename($from, $to){
234260

235261
$currentFrom = $object['Key'];
236262
$currentTo = $toKeyname.substr($currentFrom, strlen($fromKeyname));
263+
if($isViPR) {
264+
if(isset($parts[1])) {
265+
$currentTo = $parts[1] . "/" . $currentTo;
266+
}
267+
}
237268
AJXP_Logger::debug(__CLASS__, __FUNCTION__, "S3 Should move one object ".$currentFrom. " to new key :".$currentTo);
238269
$batch[] = $s3Client->getCommand('CopyObject', array(
239270
'Bucket' => $bucket,

core/src/plugins/access.s3/manifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<param name="REGION" type="select" choices="us-east-1|US Standard (Virginia),us-west-1|US West 1 (Northern California),us-west-2|US West 2 (Oregon),eu-west-1|EU (Ireland), ap-southeast-2|South-East (Sydney), ap-southeast-1|South-East (Singapore),ap-northeast-1|Asia Pacific (Japan),sa-east-1|South America (Sao Paulo),us-gov-west-1|EU Governement Cloud" label="CONF_MESSAGE[Region]" description="CONF_MESSAGE[S3 storage region]" mandatory="true"/>
1414
<param name="STORAGE_URL" type="string" label="CONF_MESSAGE[Storage URL]" description="CONF_MESSAGE[Replace default AWS access points (built from region). Set a full URL, including protocol]" mandatory="false"/>
1515
<param name="CONTAINER" type="string" label="CONF_MESSAGE[Container]" description="CONF_MESSAGE[Root container in the S3 storage]" mandatory="true"/>
16+
<param name="PROXY" type="string" label="CONF_MESSAGE[Proxy]" description="CONF_MESSAGE[If you are using a proxy, for example: 127.0.0.1:80 or username:[email protected]:8080]" mandatory="false"/>
17+
<param name="IS_VIPR" type="boolean" label="CONF_MESSAGE[Is ViPR]" description="CONF_MESSAGE[If the backend storage is an EMC ViPR storage]" mandatory="false"/>
1618
</server_settings>
1719
<registry_contributions>
1820
<external_file filename="plugins/access.fs/fsTemplatePart.xml" include="client_configs/*" exclude=""/>

0 commit comments

Comments
 (0)