private $connection;
private $bucket;
private static $tmpFiles = array();
+ private $test = false;
+ private $timeout = 15;
private function normalizePath($path) {
$path = trim($path, '/');
return $path;
}
+ private function testTimeout() {
+ if ($this->test) {
+ sleep($this->timeout);
+ }
+ }
+
public function __construct($params) {
if ( ! isset($params['key']) || ! isset($params['secret']) || ! isset($params['bucket'])) {
throw new \Exception("Access Key, Secret and Bucket have to be configured.");
}
$this->id = 'amazon::' . $params['key'] . md5($params['secret']);
+
$this->bucket = $params['bucket'];
$scheme = ($params['use_ssl'] === 'false') ? 'http' : 'https';
-
- if (isset($params['hostname']) && isset($params['port'])) {
- $base_url = $scheme.'://'.$params['hostname'].':'.$params['port'].'/';
- $this->connection = S3Client::factory(array(
- 'key' => $params['key'],
- 'secret' => $params['secret'],
- 'base_url' => $base_url
- ));
- } else {
- if ( ! isset($params['region'])) {
- $params['region'] = 'us-west-1';
- }
- $this->connection = S3Client::factory(array(
- 'key' => $params['key'],
- 'secret' => $params['secret'],
- 'scheme' => $scheme,
- 'region' => $params['region']
- ));
+ $this->test = ( isset($params['test'])) ? true : false;
+ $this->timeout = ( ! isset($params['timeout'])) ? 15 : $params['timeout'];
+ $params['region'] = ( ! isset($params['region'])) ? 'eu-west-1' : $params['region'];
+ $params['hostname'] = ( !isset($params['hostname'])) ? 's3.amazonaws.com' : $params['hostname'];
+ if ( ! isset($params['port'])) {
+ $params['port'] = ($params['use_ssl'] === 'false') ? 80 : 443;
}
+ $base_url = $scheme.'://'.$params['hostname'].':'.$params['port'].'/';
+
+ $this->connection = S3Client::factory(array(
+ 'key' => $params['key'],
+ 'secret' => $params['secret'],
+ 'base_url' => $base_url,
+ 'region' => $params['region']
+ ));
if (! $this->connection->isValidBucketName($this->bucket)) {
throw new \Exception("The configured bucket name is invalid.");
}
if ( ! $this->connection->doesBucketExist($this->bucket)) {
- $result = $this->connection->createBucket(array(
- 'Bucket' => $this->bucket
- ));
- while ( ! $this->connection->doesBucketExist($this->bucket)) {
- sleep(1);
+ try {
+ $result = $this->connection->createBucket(array(
+ 'Bucket' => $this->bucket
+ ));
+ $this->connection->waitUntilBucketExists(array(
+ 'Bucket' => $this->bucket,
+ 'waiter.interval' => 1,
+ 'waiter.max_attempts' => 15
+ ));
+ $this->testTimeout();
+ } catch (S3Exception $e) {
+ throw new \Exception("Creation of bucket failed.");
}
}
'ContentType' => 'httpd/unix-directory',
'ContentLength' => 0
));
+ $this->testTimeout();
}
}
'ContentType' => 'httpd/unix-directory',
'ContentLength' => 0
));
+ $this->testTimeout();
} catch (S3Exception $e) {
return false;
}
'Bucket' => $this->bucket,
'Key' => $path . '/'
));
+ $this->testTimeout();
} catch (S3Exception $e) {
return false;
}
'Bucket' => $this->bucket,
'Key' => $path
));
+ $this->testTimeout();
} catch (S3Exception $e) {
return false;
}
'Metadata' => $metadata,
'CopySource' => $this->bucket . '/' . $path
));
+ $this->testTimeout();
} else {
$result = $this->connection->putObject(array(
'Bucket' => $this->bucket,
'Key' => $path,
'Metadata' => $metadata
));
+ $this->testTimeout();
}
} catch (S3Exception $e) {
return false;
'Key' => $path2,
'CopySource' => $this->bucket . '/' . $path1
));
+ $this->testTimeout();
} catch (S3Exception $e) {
return false;
}
'Key' => $path2 . '/',
'CopySource' => $this->bucket . '/' . $path1 . '/'
));
+ $this->testTimeout();
} catch (S3Exception $e) {
return false;
}
'ContentType' => \OC_Helper::getMimeType($tmpFile),
'ContentLength' => filesize($tmpFile)
));
+ $this->testTimeout();
unlink($tmpFile);
$this->touch(dirname(self::$tmpFiles[$tmpFile]));