Skip to content

Commit

Permalink
Implement code style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed Nov 8, 2019
1 parent ac79feb commit 5610db8
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 105 deletions.
8 changes: 4 additions & 4 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
*
* @copyright Copyright (c) 2018, ownCloud GmbH.
* @license GPL-2.0
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/

require_once dirname(__DIR__) . '/vendor/autoload.php';
require_once \dirname(__DIR__) . '/vendor/autoload.php';

$app = new \OCA\FilesExternalS3\AppInfo\Application();
43 changes: 21 additions & 22 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
*
* @copyright Copyright (c) 2018, ownCloud GmbH.
* @license GPL-2.0
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Expand All @@ -34,29 +34,28 @@
* @package OCA\FilesExternalS3\AppInfo
*/
class Application extends App implements IBackendProvider, IAuthMechanismProvider {
public function __construct(array $urlParams = []) {
parent::__construct('files_external_s3', $urlParams);

public function __construct(array $urlParams = []) {
parent::__construct('files_external_s3', $urlParams);

$container = $this->getContainer();
$container = $this->getContainer();

/** @var \OCP\Files\External\IStoragesBackendService $backendService */
$backendService = $container->getServer()->getStoragesBackendService();
$backendService->registerBackendProvider($this);
$backendService->registerAuthMechanismProvider($this);
}
/** @var \OCP\Files\External\IStoragesBackendService $backendService */
$backendService = $container->getServer()->getStoragesBackendService();
$backendService->registerBackendProvider($this);
$backendService->registerAuthMechanismProvider($this);
}

/**
* @{inheritdoc}
*/
public function getBackends() {
$container = $this->getContainer();
/**
* @{inheritdoc}
*/
public function getBackends() {
$container = $this->getContainer();

$backends = [
$container->query(AmazonS3::class)
];
return $backends;
}
$backends = [
$container->query(AmazonS3::class)
];
return $backends;
}

/**
* @{inheritdoc}
Expand Down
2 changes: 0 additions & 2 deletions lib/Auth/AccessKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
* Amazon S3 access key authentication
*/
class AccessKey extends AuthMechanism {

const SCHEME_AMAZONS3_ACCESSKEY = 'amazons3_accesskey';

public function __construct(IL10N $l) {
Expand All @@ -46,5 +45,4 @@ public function __construct(IL10N $l) {
->setType(DefinitionParameter::VALUE_PASSWORD),
]);
}

}
2 changes: 0 additions & 2 deletions lib/Backend/AmazonS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use OCP\IL10N;

class AmazonS3 extends Backend {

public function __construct(IL10N $l) {
$this
->setIdentifier('files_external_s3')
Expand All @@ -52,5 +51,4 @@ public function __construct(IL10N $l) {
->addAuthScheme(AccessKey::SCHEME_AMAZONS3_ACCESSKEY);
;
}

}
57 changes: 25 additions & 32 deletions lib/Storage/AmazonS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

namespace OCA\FilesExternalS3\Storage;


use Aws\Handler\GuzzleV5\GuzzleHandler;
use Aws\S3\Exception\S3Exception;
use Aws\S3\S3Client;
Expand Down Expand Up @@ -84,7 +83,7 @@ class AmazonS3 extends \OCP\Files\Storage\StorageAdapter {
* @return string correctly encoded path
*/
private function normalizePath($path) {
$path = trim($path, '/');
$path = \trim($path, '/');

if (!$path) {
$path = '.';
Expand All @@ -98,7 +97,7 @@ private function normalizePath($path) {
*/
private function testTimeout() {
if ($this->test) {
sleep($this->timeout);
\sleep($this->timeout);
}
}

Expand Down Expand Up @@ -185,7 +184,6 @@ public function file_exists($path) {
return $this->filetype($path) !== false;
}


public function rmdir($path) {
$path = $this->normalizePath($path);

Expand All @@ -211,7 +209,7 @@ protected function clearBucket() {
return false;
}

private function batchDelete ($path = null) {
private function batchDelete($path = null) {
$params = [
'Bucket' => $this->bucket
];
Expand All @@ -228,9 +226,9 @@ private function batchDelete ($path = null) {
if (empty($keys)) {
continue;
}
$keys = array_map(function ($key) {
$keys = \array_map(function ($key) {
echo $key;
return array('Key' => $key);
return ['Key' => $key];
}, $keys);
// ... so we can delete the files in batches
$this->getConnection()->deleteObjects([
Expand Down Expand Up @@ -292,7 +290,7 @@ public function stat($path) {
if ($this->is_dir($path)) {
//folders don't really exist
$stat['size'] = -1; //unknown
$stat['mtime'] = time() - $this->rescanDelay * 1000;
$stat['mtime'] = \time() - $this->rescanDelay * 1000;
} else {
$result = $this->getConnection()->headObject([
'Bucket' => $this->bucket,
Expand All @@ -301,15 +299,15 @@ public function stat($path) {

$stat['size'] = $result['ContentLength'] ?: 0;
if (isset($result['Metadata']['lastmodified'])) {
$stat['mtime'] = strtotime($result['Metadata']['lastmodified']);
$stat['mtime'] = \strtotime($result['Metadata']['lastmodified']);
} else {
$stat['mtime'] = strtotime($result['LastModified']);
$stat['mtime'] = \strtotime($result['LastModified']);
}
}
$stat['atime'] = time();
$stat['atime'] = \time();

return $stat;
} catch(S3Exception $e) {
} catch (S3Exception $e) {
\OCP\Util::logException('files_external', $e);
return false;
}
Expand Down Expand Up @@ -378,7 +376,7 @@ public function fopen($path, $mode) {
return false;
}

return fopen($tmpFile, 'r');
return \fopen($tmpFile, 'r');
case 'w':
case 'wb':
case 'a':
Expand All @@ -391,20 +389,20 @@ public function fopen($path, $mode) {
case 'x+':
case 'c':
case 'c+':
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
if (\strrpos($path, '.') !== false) {
$ext = \substr($path, \strrpos($path, '.'));
} else {
$ext = '';
}
$tmpFile = \OCP\Files::tmpFile($ext);
\OC\Files\Stream\Close::registerCallback($tmpFile, [$this, 'writeBack']);
if ($this->file_exists($path)) {
$source = $this->fopen($path, 'r');
file_put_contents($tmpFile, $source);
\file_put_contents($tmpFile, $source);
}
self::$tmpFiles[$tmpFile] = $path;

return fopen('close://' . $tmpFile, $mode);
return \fopen('close://' . $tmpFile, $mode);
}
return false;
}
Expand All @@ -413,10 +411,10 @@ public function touch($path, $mtime = null) {
$path = $this->normalizePath($path);

if ($mtime === null) {
$mtime = time();
$mtime = \time();
}
$metadata = [
'lastmodified' => gmdate(\DateTime::RFC1123, $mtime)
'lastmodified' => \gmdate(\DateTime::RFC1123, $mtime)
];

$fileType = $this->filetype($path);
Expand Down Expand Up @@ -485,8 +483,8 @@ public function copy($path1, $path2) {
}

$dh = $this->opendir($path1);
if (is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if (\is_resource($dh)) {
while (($file = \readdir($dh)) !== false) {
if (\OC\Files\Filesystem::isIgnoredDir($file)) {
continue;
}
Expand All @@ -506,7 +504,6 @@ public function rename($path1, $path2) {
$path2 = $this->normalizePath($path2);

if ($this->is_file($path1)) {

if ($this->copy($path1, $path2) === false) {
return false;
}
Expand All @@ -516,7 +513,6 @@ public function rename($path1, $path2) {
return false;
}
} else {

if ($this->copy($path1, $path2) === false) {
return false;
}
Expand All @@ -532,7 +528,6 @@ public function rename($path1, $path2) {

public function test() {
if ($this->getConnection()->getApi()->hasOperation('GetBucketAcl')) {

$test = $this->getConnection()->getBucketAcl([
'Bucket' => $this->bucket,
]);
Expand All @@ -543,12 +538,12 @@ public function test() {
}

$buckets = $this->getConnection()->listBuckets();
if ($buckets->getPath('Owner/ID') === null ) {
if ($buckets->getPath('Owner/ID') === null) {
return false;
}
$bucketExists = !empty(array_filter($buckets->getPath('Buckets'), function ($k) {
$bucketExists = !empty(\array_filter($buckets->getPath('Buckets'), function ($k) {
return $k['Name'] === $this->bucket;
} ));
}));
return $bucketExists;
}

Expand All @@ -570,7 +565,6 @@ public function getConnection() {
$scheme = ($this->params['use_ssl'] === false) ? 'http' : 'https';
$base_url = $scheme . '://' . $this->params['hostname'] . ':' . $this->params['port'] . '/';


$config = [
'version' => '2006-03-01',
'region' => $this->params['region'],
Expand Down Expand Up @@ -608,7 +602,7 @@ public function getConnection() {
$this->connection->createBucket([
'Bucket' => $this->bucket
]);
$this->connection->waitUntil('BucketExists',[
$this->connection->waitUntil('BucketExists', [
'Bucket' => $this->bucket,
'waiter.interval' => 1,
'waiter.max_attempts' => 15
Expand All @@ -634,11 +628,11 @@ public function writeBack($tmpFile) {
'Key' => $this->cleanKey(self::$tmpFiles[$tmpFile]),
'SourceFile' => $tmpFile,
'ContentType' => \OC::$server->getMimeTypeDetector()->detect($tmpFile),
'ContentLength' => filesize($tmpFile)
'ContentLength' => \filesize($tmpFile)
]);
$this->testTimeout();

unlink($tmpFile);
\unlink($tmpFile);
} catch (S3Exception $e) {
\OCP\Util::logException('files_external', $e);
return false;
Expand All @@ -651,5 +645,4 @@ public function writeBack($tmpFile) {
public static function checkDependencies() {
return true;
}

}
20 changes: 10 additions & 10 deletions tests/drone/configs/config.ceph.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

return array(
'run' => true,
'bucket' => 'octesting',
'hostname' => 'ceph',
'port' => '80',
'key' => 'owncloud123456',
'secret' => 'secret123456',
'use_ssl' => false,
'use_path_style'=> true,
);
return [
'run' => true,
'bucket' => 'octesting',
'hostname' => 'ceph',
'port' => '80',
'key' => 'owncloud123456',
'secret' => 'secret123456',
'use_ssl' => false,
'use_path_style'=> true,
];
20 changes: 10 additions & 10 deletions tests/drone/configs/config.minio.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

return array(
'run' => true,
'bucket' => 'octesting',
'hostname' => 'minio',
'port' => '9000',
'key' => 'owncloud123456',
'secret' => 'secret123456',
'use_ssl' => false,
'use_path_style'=> true,
);
return [
'run' => true,
'bucket' => 'octesting',
'hostname' => 'minio',
'port' => '9000',
'key' => 'owncloud123456',
'secret' => 'secret123456',
'use_ssl' => false,
'use_path_style'=> true,
];
Loading

0 comments on commit 5610db8

Please sign in to comment.