@@ -25,16 +25,16 @@ |
||
| 25 | 25 | |
| 26 | 26 | class Exception extends \Exception { |
| 27 | 27 | |
| 28 | - /** @var Result */ |
|
| 29 | - private $result; |
|
| 28 | + /** @var Result */ |
|
| 29 | + private $result; |
|
| 30 | 30 | |
| 31 | - public function __construct(Result $result) { |
|
| 32 | - parent::__construct(); |
|
| 33 | - $this->result = $result; |
|
| 34 | - } |
|
| 31 | + public function __construct(Result $result) { |
|
| 32 | + parent::__construct(); |
|
| 33 | + $this->result = $result; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - public function getResult() { |
|
| 37 | - return $this->result; |
|
| 38 | - } |
|
| 36 | + public function getResult() { |
|
| 37 | + return $this->result; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | 40 | } |
@@ -32,85 +32,85 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | class File extends \OCP\Search\Result { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Type name; translated in templates |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - public $type = 'file'; |
|
| 35 | + /** |
|
| 36 | + * Type name; translated in templates |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + public $type = 'file'; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Path to file |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - public $path; |
|
| 41 | + /** |
|
| 42 | + * Path to file |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + public $path; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Size, in bytes |
|
| 49 | - * @var int |
|
| 50 | - */ |
|
| 51 | - public $size; |
|
| 47 | + /** |
|
| 48 | + * Size, in bytes |
|
| 49 | + * @var int |
|
| 50 | + */ |
|
| 51 | + public $size; |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Date modified, in human readable form |
|
| 55 | - * @var string |
|
| 56 | - */ |
|
| 57 | - public $modified; |
|
| 53 | + /** |
|
| 54 | + * Date modified, in human readable form |
|
| 55 | + * @var string |
|
| 56 | + */ |
|
| 57 | + public $modified; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * File mime type |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 63 | - public $mime_type; |
|
| 59 | + /** |
|
| 60 | + * File mime type |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | + public $mime_type; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * File permissions: |
|
| 67 | - * |
|
| 68 | - * @var string |
|
| 69 | - */ |
|
| 70 | - public $permissions; |
|
| 65 | + /** |
|
| 66 | + * File permissions: |
|
| 67 | + * |
|
| 68 | + * @var string |
|
| 69 | + */ |
|
| 70 | + public $permissions; |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Create a new file search result |
|
| 74 | - * @param FileInfo $data file data given by provider |
|
| 75 | - */ |
|
| 76 | - public function __construct(FileInfo $data) { |
|
| 72 | + /** |
|
| 73 | + * Create a new file search result |
|
| 74 | + * @param FileInfo $data file data given by provider |
|
| 75 | + */ |
|
| 76 | + public function __construct(FileInfo $data) { |
|
| 77 | 77 | |
| 78 | - $path = $this->getRelativePath($data->getPath()); |
|
| 78 | + $path = $this->getRelativePath($data->getPath()); |
|
| 79 | 79 | |
| 80 | - $info = pathinfo($path); |
|
| 81 | - $this->id = $data->getId(); |
|
| 82 | - $this->name = $info['basename']; |
|
| 83 | - $this->link = \OC::$server->getURLGenerator()->linkToRoute( |
|
| 84 | - 'files.view.index', |
|
| 85 | - [ |
|
| 86 | - 'dir' => $info['dirname'], |
|
| 87 | - 'scrollto' => $info['basename'], |
|
| 88 | - ] |
|
| 89 | - ); |
|
| 90 | - $this->permissions = $data->getPermissions(); |
|
| 91 | - $this->path = $path; |
|
| 92 | - $this->size = $data->getSize(); |
|
| 93 | - $this->modified = $data->getMtime(); |
|
| 94 | - $this->mime_type = $data->getMimetype(); |
|
| 95 | - } |
|
| 80 | + $info = pathinfo($path); |
|
| 81 | + $this->id = $data->getId(); |
|
| 82 | + $this->name = $info['basename']; |
|
| 83 | + $this->link = \OC::$server->getURLGenerator()->linkToRoute( |
|
| 84 | + 'files.view.index', |
|
| 85 | + [ |
|
| 86 | + 'dir' => $info['dirname'], |
|
| 87 | + 'scrollto' => $info['basename'], |
|
| 88 | + ] |
|
| 89 | + ); |
|
| 90 | + $this->permissions = $data->getPermissions(); |
|
| 91 | + $this->path = $path; |
|
| 92 | + $this->size = $data->getSize(); |
|
| 93 | + $this->modified = $data->getMtime(); |
|
| 94 | + $this->mime_type = $data->getMimetype(); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * @var Folder $userFolderCache |
|
| 99 | - */ |
|
| 100 | - static protected $userFolderCache = null; |
|
| 97 | + /** |
|
| 98 | + * @var Folder $userFolderCache |
|
| 99 | + */ |
|
| 100 | + static protected $userFolderCache = null; |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * converts a path relative to the users files folder |
|
| 104 | - * eg /user/files/foo.txt -> /foo.txt |
|
| 105 | - * @param string $path |
|
| 106 | - * @return string relative path |
|
| 107 | - */ |
|
| 108 | - protected function getRelativePath ($path) { |
|
| 109 | - if (!isset(self::$userFolderCache)) { |
|
| 110 | - $user = \OC::$server->getUserSession()->getUser()->getUID(); |
|
| 111 | - self::$userFolderCache = \OC::$server->getUserFolder($user); |
|
| 112 | - } |
|
| 113 | - return self::$userFolderCache->getRelativePath($path); |
|
| 114 | - } |
|
| 102 | + /** |
|
| 103 | + * converts a path relative to the users files folder |
|
| 104 | + * eg /user/files/foo.txt -> /foo.txt |
|
| 105 | + * @param string $path |
|
| 106 | + * @return string relative path |
|
| 107 | + */ |
|
| 108 | + protected function getRelativePath ($path) { |
|
| 109 | + if (!isset(self::$userFolderCache)) { |
|
| 110 | + $user = \OC::$server->getUserSession()->getUser()->getUID(); |
|
| 111 | + self::$userFolderCache = \OC::$server->getUserFolder($user); |
|
| 112 | + } |
|
| 113 | + return self::$userFolderCache->getRelativePath($path); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | 116 | } |
@@ -32,26 +32,26 @@ |
||
| 32 | 32 | * @package OC\BackgroundJob |
| 33 | 33 | */ |
| 34 | 34 | abstract class TimedJob extends Job { |
| 35 | - protected $interval = 0; |
|
| 35 | + protected $interval = 0; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * set the interval for the job |
|
| 39 | - * |
|
| 40 | - * @param int $interval |
|
| 41 | - */ |
|
| 42 | - public function setInterval($interval) { |
|
| 43 | - $this->interval = $interval; |
|
| 44 | - } |
|
| 37 | + /** |
|
| 38 | + * set the interval for the job |
|
| 39 | + * |
|
| 40 | + * @param int $interval |
|
| 41 | + */ |
|
| 42 | + public function setInterval($interval) { |
|
| 43 | + $this->interval = $interval; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * run the job if |
|
| 48 | - * |
|
| 49 | - * @param JobList $jobList |
|
| 50 | - * @param ILogger|null $logger |
|
| 51 | - */ |
|
| 52 | - public function execute($jobList, ILogger $logger = null) { |
|
| 53 | - if ((time() - $this->lastRun) > $this->interval) { |
|
| 54 | - parent::execute($jobList, $logger); |
|
| 55 | - } |
|
| 56 | - } |
|
| 46 | + /** |
|
| 47 | + * run the job if |
|
| 48 | + * |
|
| 49 | + * @param JobList $jobList |
|
| 50 | + * @param ILogger|null $logger |
|
| 51 | + */ |
|
| 52 | + public function execute($jobList, ILogger $logger = null) { |
|
| 53 | + if ((time() - $this->lastRun) > $this->interval) { |
|
| 54 | + parent::execute($jobList, $logger); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -28,72 +28,72 @@ |
||
| 28 | 28 | use OCP\ILogger; |
| 29 | 29 | |
| 30 | 30 | abstract class Job implements IJob { |
| 31 | - /** |
|
| 32 | - * @var int $id |
|
| 33 | - */ |
|
| 34 | - protected $id; |
|
| 31 | + /** |
|
| 32 | + * @var int $id |
|
| 33 | + */ |
|
| 34 | + protected $id; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var int $lastRun |
|
| 38 | - */ |
|
| 39 | - protected $lastRun; |
|
| 36 | + /** |
|
| 37 | + * @var int $lastRun |
|
| 38 | + */ |
|
| 39 | + protected $lastRun; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var mixed $argument |
|
| 43 | - */ |
|
| 44 | - protected $argument; |
|
| 41 | + /** |
|
| 42 | + * @var mixed $argument |
|
| 43 | + */ |
|
| 44 | + protected $argument; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @param JobList $jobList |
|
| 48 | - * @param ILogger|null $logger |
|
| 49 | - */ |
|
| 50 | - public function execute($jobList, ILogger $logger = null) { |
|
| 51 | - $jobList->setLastRun($this); |
|
| 52 | - if ($logger === null) { |
|
| 53 | - $logger = \OC::$server->getLogger(); |
|
| 54 | - } |
|
| 46 | + /** |
|
| 47 | + * @param JobList $jobList |
|
| 48 | + * @param ILogger|null $logger |
|
| 49 | + */ |
|
| 50 | + public function execute($jobList, ILogger $logger = null) { |
|
| 51 | + $jobList->setLastRun($this); |
|
| 52 | + if ($logger === null) { |
|
| 53 | + $logger = \OC::$server->getLogger(); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - try { |
|
| 57 | - $jobStartTime = time(); |
|
| 58 | - $logger->debug('Run ' . get_class($this) . ' job with ID ' . $this->getId(), ['app' => 'cron']); |
|
| 59 | - $this->run($this->argument); |
|
| 60 | - $timeTaken = time() - $jobStartTime; |
|
| 56 | + try { |
|
| 57 | + $jobStartTime = time(); |
|
| 58 | + $logger->debug('Run ' . get_class($this) . ' job with ID ' . $this->getId(), ['app' => 'cron']); |
|
| 59 | + $this->run($this->argument); |
|
| 60 | + $timeTaken = time() - $jobStartTime; |
|
| 61 | 61 | |
| 62 | - $logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']); |
|
| 63 | - $jobList->setExecutionTime($this, $timeTaken); |
|
| 64 | - } catch (\Exception $e) { |
|
| 65 | - if ($logger) { |
|
| 66 | - $logger->logException($e, [ |
|
| 67 | - 'app' => 'core', |
|
| 68 | - 'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')' |
|
| 69 | - ]); |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - } |
|
| 62 | + $logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']); |
|
| 63 | + $jobList->setExecutionTime($this, $timeTaken); |
|
| 64 | + } catch (\Exception $e) { |
|
| 65 | + if ($logger) { |
|
| 66 | + $logger->logException($e, [ |
|
| 67 | + 'app' => 'core', |
|
| 68 | + 'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')' |
|
| 69 | + ]); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - abstract protected function run($argument); |
|
| 74 | + abstract protected function run($argument); |
|
| 75 | 75 | |
| 76 | - public function setId($id) { |
|
| 77 | - $this->id = $id; |
|
| 78 | - } |
|
| 76 | + public function setId($id) { |
|
| 77 | + $this->id = $id; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - public function setLastRun($lastRun) { |
|
| 81 | - $this->lastRun = $lastRun; |
|
| 82 | - } |
|
| 80 | + public function setLastRun($lastRun) { |
|
| 81 | + $this->lastRun = $lastRun; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - public function setArgument($argument) { |
|
| 85 | - $this->argument = $argument; |
|
| 86 | - } |
|
| 84 | + public function setArgument($argument) { |
|
| 85 | + $this->argument = $argument; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - public function getId() { |
|
| 89 | - return $this->id; |
|
| 90 | - } |
|
| 88 | + public function getId() { |
|
| 89 | + return $this->id; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - public function getLastRun() { |
|
| 93 | - return $this->lastRun; |
|
| 94 | - } |
|
| 92 | + public function getLastRun() { |
|
| 93 | + return $this->lastRun; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - public function getArgument() { |
|
| 97 | - return $this->argument; |
|
| 98 | - } |
|
| 96 | + public function getArgument() { |
|
| 97 | + return $this->argument; |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -32,14 +32,14 @@ |
||
| 32 | 32 | * @package OC\BackgroundJob |
| 33 | 33 | */ |
| 34 | 34 | abstract class QueuedJob extends Job { |
| 35 | - /** |
|
| 36 | - * run the job, then remove it from the joblist |
|
| 37 | - * |
|
| 38 | - * @param JobList $jobList |
|
| 39 | - * @param ILogger|null $logger |
|
| 40 | - */ |
|
| 41 | - public function execute($jobList, ILogger $logger = null) { |
|
| 42 | - $jobList->remove($this, $this->argument); |
|
| 43 | - parent::execute($jobList, $logger); |
|
| 44 | - } |
|
| 35 | + /** |
|
| 36 | + * run the job, then remove it from the joblist |
|
| 37 | + * |
|
| 38 | + * @param JobList $jobList |
|
| 39 | + * @param ILogger|null $logger |
|
| 40 | + */ |
|
| 41 | + public function execute($jobList, ILogger $logger = null) { |
|
| 42 | + $jobList->remove($this, $this->argument); |
|
| 43 | + parent::execute($jobList, $logger); |
|
| 44 | + } |
|
| 45 | 45 | } |
@@ -34,502 +34,502 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class Encoding extends Wrapper { |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var ICache |
|
| 39 | - */ |
|
| 40 | - private $namesCache; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @param array $parameters |
|
| 44 | - */ |
|
| 45 | - public function __construct($parameters) { |
|
| 46 | - $this->storage = $parameters['storage']; |
|
| 47 | - $this->namesCache = new CappedMemoryCache(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Returns whether the given string is only made of ASCII characters |
|
| 52 | - * |
|
| 53 | - * @param string $str string |
|
| 54 | - * |
|
| 55 | - * @return bool true if the string is all ASCII, false otherwise |
|
| 56 | - */ |
|
| 57 | - private function isAscii($str) { |
|
| 58 | - return (bool) !preg_match('/[\\x80-\\xff]+/', $str); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Checks whether the given path exists in NFC or NFD form after checking |
|
| 63 | - * each form for each path section and returns the correct form. |
|
| 64 | - * If no existing path found, returns the path as it was given. |
|
| 65 | - * |
|
| 66 | - * @param string $fullPath path to check |
|
| 67 | - * |
|
| 68 | - * @return string original or converted path |
|
| 69 | - */ |
|
| 70 | - private function findPathToUse($fullPath) { |
|
| 71 | - $cachedPath = $this->namesCache[$fullPath]; |
|
| 72 | - if ($cachedPath !== null) { |
|
| 73 | - return $cachedPath; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - $sections = explode('/', $fullPath); |
|
| 77 | - $path = ''; |
|
| 78 | - foreach ($sections as $section) { |
|
| 79 | - $convertedPath = $this->findPathToUseLastSection($path, $section); |
|
| 80 | - if ($convertedPath === null) { |
|
| 81 | - // no point in continuing if the section was not found, use original path |
|
| 82 | - return $fullPath; |
|
| 83 | - } |
|
| 84 | - $path = $convertedPath . '/'; |
|
| 85 | - } |
|
| 86 | - $path = rtrim($path, '/'); |
|
| 87 | - return $path; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Checks whether the last path section of the given path exists in NFC or NFD form |
|
| 92 | - * and returns the correct form. If no existing path found, returns null. |
|
| 93 | - * |
|
| 94 | - * @param string $basePath base path to check |
|
| 95 | - * @param string $lastSection last section of the path to check for NFD/NFC variations |
|
| 96 | - * |
|
| 97 | - * @return string|null original or converted path, or null if none of the forms was found |
|
| 98 | - */ |
|
| 99 | - private function findPathToUseLastSection($basePath, $lastSection) { |
|
| 100 | - $fullPath = $basePath . $lastSection; |
|
| 101 | - if ($lastSection === '' || $this->isAscii($lastSection) || $this->storage->file_exists($fullPath)) { |
|
| 102 | - $this->namesCache[$fullPath] = $fullPath; |
|
| 103 | - return $fullPath; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // swap encoding |
|
| 107 | - if (\Normalizer::isNormalized($lastSection, \Normalizer::FORM_C)) { |
|
| 108 | - $otherFormPath = \Normalizer::normalize($lastSection, \Normalizer::FORM_D); |
|
| 109 | - } else { |
|
| 110 | - $otherFormPath = \Normalizer::normalize($lastSection, \Normalizer::FORM_C); |
|
| 111 | - } |
|
| 112 | - $otherFullPath = $basePath . $otherFormPath; |
|
| 113 | - if ($this->storage->file_exists($otherFullPath)) { |
|
| 114 | - $this->namesCache[$fullPath] = $otherFullPath; |
|
| 115 | - return $otherFullPath; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // return original path, file did not exist at all |
|
| 119 | - $this->namesCache[$fullPath] = $fullPath; |
|
| 120 | - return null; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * see http://php.net/manual/en/function.mkdir.php |
|
| 125 | - * |
|
| 126 | - * @param string $path |
|
| 127 | - * @return bool |
|
| 128 | - */ |
|
| 129 | - public function mkdir($path) { |
|
| 130 | - // note: no conversion here, method should not be called with non-NFC names! |
|
| 131 | - $result = $this->storage->mkdir($path); |
|
| 132 | - if ($result) { |
|
| 133 | - $this->namesCache[$path] = $path; |
|
| 134 | - } |
|
| 135 | - return $result; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * see http://php.net/manual/en/function.rmdir.php |
|
| 140 | - * |
|
| 141 | - * @param string $path |
|
| 142 | - * @return bool |
|
| 143 | - */ |
|
| 144 | - public function rmdir($path) { |
|
| 145 | - $result = $this->storage->rmdir($this->findPathToUse($path)); |
|
| 146 | - if ($result) { |
|
| 147 | - unset($this->namesCache[$path]); |
|
| 148 | - } |
|
| 149 | - return $result; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * see http://php.net/manual/en/function.opendir.php |
|
| 154 | - * |
|
| 155 | - * @param string $path |
|
| 156 | - * @return resource |
|
| 157 | - */ |
|
| 158 | - public function opendir($path) { |
|
| 159 | - return $this->storage->opendir($this->findPathToUse($path)); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * see http://php.net/manual/en/function.is_dir.php |
|
| 164 | - * |
|
| 165 | - * @param string $path |
|
| 166 | - * @return bool |
|
| 167 | - */ |
|
| 168 | - public function is_dir($path) { |
|
| 169 | - return $this->storage->is_dir($this->findPathToUse($path)); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * see http://php.net/manual/en/function.is_file.php |
|
| 174 | - * |
|
| 175 | - * @param string $path |
|
| 176 | - * @return bool |
|
| 177 | - */ |
|
| 178 | - public function is_file($path) { |
|
| 179 | - return $this->storage->is_file($this->findPathToUse($path)); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * see http://php.net/manual/en/function.stat.php |
|
| 184 | - * only the following keys are required in the result: size and mtime |
|
| 185 | - * |
|
| 186 | - * @param string $path |
|
| 187 | - * @return array |
|
| 188 | - */ |
|
| 189 | - public function stat($path) { |
|
| 190 | - return $this->storage->stat($this->findPathToUse($path)); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * see http://php.net/manual/en/function.filetype.php |
|
| 195 | - * |
|
| 196 | - * @param string $path |
|
| 197 | - * @return bool |
|
| 198 | - */ |
|
| 199 | - public function filetype($path) { |
|
| 200 | - return $this->storage->filetype($this->findPathToUse($path)); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * see http://php.net/manual/en/function.filesize.php |
|
| 205 | - * The result for filesize when called on a folder is required to be 0 |
|
| 206 | - * |
|
| 207 | - * @param string $path |
|
| 208 | - * @return int |
|
| 209 | - */ |
|
| 210 | - public function filesize($path) { |
|
| 211 | - return $this->storage->filesize($this->findPathToUse($path)); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * check if a file can be created in $path |
|
| 216 | - * |
|
| 217 | - * @param string $path |
|
| 218 | - * @return bool |
|
| 219 | - */ |
|
| 220 | - public function isCreatable($path) { |
|
| 221 | - return $this->storage->isCreatable($this->findPathToUse($path)); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * check if a file can be read |
|
| 226 | - * |
|
| 227 | - * @param string $path |
|
| 228 | - * @return bool |
|
| 229 | - */ |
|
| 230 | - public function isReadable($path) { |
|
| 231 | - return $this->storage->isReadable($this->findPathToUse($path)); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * check if a file can be written to |
|
| 236 | - * |
|
| 237 | - * @param string $path |
|
| 238 | - * @return bool |
|
| 239 | - */ |
|
| 240 | - public function isUpdatable($path) { |
|
| 241 | - return $this->storage->isUpdatable($this->findPathToUse($path)); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * check if a file can be deleted |
|
| 246 | - * |
|
| 247 | - * @param string $path |
|
| 248 | - * @return bool |
|
| 249 | - */ |
|
| 250 | - public function isDeletable($path) { |
|
| 251 | - return $this->storage->isDeletable($this->findPathToUse($path)); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * check if a file can be shared |
|
| 256 | - * |
|
| 257 | - * @param string $path |
|
| 258 | - * @return bool |
|
| 259 | - */ |
|
| 260 | - public function isSharable($path) { |
|
| 261 | - return $this->storage->isSharable($this->findPathToUse($path)); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * get the full permissions of a path. |
|
| 266 | - * Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php |
|
| 267 | - * |
|
| 268 | - * @param string $path |
|
| 269 | - * @return int |
|
| 270 | - */ |
|
| 271 | - public function getPermissions($path) { |
|
| 272 | - return $this->storage->getPermissions($this->findPathToUse($path)); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * see http://php.net/manual/en/function.file_exists.php |
|
| 277 | - * |
|
| 278 | - * @param string $path |
|
| 279 | - * @return bool |
|
| 280 | - */ |
|
| 281 | - public function file_exists($path) { |
|
| 282 | - return $this->storage->file_exists($this->findPathToUse($path)); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * see http://php.net/manual/en/function.filemtime.php |
|
| 287 | - * |
|
| 288 | - * @param string $path |
|
| 289 | - * @return int |
|
| 290 | - */ |
|
| 291 | - public function filemtime($path) { |
|
| 292 | - return $this->storage->filemtime($this->findPathToUse($path)); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * see http://php.net/manual/en/function.file_get_contents.php |
|
| 297 | - * |
|
| 298 | - * @param string $path |
|
| 299 | - * @return string |
|
| 300 | - */ |
|
| 301 | - public function file_get_contents($path) { |
|
| 302 | - return $this->storage->file_get_contents($this->findPathToUse($path)); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * see http://php.net/manual/en/function.file_put_contents.php |
|
| 307 | - * |
|
| 308 | - * @param string $path |
|
| 309 | - * @param string $data |
|
| 310 | - * @return bool |
|
| 311 | - */ |
|
| 312 | - public function file_put_contents($path, $data) { |
|
| 313 | - return $this->storage->file_put_contents($this->findPathToUse($path), $data); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * see http://php.net/manual/en/function.unlink.php |
|
| 318 | - * |
|
| 319 | - * @param string $path |
|
| 320 | - * @return bool |
|
| 321 | - */ |
|
| 322 | - public function unlink($path) { |
|
| 323 | - $result = $this->storage->unlink($this->findPathToUse($path)); |
|
| 324 | - if ($result) { |
|
| 325 | - unset($this->namesCache[$path]); |
|
| 326 | - } |
|
| 327 | - return $result; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * see http://php.net/manual/en/function.rename.php |
|
| 332 | - * |
|
| 333 | - * @param string $path1 |
|
| 334 | - * @param string $path2 |
|
| 335 | - * @return bool |
|
| 336 | - */ |
|
| 337 | - public function rename($path1, $path2) { |
|
| 338 | - // second name always NFC |
|
| 339 | - return $this->storage->rename($this->findPathToUse($path1), $this->findPathToUse($path2)); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * see http://php.net/manual/en/function.copy.php |
|
| 344 | - * |
|
| 345 | - * @param string $path1 |
|
| 346 | - * @param string $path2 |
|
| 347 | - * @return bool |
|
| 348 | - */ |
|
| 349 | - public function copy($path1, $path2) { |
|
| 350 | - return $this->storage->copy($this->findPathToUse($path1), $this->findPathToUse($path2)); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * see http://php.net/manual/en/function.fopen.php |
|
| 355 | - * |
|
| 356 | - * @param string $path |
|
| 357 | - * @param string $mode |
|
| 358 | - * @return resource |
|
| 359 | - */ |
|
| 360 | - public function fopen($path, $mode) { |
|
| 361 | - $result = $this->storage->fopen($this->findPathToUse($path), $mode); |
|
| 362 | - if ($result && $mode !== 'r' && $mode !== 'rb') { |
|
| 363 | - unset($this->namesCache[$path]); |
|
| 364 | - } |
|
| 365 | - return $result; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * get the mimetype for a file or folder |
|
| 370 | - * The mimetype for a folder is required to be "httpd/unix-directory" |
|
| 371 | - * |
|
| 372 | - * @param string $path |
|
| 373 | - * @return string |
|
| 374 | - */ |
|
| 375 | - public function getMimeType($path) { |
|
| 376 | - return $this->storage->getMimeType($this->findPathToUse($path)); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * see http://php.net/manual/en/function.hash.php |
|
| 381 | - * |
|
| 382 | - * @param string $type |
|
| 383 | - * @param string $path |
|
| 384 | - * @param bool $raw |
|
| 385 | - * @return string |
|
| 386 | - */ |
|
| 387 | - public function hash($type, $path, $raw = false) { |
|
| 388 | - return $this->storage->hash($type, $this->findPathToUse($path), $raw); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * see http://php.net/manual/en/function.free_space.php |
|
| 393 | - * |
|
| 394 | - * @param string $path |
|
| 395 | - * @return int |
|
| 396 | - */ |
|
| 397 | - public function free_space($path) { |
|
| 398 | - return $this->storage->free_space($this->findPathToUse($path)); |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * search for occurrences of $query in file names |
|
| 403 | - * |
|
| 404 | - * @param string $query |
|
| 405 | - * @return array |
|
| 406 | - */ |
|
| 407 | - public function search($query) { |
|
| 408 | - return $this->storage->search($query); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * see http://php.net/manual/en/function.touch.php |
|
| 413 | - * If the backend does not support the operation, false should be returned |
|
| 414 | - * |
|
| 415 | - * @param string $path |
|
| 416 | - * @param int $mtime |
|
| 417 | - * @return bool |
|
| 418 | - */ |
|
| 419 | - public function touch($path, $mtime = null) { |
|
| 420 | - return $this->storage->touch($this->findPathToUse($path), $mtime); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * get the path to a local version of the file. |
|
| 425 | - * The local version of the file can be temporary and doesn't have to be persistent across requests |
|
| 426 | - * |
|
| 427 | - * @param string $path |
|
| 428 | - * @return string |
|
| 429 | - */ |
|
| 430 | - public function getLocalFile($path) { |
|
| 431 | - return $this->storage->getLocalFile($this->findPathToUse($path)); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * check if a file or folder has been updated since $time |
|
| 436 | - * |
|
| 437 | - * @param string $path |
|
| 438 | - * @param int $time |
|
| 439 | - * @return bool |
|
| 440 | - * |
|
| 441 | - * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed. |
|
| 442 | - * returning true for other changes in the folder is optional |
|
| 443 | - */ |
|
| 444 | - public function hasUpdated($path, $time) { |
|
| 445 | - return $this->storage->hasUpdated($this->findPathToUse($path), $time); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * get a cache instance for the storage |
|
| 450 | - * |
|
| 451 | - * @param string $path |
|
| 452 | - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache |
|
| 453 | - * @return \OC\Files\Cache\Cache |
|
| 454 | - */ |
|
| 455 | - public function getCache($path = '', $storage = null) { |
|
| 456 | - if (!$storage) { |
|
| 457 | - $storage = $this; |
|
| 458 | - } |
|
| 459 | - return $this->storage->getCache($this->findPathToUse($path), $storage); |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * get a scanner instance for the storage |
|
| 464 | - * |
|
| 465 | - * @param string $path |
|
| 466 | - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the scanner |
|
| 467 | - * @return \OC\Files\Cache\Scanner |
|
| 468 | - */ |
|
| 469 | - public function getScanner($path = '', $storage = null) { |
|
| 470 | - if (!$storage) { |
|
| 471 | - $storage = $this; |
|
| 472 | - } |
|
| 473 | - return $this->storage->getScanner($this->findPathToUse($path), $storage); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - /** |
|
| 477 | - * get the ETag for a file or folder |
|
| 478 | - * |
|
| 479 | - * @param string $path |
|
| 480 | - * @return string |
|
| 481 | - */ |
|
| 482 | - public function getETag($path) { |
|
| 483 | - return $this->storage->getETag($this->findPathToUse($path)); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * @param IStorage $sourceStorage |
|
| 488 | - * @param string $sourceInternalPath |
|
| 489 | - * @param string $targetInternalPath |
|
| 490 | - * @return bool |
|
| 491 | - */ |
|
| 492 | - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|
| 493 | - if ($sourceStorage === $this) { |
|
| 494 | - return $this->copy($sourceInternalPath, $this->findPathToUse($targetInternalPath)); |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - $result = $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $this->findPathToUse($targetInternalPath)); |
|
| 498 | - if ($result) { |
|
| 499 | - unset($this->namesCache[$targetInternalPath]); |
|
| 500 | - } |
|
| 501 | - return $result; |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * @param IStorage $sourceStorage |
|
| 506 | - * @param string $sourceInternalPath |
|
| 507 | - * @param string $targetInternalPath |
|
| 508 | - * @return bool |
|
| 509 | - */ |
|
| 510 | - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|
| 511 | - if ($sourceStorage === $this) { |
|
| 512 | - $result = $this->rename($sourceInternalPath, $this->findPathToUse($targetInternalPath)); |
|
| 513 | - if ($result) { |
|
| 514 | - unset($this->namesCache[$sourceInternalPath]); |
|
| 515 | - unset($this->namesCache[$targetInternalPath]); |
|
| 516 | - } |
|
| 517 | - return $result; |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - $result = $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $this->findPathToUse($targetInternalPath)); |
|
| 521 | - if ($result) { |
|
| 522 | - unset($this->namesCache[$sourceInternalPath]); |
|
| 523 | - unset($this->namesCache[$targetInternalPath]); |
|
| 524 | - } |
|
| 525 | - return $result; |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * @param string $path |
|
| 530 | - * @return array |
|
| 531 | - */ |
|
| 532 | - public function getMetaData($path) { |
|
| 533 | - return $this->storage->getMetaData($this->findPathToUse($path)); |
|
| 534 | - } |
|
| 37 | + /** |
|
| 38 | + * @var ICache |
|
| 39 | + */ |
|
| 40 | + private $namesCache; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @param array $parameters |
|
| 44 | + */ |
|
| 45 | + public function __construct($parameters) { |
|
| 46 | + $this->storage = $parameters['storage']; |
|
| 47 | + $this->namesCache = new CappedMemoryCache(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Returns whether the given string is only made of ASCII characters |
|
| 52 | + * |
|
| 53 | + * @param string $str string |
|
| 54 | + * |
|
| 55 | + * @return bool true if the string is all ASCII, false otherwise |
|
| 56 | + */ |
|
| 57 | + private function isAscii($str) { |
|
| 58 | + return (bool) !preg_match('/[\\x80-\\xff]+/', $str); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Checks whether the given path exists in NFC or NFD form after checking |
|
| 63 | + * each form for each path section and returns the correct form. |
|
| 64 | + * If no existing path found, returns the path as it was given. |
|
| 65 | + * |
|
| 66 | + * @param string $fullPath path to check |
|
| 67 | + * |
|
| 68 | + * @return string original or converted path |
|
| 69 | + */ |
|
| 70 | + private function findPathToUse($fullPath) { |
|
| 71 | + $cachedPath = $this->namesCache[$fullPath]; |
|
| 72 | + if ($cachedPath !== null) { |
|
| 73 | + return $cachedPath; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + $sections = explode('/', $fullPath); |
|
| 77 | + $path = ''; |
|
| 78 | + foreach ($sections as $section) { |
|
| 79 | + $convertedPath = $this->findPathToUseLastSection($path, $section); |
|
| 80 | + if ($convertedPath === null) { |
|
| 81 | + // no point in continuing if the section was not found, use original path |
|
| 82 | + return $fullPath; |
|
| 83 | + } |
|
| 84 | + $path = $convertedPath . '/'; |
|
| 85 | + } |
|
| 86 | + $path = rtrim($path, '/'); |
|
| 87 | + return $path; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Checks whether the last path section of the given path exists in NFC or NFD form |
|
| 92 | + * and returns the correct form. If no existing path found, returns null. |
|
| 93 | + * |
|
| 94 | + * @param string $basePath base path to check |
|
| 95 | + * @param string $lastSection last section of the path to check for NFD/NFC variations |
|
| 96 | + * |
|
| 97 | + * @return string|null original or converted path, or null if none of the forms was found |
|
| 98 | + */ |
|
| 99 | + private function findPathToUseLastSection($basePath, $lastSection) { |
|
| 100 | + $fullPath = $basePath . $lastSection; |
|
| 101 | + if ($lastSection === '' || $this->isAscii($lastSection) || $this->storage->file_exists($fullPath)) { |
|
| 102 | + $this->namesCache[$fullPath] = $fullPath; |
|
| 103 | + return $fullPath; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // swap encoding |
|
| 107 | + if (\Normalizer::isNormalized($lastSection, \Normalizer::FORM_C)) { |
|
| 108 | + $otherFormPath = \Normalizer::normalize($lastSection, \Normalizer::FORM_D); |
|
| 109 | + } else { |
|
| 110 | + $otherFormPath = \Normalizer::normalize($lastSection, \Normalizer::FORM_C); |
|
| 111 | + } |
|
| 112 | + $otherFullPath = $basePath . $otherFormPath; |
|
| 113 | + if ($this->storage->file_exists($otherFullPath)) { |
|
| 114 | + $this->namesCache[$fullPath] = $otherFullPath; |
|
| 115 | + return $otherFullPath; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // return original path, file did not exist at all |
|
| 119 | + $this->namesCache[$fullPath] = $fullPath; |
|
| 120 | + return null; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * see http://php.net/manual/en/function.mkdir.php |
|
| 125 | + * |
|
| 126 | + * @param string $path |
|
| 127 | + * @return bool |
|
| 128 | + */ |
|
| 129 | + public function mkdir($path) { |
|
| 130 | + // note: no conversion here, method should not be called with non-NFC names! |
|
| 131 | + $result = $this->storage->mkdir($path); |
|
| 132 | + if ($result) { |
|
| 133 | + $this->namesCache[$path] = $path; |
|
| 134 | + } |
|
| 135 | + return $result; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * see http://php.net/manual/en/function.rmdir.php |
|
| 140 | + * |
|
| 141 | + * @param string $path |
|
| 142 | + * @return bool |
|
| 143 | + */ |
|
| 144 | + public function rmdir($path) { |
|
| 145 | + $result = $this->storage->rmdir($this->findPathToUse($path)); |
|
| 146 | + if ($result) { |
|
| 147 | + unset($this->namesCache[$path]); |
|
| 148 | + } |
|
| 149 | + return $result; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * see http://php.net/manual/en/function.opendir.php |
|
| 154 | + * |
|
| 155 | + * @param string $path |
|
| 156 | + * @return resource |
|
| 157 | + */ |
|
| 158 | + public function opendir($path) { |
|
| 159 | + return $this->storage->opendir($this->findPathToUse($path)); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * see http://php.net/manual/en/function.is_dir.php |
|
| 164 | + * |
|
| 165 | + * @param string $path |
|
| 166 | + * @return bool |
|
| 167 | + */ |
|
| 168 | + public function is_dir($path) { |
|
| 169 | + return $this->storage->is_dir($this->findPathToUse($path)); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * see http://php.net/manual/en/function.is_file.php |
|
| 174 | + * |
|
| 175 | + * @param string $path |
|
| 176 | + * @return bool |
|
| 177 | + */ |
|
| 178 | + public function is_file($path) { |
|
| 179 | + return $this->storage->is_file($this->findPathToUse($path)); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * see http://php.net/manual/en/function.stat.php |
|
| 184 | + * only the following keys are required in the result: size and mtime |
|
| 185 | + * |
|
| 186 | + * @param string $path |
|
| 187 | + * @return array |
|
| 188 | + */ |
|
| 189 | + public function stat($path) { |
|
| 190 | + return $this->storage->stat($this->findPathToUse($path)); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * see http://php.net/manual/en/function.filetype.php |
|
| 195 | + * |
|
| 196 | + * @param string $path |
|
| 197 | + * @return bool |
|
| 198 | + */ |
|
| 199 | + public function filetype($path) { |
|
| 200 | + return $this->storage->filetype($this->findPathToUse($path)); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * see http://php.net/manual/en/function.filesize.php |
|
| 205 | + * The result for filesize when called on a folder is required to be 0 |
|
| 206 | + * |
|
| 207 | + * @param string $path |
|
| 208 | + * @return int |
|
| 209 | + */ |
|
| 210 | + public function filesize($path) { |
|
| 211 | + return $this->storage->filesize($this->findPathToUse($path)); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * check if a file can be created in $path |
|
| 216 | + * |
|
| 217 | + * @param string $path |
|
| 218 | + * @return bool |
|
| 219 | + */ |
|
| 220 | + public function isCreatable($path) { |
|
| 221 | + return $this->storage->isCreatable($this->findPathToUse($path)); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * check if a file can be read |
|
| 226 | + * |
|
| 227 | + * @param string $path |
|
| 228 | + * @return bool |
|
| 229 | + */ |
|
| 230 | + public function isReadable($path) { |
|
| 231 | + return $this->storage->isReadable($this->findPathToUse($path)); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * check if a file can be written to |
|
| 236 | + * |
|
| 237 | + * @param string $path |
|
| 238 | + * @return bool |
|
| 239 | + */ |
|
| 240 | + public function isUpdatable($path) { |
|
| 241 | + return $this->storage->isUpdatable($this->findPathToUse($path)); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * check if a file can be deleted |
|
| 246 | + * |
|
| 247 | + * @param string $path |
|
| 248 | + * @return bool |
|
| 249 | + */ |
|
| 250 | + public function isDeletable($path) { |
|
| 251 | + return $this->storage->isDeletable($this->findPathToUse($path)); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * check if a file can be shared |
|
| 256 | + * |
|
| 257 | + * @param string $path |
|
| 258 | + * @return bool |
|
| 259 | + */ |
|
| 260 | + public function isSharable($path) { |
|
| 261 | + return $this->storage->isSharable($this->findPathToUse($path)); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * get the full permissions of a path. |
|
| 266 | + * Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php |
|
| 267 | + * |
|
| 268 | + * @param string $path |
|
| 269 | + * @return int |
|
| 270 | + */ |
|
| 271 | + public function getPermissions($path) { |
|
| 272 | + return $this->storage->getPermissions($this->findPathToUse($path)); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * see http://php.net/manual/en/function.file_exists.php |
|
| 277 | + * |
|
| 278 | + * @param string $path |
|
| 279 | + * @return bool |
|
| 280 | + */ |
|
| 281 | + public function file_exists($path) { |
|
| 282 | + return $this->storage->file_exists($this->findPathToUse($path)); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * see http://php.net/manual/en/function.filemtime.php |
|
| 287 | + * |
|
| 288 | + * @param string $path |
|
| 289 | + * @return int |
|
| 290 | + */ |
|
| 291 | + public function filemtime($path) { |
|
| 292 | + return $this->storage->filemtime($this->findPathToUse($path)); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * see http://php.net/manual/en/function.file_get_contents.php |
|
| 297 | + * |
|
| 298 | + * @param string $path |
|
| 299 | + * @return string |
|
| 300 | + */ |
|
| 301 | + public function file_get_contents($path) { |
|
| 302 | + return $this->storage->file_get_contents($this->findPathToUse($path)); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * see http://php.net/manual/en/function.file_put_contents.php |
|
| 307 | + * |
|
| 308 | + * @param string $path |
|
| 309 | + * @param string $data |
|
| 310 | + * @return bool |
|
| 311 | + */ |
|
| 312 | + public function file_put_contents($path, $data) { |
|
| 313 | + return $this->storage->file_put_contents($this->findPathToUse($path), $data); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * see http://php.net/manual/en/function.unlink.php |
|
| 318 | + * |
|
| 319 | + * @param string $path |
|
| 320 | + * @return bool |
|
| 321 | + */ |
|
| 322 | + public function unlink($path) { |
|
| 323 | + $result = $this->storage->unlink($this->findPathToUse($path)); |
|
| 324 | + if ($result) { |
|
| 325 | + unset($this->namesCache[$path]); |
|
| 326 | + } |
|
| 327 | + return $result; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * see http://php.net/manual/en/function.rename.php |
|
| 332 | + * |
|
| 333 | + * @param string $path1 |
|
| 334 | + * @param string $path2 |
|
| 335 | + * @return bool |
|
| 336 | + */ |
|
| 337 | + public function rename($path1, $path2) { |
|
| 338 | + // second name always NFC |
|
| 339 | + return $this->storage->rename($this->findPathToUse($path1), $this->findPathToUse($path2)); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * see http://php.net/manual/en/function.copy.php |
|
| 344 | + * |
|
| 345 | + * @param string $path1 |
|
| 346 | + * @param string $path2 |
|
| 347 | + * @return bool |
|
| 348 | + */ |
|
| 349 | + public function copy($path1, $path2) { |
|
| 350 | + return $this->storage->copy($this->findPathToUse($path1), $this->findPathToUse($path2)); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * see http://php.net/manual/en/function.fopen.php |
|
| 355 | + * |
|
| 356 | + * @param string $path |
|
| 357 | + * @param string $mode |
|
| 358 | + * @return resource |
|
| 359 | + */ |
|
| 360 | + public function fopen($path, $mode) { |
|
| 361 | + $result = $this->storage->fopen($this->findPathToUse($path), $mode); |
|
| 362 | + if ($result && $mode !== 'r' && $mode !== 'rb') { |
|
| 363 | + unset($this->namesCache[$path]); |
|
| 364 | + } |
|
| 365 | + return $result; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * get the mimetype for a file or folder |
|
| 370 | + * The mimetype for a folder is required to be "httpd/unix-directory" |
|
| 371 | + * |
|
| 372 | + * @param string $path |
|
| 373 | + * @return string |
|
| 374 | + */ |
|
| 375 | + public function getMimeType($path) { |
|
| 376 | + return $this->storage->getMimeType($this->findPathToUse($path)); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * see http://php.net/manual/en/function.hash.php |
|
| 381 | + * |
|
| 382 | + * @param string $type |
|
| 383 | + * @param string $path |
|
| 384 | + * @param bool $raw |
|
| 385 | + * @return string |
|
| 386 | + */ |
|
| 387 | + public function hash($type, $path, $raw = false) { |
|
| 388 | + return $this->storage->hash($type, $this->findPathToUse($path), $raw); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * see http://php.net/manual/en/function.free_space.php |
|
| 393 | + * |
|
| 394 | + * @param string $path |
|
| 395 | + * @return int |
|
| 396 | + */ |
|
| 397 | + public function free_space($path) { |
|
| 398 | + return $this->storage->free_space($this->findPathToUse($path)); |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * search for occurrences of $query in file names |
|
| 403 | + * |
|
| 404 | + * @param string $query |
|
| 405 | + * @return array |
|
| 406 | + */ |
|
| 407 | + public function search($query) { |
|
| 408 | + return $this->storage->search($query); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * see http://php.net/manual/en/function.touch.php |
|
| 413 | + * If the backend does not support the operation, false should be returned |
|
| 414 | + * |
|
| 415 | + * @param string $path |
|
| 416 | + * @param int $mtime |
|
| 417 | + * @return bool |
|
| 418 | + */ |
|
| 419 | + public function touch($path, $mtime = null) { |
|
| 420 | + return $this->storage->touch($this->findPathToUse($path), $mtime); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * get the path to a local version of the file. |
|
| 425 | + * The local version of the file can be temporary and doesn't have to be persistent across requests |
|
| 426 | + * |
|
| 427 | + * @param string $path |
|
| 428 | + * @return string |
|
| 429 | + */ |
|
| 430 | + public function getLocalFile($path) { |
|
| 431 | + return $this->storage->getLocalFile($this->findPathToUse($path)); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * check if a file or folder has been updated since $time |
|
| 436 | + * |
|
| 437 | + * @param string $path |
|
| 438 | + * @param int $time |
|
| 439 | + * @return bool |
|
| 440 | + * |
|
| 441 | + * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed. |
|
| 442 | + * returning true for other changes in the folder is optional |
|
| 443 | + */ |
|
| 444 | + public function hasUpdated($path, $time) { |
|
| 445 | + return $this->storage->hasUpdated($this->findPathToUse($path), $time); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * get a cache instance for the storage |
|
| 450 | + * |
|
| 451 | + * @param string $path |
|
| 452 | + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache |
|
| 453 | + * @return \OC\Files\Cache\Cache |
|
| 454 | + */ |
|
| 455 | + public function getCache($path = '', $storage = null) { |
|
| 456 | + if (!$storage) { |
|
| 457 | + $storage = $this; |
|
| 458 | + } |
|
| 459 | + return $this->storage->getCache($this->findPathToUse($path), $storage); |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * get a scanner instance for the storage |
|
| 464 | + * |
|
| 465 | + * @param string $path |
|
| 466 | + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the scanner |
|
| 467 | + * @return \OC\Files\Cache\Scanner |
|
| 468 | + */ |
|
| 469 | + public function getScanner($path = '', $storage = null) { |
|
| 470 | + if (!$storage) { |
|
| 471 | + $storage = $this; |
|
| 472 | + } |
|
| 473 | + return $this->storage->getScanner($this->findPathToUse($path), $storage); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + /** |
|
| 477 | + * get the ETag for a file or folder |
|
| 478 | + * |
|
| 479 | + * @param string $path |
|
| 480 | + * @return string |
|
| 481 | + */ |
|
| 482 | + public function getETag($path) { |
|
| 483 | + return $this->storage->getETag($this->findPathToUse($path)); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * @param IStorage $sourceStorage |
|
| 488 | + * @param string $sourceInternalPath |
|
| 489 | + * @param string $targetInternalPath |
|
| 490 | + * @return bool |
|
| 491 | + */ |
|
| 492 | + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|
| 493 | + if ($sourceStorage === $this) { |
|
| 494 | + return $this->copy($sourceInternalPath, $this->findPathToUse($targetInternalPath)); |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + $result = $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $this->findPathToUse($targetInternalPath)); |
|
| 498 | + if ($result) { |
|
| 499 | + unset($this->namesCache[$targetInternalPath]); |
|
| 500 | + } |
|
| 501 | + return $result; |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * @param IStorage $sourceStorage |
|
| 506 | + * @param string $sourceInternalPath |
|
| 507 | + * @param string $targetInternalPath |
|
| 508 | + * @return bool |
|
| 509 | + */ |
|
| 510 | + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|
| 511 | + if ($sourceStorage === $this) { |
|
| 512 | + $result = $this->rename($sourceInternalPath, $this->findPathToUse($targetInternalPath)); |
|
| 513 | + if ($result) { |
|
| 514 | + unset($this->namesCache[$sourceInternalPath]); |
|
| 515 | + unset($this->namesCache[$targetInternalPath]); |
|
| 516 | + } |
|
| 517 | + return $result; |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + $result = $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $this->findPathToUse($targetInternalPath)); |
|
| 521 | + if ($result) { |
|
| 522 | + unset($this->namesCache[$sourceInternalPath]); |
|
| 523 | + unset($this->namesCache[$targetInternalPath]); |
|
| 524 | + } |
|
| 525 | + return $result; |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * @param string $path |
|
| 530 | + * @return array |
|
| 531 | + */ |
|
| 532 | + public function getMetaData($path) { |
|
| 533 | + return $this->storage->getMetaData($this->findPathToUse($path)); |
|
| 534 | + } |
|
| 535 | 535 | } |
@@ -30,439 +30,439 @@ |
||
| 30 | 30 | * Throws a StorageNotAvailableException for storages with known failures |
| 31 | 31 | */ |
| 32 | 32 | class Availability extends Wrapper { |
| 33 | - const RECHECK_TTL_SEC = 600; // 10 minutes |
|
| 34 | - |
|
| 35 | - public static function shouldRecheck($availability) { |
|
| 36 | - if (!$availability['available']) { |
|
| 37 | - // trigger a recheck if TTL reached |
|
| 38 | - if ((time() - $availability['last_checked']) > self::RECHECK_TTL_SEC) { |
|
| 39 | - return true; |
|
| 40 | - } |
|
| 41 | - } |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Only called if availability === false |
|
| 47 | - * |
|
| 48 | - * @return bool |
|
| 49 | - */ |
|
| 50 | - private function updateAvailability() { |
|
| 51 | - // reset availability to false so that multiple requests don't recheck concurrently |
|
| 52 | - $this->setAvailability(false); |
|
| 53 | - try { |
|
| 54 | - $result = $this->test(); |
|
| 55 | - } catch (\Exception $e) { |
|
| 56 | - $result = false; |
|
| 57 | - } |
|
| 58 | - $this->setAvailability($result); |
|
| 59 | - return $result; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return bool |
|
| 64 | - */ |
|
| 65 | - private function isAvailable() { |
|
| 66 | - $availability = $this->getAvailability(); |
|
| 67 | - if (self::shouldRecheck($availability)) { |
|
| 68 | - return $this->updateAvailability(); |
|
| 69 | - } |
|
| 70 | - return $availability['available']; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @throws \OCP\Files\StorageNotAvailableException |
|
| 75 | - */ |
|
| 76 | - private function checkAvailability() { |
|
| 77 | - if (!$this->isAvailable()) { |
|
| 78 | - throw new \OCP\Files\StorageNotAvailableException(); |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** {@inheritdoc} */ |
|
| 83 | - public function mkdir($path) { |
|
| 84 | - $this->checkAvailability(); |
|
| 85 | - try { |
|
| 86 | - return parent::mkdir($path); |
|
| 87 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 88 | - $this->setAvailability(false); |
|
| 89 | - throw $e; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** {@inheritdoc} */ |
|
| 94 | - public function rmdir($path) { |
|
| 95 | - $this->checkAvailability(); |
|
| 96 | - try { |
|
| 97 | - return parent::rmdir($path); |
|
| 98 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 99 | - $this->setAvailability(false); |
|
| 100 | - throw $e; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** {@inheritdoc} */ |
|
| 105 | - public function opendir($path) { |
|
| 106 | - $this->checkAvailability(); |
|
| 107 | - try { |
|
| 108 | - return parent::opendir($path); |
|
| 109 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 110 | - $this->setAvailability(false); |
|
| 111 | - throw $e; |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** {@inheritdoc} */ |
|
| 116 | - public function is_dir($path) { |
|
| 117 | - $this->checkAvailability(); |
|
| 118 | - try { |
|
| 119 | - return parent::is_dir($path); |
|
| 120 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 121 | - $this->setAvailability(false); |
|
| 122 | - throw $e; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** {@inheritdoc} */ |
|
| 127 | - public function is_file($path) { |
|
| 128 | - $this->checkAvailability(); |
|
| 129 | - try { |
|
| 130 | - return parent::is_file($path); |
|
| 131 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 132 | - $this->setAvailability(false); |
|
| 133 | - throw $e; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** {@inheritdoc} */ |
|
| 138 | - public function stat($path) { |
|
| 139 | - $this->checkAvailability(); |
|
| 140 | - try { |
|
| 141 | - return parent::stat($path); |
|
| 142 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 143 | - $this->setAvailability(false); |
|
| 144 | - throw $e; |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** {@inheritdoc} */ |
|
| 149 | - public function filetype($path) { |
|
| 150 | - $this->checkAvailability(); |
|
| 151 | - try { |
|
| 152 | - return parent::filetype($path); |
|
| 153 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 154 | - $this->setAvailability(false); |
|
| 155 | - throw $e; |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** {@inheritdoc} */ |
|
| 160 | - public function filesize($path) { |
|
| 161 | - $this->checkAvailability(); |
|
| 162 | - try { |
|
| 163 | - return parent::filesize($path); |
|
| 164 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 165 | - $this->setAvailability(false); |
|
| 166 | - throw $e; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** {@inheritdoc} */ |
|
| 171 | - public function isCreatable($path) { |
|
| 172 | - $this->checkAvailability(); |
|
| 173 | - try { |
|
| 174 | - return parent::isCreatable($path); |
|
| 175 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 176 | - $this->setAvailability(false); |
|
| 177 | - throw $e; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** {@inheritdoc} */ |
|
| 182 | - public function isReadable($path) { |
|
| 183 | - $this->checkAvailability(); |
|
| 184 | - try { |
|
| 185 | - return parent::isReadable($path); |
|
| 186 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 187 | - $this->setAvailability(false); |
|
| 188 | - throw $e; |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** {@inheritdoc} */ |
|
| 193 | - public function isUpdatable($path) { |
|
| 194 | - $this->checkAvailability(); |
|
| 195 | - try { |
|
| 196 | - return parent::isUpdatable($path); |
|
| 197 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 198 | - $this->setAvailability(false); |
|
| 199 | - throw $e; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** {@inheritdoc} */ |
|
| 204 | - public function isDeletable($path) { |
|
| 205 | - $this->checkAvailability(); |
|
| 206 | - try { |
|
| 207 | - return parent::isDeletable($path); |
|
| 208 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 209 | - $this->setAvailability(false); |
|
| 210 | - throw $e; |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** {@inheritdoc} */ |
|
| 215 | - public function isSharable($path) { |
|
| 216 | - $this->checkAvailability(); |
|
| 217 | - try { |
|
| 218 | - return parent::isSharable($path); |
|
| 219 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 220 | - $this->setAvailability(false); |
|
| 221 | - throw $e; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** {@inheritdoc} */ |
|
| 226 | - public function getPermissions($path) { |
|
| 227 | - $this->checkAvailability(); |
|
| 228 | - try { |
|
| 229 | - return parent::getPermissions($path); |
|
| 230 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 231 | - $this->setAvailability(false); |
|
| 232 | - throw $e; |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** {@inheritdoc} */ |
|
| 237 | - public function file_exists($path) { |
|
| 238 | - if ($path === '') { |
|
| 239 | - return true; |
|
| 240 | - } |
|
| 241 | - $this->checkAvailability(); |
|
| 242 | - try { |
|
| 243 | - return parent::file_exists($path); |
|
| 244 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 245 | - $this->setAvailability(false); |
|
| 246 | - throw $e; |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** {@inheritdoc} */ |
|
| 251 | - public function filemtime($path) { |
|
| 252 | - $this->checkAvailability(); |
|
| 253 | - try { |
|
| 254 | - return parent::filemtime($path); |
|
| 255 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 256 | - $this->setAvailability(false); |
|
| 257 | - throw $e; |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** {@inheritdoc} */ |
|
| 262 | - public function file_get_contents($path) { |
|
| 263 | - $this->checkAvailability(); |
|
| 264 | - try { |
|
| 265 | - return parent::file_get_contents($path); |
|
| 266 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 267 | - $this->setAvailability(false); |
|
| 268 | - throw $e; |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** {@inheritdoc} */ |
|
| 273 | - public function file_put_contents($path, $data) { |
|
| 274 | - $this->checkAvailability(); |
|
| 275 | - try { |
|
| 276 | - return parent::file_put_contents($path, $data); |
|
| 277 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 278 | - $this->setAvailability(false); |
|
| 279 | - throw $e; |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** {@inheritdoc} */ |
|
| 284 | - public function unlink($path) { |
|
| 285 | - $this->checkAvailability(); |
|
| 286 | - try { |
|
| 287 | - return parent::unlink($path); |
|
| 288 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 289 | - $this->setAvailability(false); |
|
| 290 | - throw $e; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** {@inheritdoc} */ |
|
| 295 | - public function rename($path1, $path2) { |
|
| 296 | - $this->checkAvailability(); |
|
| 297 | - try { |
|
| 298 | - return parent::rename($path1, $path2); |
|
| 299 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 300 | - $this->setAvailability(false); |
|
| 301 | - throw $e; |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** {@inheritdoc} */ |
|
| 306 | - public function copy($path1, $path2) { |
|
| 307 | - $this->checkAvailability(); |
|
| 308 | - try { |
|
| 309 | - return parent::copy($path1, $path2); |
|
| 310 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 311 | - $this->setAvailability(false); |
|
| 312 | - throw $e; |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** {@inheritdoc} */ |
|
| 317 | - public function fopen($path, $mode) { |
|
| 318 | - $this->checkAvailability(); |
|
| 319 | - try { |
|
| 320 | - return parent::fopen($path, $mode); |
|
| 321 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 322 | - $this->setAvailability(false); |
|
| 323 | - throw $e; |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - /** {@inheritdoc} */ |
|
| 328 | - public function getMimeType($path) { |
|
| 329 | - $this->checkAvailability(); |
|
| 330 | - try { |
|
| 331 | - return parent::getMimeType($path); |
|
| 332 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 333 | - $this->setAvailability(false); |
|
| 334 | - throw $e; |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - /** {@inheritdoc} */ |
|
| 339 | - public function hash($type, $path, $raw = false) { |
|
| 340 | - $this->checkAvailability(); |
|
| 341 | - try { |
|
| 342 | - return parent::hash($type, $path, $raw); |
|
| 343 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 344 | - $this->setAvailability(false); |
|
| 345 | - throw $e; |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - /** {@inheritdoc} */ |
|
| 350 | - public function free_space($path) { |
|
| 351 | - $this->checkAvailability(); |
|
| 352 | - try { |
|
| 353 | - return parent::free_space($path); |
|
| 354 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 355 | - $this->setAvailability(false); |
|
| 356 | - throw $e; |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** {@inheritdoc} */ |
|
| 361 | - public function search($query) { |
|
| 362 | - $this->checkAvailability(); |
|
| 363 | - try { |
|
| 364 | - return parent::search($query); |
|
| 365 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 366 | - $this->setAvailability(false); |
|
| 367 | - throw $e; |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** {@inheritdoc} */ |
|
| 372 | - public function touch($path, $mtime = null) { |
|
| 373 | - $this->checkAvailability(); |
|
| 374 | - try { |
|
| 375 | - return parent::touch($path, $mtime); |
|
| 376 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 377 | - $this->setAvailability(false); |
|
| 378 | - throw $e; |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** {@inheritdoc} */ |
|
| 383 | - public function getLocalFile($path) { |
|
| 384 | - $this->checkAvailability(); |
|
| 385 | - try { |
|
| 386 | - return parent::getLocalFile($path); |
|
| 387 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 388 | - $this->setAvailability(false); |
|
| 389 | - throw $e; |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** {@inheritdoc} */ |
|
| 394 | - public function hasUpdated($path, $time) { |
|
| 395 | - $this->checkAvailability(); |
|
| 396 | - try { |
|
| 397 | - return parent::hasUpdated($path, $time); |
|
| 398 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 399 | - $this->setAvailability(false); |
|
| 400 | - throw $e; |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** {@inheritdoc} */ |
|
| 405 | - public function getOwner($path) { |
|
| 406 | - try { |
|
| 407 | - return parent::getOwner($path); |
|
| 408 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 409 | - $this->setAvailability(false); |
|
| 410 | - throw $e; |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - /** {@inheritdoc} */ |
|
| 415 | - public function getETag($path) { |
|
| 416 | - $this->checkAvailability(); |
|
| 417 | - try { |
|
| 418 | - return parent::getETag($path); |
|
| 419 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 420 | - $this->setAvailability(false); |
|
| 421 | - throw $e; |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - /** {@inheritdoc} */ |
|
| 426 | - public function getDirectDownload($path) { |
|
| 427 | - $this->checkAvailability(); |
|
| 428 | - try { |
|
| 429 | - return parent::getDirectDownload($path); |
|
| 430 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 431 | - $this->setAvailability(false); |
|
| 432 | - throw $e; |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - /** {@inheritdoc} */ |
|
| 437 | - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|
| 438 | - $this->checkAvailability(); |
|
| 439 | - try { |
|
| 440 | - return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); |
|
| 441 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 442 | - $this->setAvailability(false); |
|
| 443 | - throw $e; |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /** {@inheritdoc} */ |
|
| 448 | - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|
| 449 | - $this->checkAvailability(); |
|
| 450 | - try { |
|
| 451 | - return parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); |
|
| 452 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 453 | - $this->setAvailability(false); |
|
| 454 | - throw $e; |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** {@inheritdoc} */ |
|
| 459 | - public function getMetaData($path) { |
|
| 460 | - $this->checkAvailability(); |
|
| 461 | - try { |
|
| 462 | - return parent::getMetaData($path); |
|
| 463 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 464 | - $this->setAvailability(false); |
|
| 465 | - throw $e; |
|
| 466 | - } |
|
| 467 | - } |
|
| 33 | + const RECHECK_TTL_SEC = 600; // 10 minutes |
|
| 34 | + |
|
| 35 | + public static function shouldRecheck($availability) { |
|
| 36 | + if (!$availability['available']) { |
|
| 37 | + // trigger a recheck if TTL reached |
|
| 38 | + if ((time() - $availability['last_checked']) > self::RECHECK_TTL_SEC) { |
|
| 39 | + return true; |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | + return false; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Only called if availability === false |
|
| 47 | + * |
|
| 48 | + * @return bool |
|
| 49 | + */ |
|
| 50 | + private function updateAvailability() { |
|
| 51 | + // reset availability to false so that multiple requests don't recheck concurrently |
|
| 52 | + $this->setAvailability(false); |
|
| 53 | + try { |
|
| 54 | + $result = $this->test(); |
|
| 55 | + } catch (\Exception $e) { |
|
| 56 | + $result = false; |
|
| 57 | + } |
|
| 58 | + $this->setAvailability($result); |
|
| 59 | + return $result; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return bool |
|
| 64 | + */ |
|
| 65 | + private function isAvailable() { |
|
| 66 | + $availability = $this->getAvailability(); |
|
| 67 | + if (self::shouldRecheck($availability)) { |
|
| 68 | + return $this->updateAvailability(); |
|
| 69 | + } |
|
| 70 | + return $availability['available']; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @throws \OCP\Files\StorageNotAvailableException |
|
| 75 | + */ |
|
| 76 | + private function checkAvailability() { |
|
| 77 | + if (!$this->isAvailable()) { |
|
| 78 | + throw new \OCP\Files\StorageNotAvailableException(); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** {@inheritdoc} */ |
|
| 83 | + public function mkdir($path) { |
|
| 84 | + $this->checkAvailability(); |
|
| 85 | + try { |
|
| 86 | + return parent::mkdir($path); |
|
| 87 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 88 | + $this->setAvailability(false); |
|
| 89 | + throw $e; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** {@inheritdoc} */ |
|
| 94 | + public function rmdir($path) { |
|
| 95 | + $this->checkAvailability(); |
|
| 96 | + try { |
|
| 97 | + return parent::rmdir($path); |
|
| 98 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 99 | + $this->setAvailability(false); |
|
| 100 | + throw $e; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** {@inheritdoc} */ |
|
| 105 | + public function opendir($path) { |
|
| 106 | + $this->checkAvailability(); |
|
| 107 | + try { |
|
| 108 | + return parent::opendir($path); |
|
| 109 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 110 | + $this->setAvailability(false); |
|
| 111 | + throw $e; |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** {@inheritdoc} */ |
|
| 116 | + public function is_dir($path) { |
|
| 117 | + $this->checkAvailability(); |
|
| 118 | + try { |
|
| 119 | + return parent::is_dir($path); |
|
| 120 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 121 | + $this->setAvailability(false); |
|
| 122 | + throw $e; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** {@inheritdoc} */ |
|
| 127 | + public function is_file($path) { |
|
| 128 | + $this->checkAvailability(); |
|
| 129 | + try { |
|
| 130 | + return parent::is_file($path); |
|
| 131 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 132 | + $this->setAvailability(false); |
|
| 133 | + throw $e; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** {@inheritdoc} */ |
|
| 138 | + public function stat($path) { |
|
| 139 | + $this->checkAvailability(); |
|
| 140 | + try { |
|
| 141 | + return parent::stat($path); |
|
| 142 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 143 | + $this->setAvailability(false); |
|
| 144 | + throw $e; |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** {@inheritdoc} */ |
|
| 149 | + public function filetype($path) { |
|
| 150 | + $this->checkAvailability(); |
|
| 151 | + try { |
|
| 152 | + return parent::filetype($path); |
|
| 153 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 154 | + $this->setAvailability(false); |
|
| 155 | + throw $e; |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** {@inheritdoc} */ |
|
| 160 | + public function filesize($path) { |
|
| 161 | + $this->checkAvailability(); |
|
| 162 | + try { |
|
| 163 | + return parent::filesize($path); |
|
| 164 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 165 | + $this->setAvailability(false); |
|
| 166 | + throw $e; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** {@inheritdoc} */ |
|
| 171 | + public function isCreatable($path) { |
|
| 172 | + $this->checkAvailability(); |
|
| 173 | + try { |
|
| 174 | + return parent::isCreatable($path); |
|
| 175 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 176 | + $this->setAvailability(false); |
|
| 177 | + throw $e; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** {@inheritdoc} */ |
|
| 182 | + public function isReadable($path) { |
|
| 183 | + $this->checkAvailability(); |
|
| 184 | + try { |
|
| 185 | + return parent::isReadable($path); |
|
| 186 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 187 | + $this->setAvailability(false); |
|
| 188 | + throw $e; |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** {@inheritdoc} */ |
|
| 193 | + public function isUpdatable($path) { |
|
| 194 | + $this->checkAvailability(); |
|
| 195 | + try { |
|
| 196 | + return parent::isUpdatable($path); |
|
| 197 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 198 | + $this->setAvailability(false); |
|
| 199 | + throw $e; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** {@inheritdoc} */ |
|
| 204 | + public function isDeletable($path) { |
|
| 205 | + $this->checkAvailability(); |
|
| 206 | + try { |
|
| 207 | + return parent::isDeletable($path); |
|
| 208 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 209 | + $this->setAvailability(false); |
|
| 210 | + throw $e; |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** {@inheritdoc} */ |
|
| 215 | + public function isSharable($path) { |
|
| 216 | + $this->checkAvailability(); |
|
| 217 | + try { |
|
| 218 | + return parent::isSharable($path); |
|
| 219 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 220 | + $this->setAvailability(false); |
|
| 221 | + throw $e; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** {@inheritdoc} */ |
|
| 226 | + public function getPermissions($path) { |
|
| 227 | + $this->checkAvailability(); |
|
| 228 | + try { |
|
| 229 | + return parent::getPermissions($path); |
|
| 230 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 231 | + $this->setAvailability(false); |
|
| 232 | + throw $e; |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** {@inheritdoc} */ |
|
| 237 | + public function file_exists($path) { |
|
| 238 | + if ($path === '') { |
|
| 239 | + return true; |
|
| 240 | + } |
|
| 241 | + $this->checkAvailability(); |
|
| 242 | + try { |
|
| 243 | + return parent::file_exists($path); |
|
| 244 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 245 | + $this->setAvailability(false); |
|
| 246 | + throw $e; |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** {@inheritdoc} */ |
|
| 251 | + public function filemtime($path) { |
|
| 252 | + $this->checkAvailability(); |
|
| 253 | + try { |
|
| 254 | + return parent::filemtime($path); |
|
| 255 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 256 | + $this->setAvailability(false); |
|
| 257 | + throw $e; |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** {@inheritdoc} */ |
|
| 262 | + public function file_get_contents($path) { |
|
| 263 | + $this->checkAvailability(); |
|
| 264 | + try { |
|
| 265 | + return parent::file_get_contents($path); |
|
| 266 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 267 | + $this->setAvailability(false); |
|
| 268 | + throw $e; |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** {@inheritdoc} */ |
|
| 273 | + public function file_put_contents($path, $data) { |
|
| 274 | + $this->checkAvailability(); |
|
| 275 | + try { |
|
| 276 | + return parent::file_put_contents($path, $data); |
|
| 277 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 278 | + $this->setAvailability(false); |
|
| 279 | + throw $e; |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** {@inheritdoc} */ |
|
| 284 | + public function unlink($path) { |
|
| 285 | + $this->checkAvailability(); |
|
| 286 | + try { |
|
| 287 | + return parent::unlink($path); |
|
| 288 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 289 | + $this->setAvailability(false); |
|
| 290 | + throw $e; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** {@inheritdoc} */ |
|
| 295 | + public function rename($path1, $path2) { |
|
| 296 | + $this->checkAvailability(); |
|
| 297 | + try { |
|
| 298 | + return parent::rename($path1, $path2); |
|
| 299 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 300 | + $this->setAvailability(false); |
|
| 301 | + throw $e; |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** {@inheritdoc} */ |
|
| 306 | + public function copy($path1, $path2) { |
|
| 307 | + $this->checkAvailability(); |
|
| 308 | + try { |
|
| 309 | + return parent::copy($path1, $path2); |
|
| 310 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 311 | + $this->setAvailability(false); |
|
| 312 | + throw $e; |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** {@inheritdoc} */ |
|
| 317 | + public function fopen($path, $mode) { |
|
| 318 | + $this->checkAvailability(); |
|
| 319 | + try { |
|
| 320 | + return parent::fopen($path, $mode); |
|
| 321 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 322 | + $this->setAvailability(false); |
|
| 323 | + throw $e; |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + /** {@inheritdoc} */ |
|
| 328 | + public function getMimeType($path) { |
|
| 329 | + $this->checkAvailability(); |
|
| 330 | + try { |
|
| 331 | + return parent::getMimeType($path); |
|
| 332 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 333 | + $this->setAvailability(false); |
|
| 334 | + throw $e; |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + /** {@inheritdoc} */ |
|
| 339 | + public function hash($type, $path, $raw = false) { |
|
| 340 | + $this->checkAvailability(); |
|
| 341 | + try { |
|
| 342 | + return parent::hash($type, $path, $raw); |
|
| 343 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 344 | + $this->setAvailability(false); |
|
| 345 | + throw $e; |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + /** {@inheritdoc} */ |
|
| 350 | + public function free_space($path) { |
|
| 351 | + $this->checkAvailability(); |
|
| 352 | + try { |
|
| 353 | + return parent::free_space($path); |
|
| 354 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 355 | + $this->setAvailability(false); |
|
| 356 | + throw $e; |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** {@inheritdoc} */ |
|
| 361 | + public function search($query) { |
|
| 362 | + $this->checkAvailability(); |
|
| 363 | + try { |
|
| 364 | + return parent::search($query); |
|
| 365 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 366 | + $this->setAvailability(false); |
|
| 367 | + throw $e; |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** {@inheritdoc} */ |
|
| 372 | + public function touch($path, $mtime = null) { |
|
| 373 | + $this->checkAvailability(); |
|
| 374 | + try { |
|
| 375 | + return parent::touch($path, $mtime); |
|
| 376 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 377 | + $this->setAvailability(false); |
|
| 378 | + throw $e; |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** {@inheritdoc} */ |
|
| 383 | + public function getLocalFile($path) { |
|
| 384 | + $this->checkAvailability(); |
|
| 385 | + try { |
|
| 386 | + return parent::getLocalFile($path); |
|
| 387 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 388 | + $this->setAvailability(false); |
|
| 389 | + throw $e; |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** {@inheritdoc} */ |
|
| 394 | + public function hasUpdated($path, $time) { |
|
| 395 | + $this->checkAvailability(); |
|
| 396 | + try { |
|
| 397 | + return parent::hasUpdated($path, $time); |
|
| 398 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 399 | + $this->setAvailability(false); |
|
| 400 | + throw $e; |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** {@inheritdoc} */ |
|
| 405 | + public function getOwner($path) { |
|
| 406 | + try { |
|
| 407 | + return parent::getOwner($path); |
|
| 408 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 409 | + $this->setAvailability(false); |
|
| 410 | + throw $e; |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + /** {@inheritdoc} */ |
|
| 415 | + public function getETag($path) { |
|
| 416 | + $this->checkAvailability(); |
|
| 417 | + try { |
|
| 418 | + return parent::getETag($path); |
|
| 419 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 420 | + $this->setAvailability(false); |
|
| 421 | + throw $e; |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + /** {@inheritdoc} */ |
|
| 426 | + public function getDirectDownload($path) { |
|
| 427 | + $this->checkAvailability(); |
|
| 428 | + try { |
|
| 429 | + return parent::getDirectDownload($path); |
|
| 430 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 431 | + $this->setAvailability(false); |
|
| 432 | + throw $e; |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + /** {@inheritdoc} */ |
|
| 437 | + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|
| 438 | + $this->checkAvailability(); |
|
| 439 | + try { |
|
| 440 | + return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); |
|
| 441 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 442 | + $this->setAvailability(false); |
|
| 443 | + throw $e; |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + /** {@inheritdoc} */ |
|
| 448 | + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|
| 449 | + $this->checkAvailability(); |
|
| 450 | + try { |
|
| 451 | + return parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); |
|
| 452 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 453 | + $this->setAvailability(false); |
|
| 454 | + throw $e; |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** {@inheritdoc} */ |
|
| 459 | + public function getMetaData($path) { |
|
| 460 | + $this->checkAvailability(); |
|
| 461 | + try { |
|
| 462 | + return parent::getMetaData($path); |
|
| 463 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 464 | + $this->setAvailability(false); |
|
| 465 | + throw $e; |
|
| 466 | + } |
|
| 467 | + } |
|
| 468 | 468 | } |
@@ -48,58 +48,58 @@ |
||
| 48 | 48 | * @package OC\Session |
| 49 | 49 | */ |
| 50 | 50 | class CryptoWrapper { |
| 51 | - const COOKIE_NAME = 'oc_sessionPassphrase'; |
|
| 51 | + const COOKIE_NAME = 'oc_sessionPassphrase'; |
|
| 52 | 52 | |
| 53 | - /** @var IConfig */ |
|
| 54 | - protected $config; |
|
| 55 | - /** @var ISession */ |
|
| 56 | - protected $session; |
|
| 57 | - /** @var ICrypto */ |
|
| 58 | - protected $crypto; |
|
| 59 | - /** @var ISecureRandom */ |
|
| 60 | - protected $random; |
|
| 61 | - /** @var string */ |
|
| 62 | - protected $passphrase; |
|
| 53 | + /** @var IConfig */ |
|
| 54 | + protected $config; |
|
| 55 | + /** @var ISession */ |
|
| 56 | + protected $session; |
|
| 57 | + /** @var ICrypto */ |
|
| 58 | + protected $crypto; |
|
| 59 | + /** @var ISecureRandom */ |
|
| 60 | + protected $random; |
|
| 61 | + /** @var string */ |
|
| 62 | + protected $passphrase; |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param IConfig $config |
|
| 66 | - * @param ICrypto $crypto |
|
| 67 | - * @param ISecureRandom $random |
|
| 68 | - * @param IRequest $request |
|
| 69 | - */ |
|
| 70 | - public function __construct(IConfig $config, |
|
| 71 | - ICrypto $crypto, |
|
| 72 | - ISecureRandom $random, |
|
| 73 | - IRequest $request) { |
|
| 74 | - $this->crypto = $crypto; |
|
| 75 | - $this->config = $config; |
|
| 76 | - $this->random = $random; |
|
| 64 | + /** |
|
| 65 | + * @param IConfig $config |
|
| 66 | + * @param ICrypto $crypto |
|
| 67 | + * @param ISecureRandom $random |
|
| 68 | + * @param IRequest $request |
|
| 69 | + */ |
|
| 70 | + public function __construct(IConfig $config, |
|
| 71 | + ICrypto $crypto, |
|
| 72 | + ISecureRandom $random, |
|
| 73 | + IRequest $request) { |
|
| 74 | + $this->crypto = $crypto; |
|
| 75 | + $this->config = $config; |
|
| 76 | + $this->random = $random; |
|
| 77 | 77 | |
| 78 | - if (!is_null($request->getCookie(self::COOKIE_NAME))) { |
|
| 79 | - $this->passphrase = $request->getCookie(self::COOKIE_NAME); |
|
| 80 | - } else { |
|
| 81 | - $this->passphrase = $this->random->generate(128); |
|
| 82 | - $secureCookie = $request->getServerProtocol() === 'https'; |
|
| 83 | - // FIXME: Required for CI |
|
| 84 | - if (!defined('PHPUNIT_RUN')) { |
|
| 85 | - $webRoot = \OC::$WEBROOT; |
|
| 86 | - if($webRoot === '') { |
|
| 87 | - $webRoot = '/'; |
|
| 88 | - } |
|
| 89 | - setcookie(self::COOKIE_NAME, $this->passphrase, 0, $webRoot, '', $secureCookie, true); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - } |
|
| 78 | + if (!is_null($request->getCookie(self::COOKIE_NAME))) { |
|
| 79 | + $this->passphrase = $request->getCookie(self::COOKIE_NAME); |
|
| 80 | + } else { |
|
| 81 | + $this->passphrase = $this->random->generate(128); |
|
| 82 | + $secureCookie = $request->getServerProtocol() === 'https'; |
|
| 83 | + // FIXME: Required for CI |
|
| 84 | + if (!defined('PHPUNIT_RUN')) { |
|
| 85 | + $webRoot = \OC::$WEBROOT; |
|
| 86 | + if($webRoot === '') { |
|
| 87 | + $webRoot = '/'; |
|
| 88 | + } |
|
| 89 | + setcookie(self::COOKIE_NAME, $this->passphrase, 0, $webRoot, '', $secureCookie, true); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @param ISession $session |
|
| 96 | - * @return ISession |
|
| 97 | - */ |
|
| 98 | - public function wrapSession(ISession $session) { |
|
| 99 | - if (!($session instanceof CryptoSessionData)) { |
|
| 100 | - return new CryptoSessionData($session, $this->crypto, $this->passphrase); |
|
| 101 | - } |
|
| 94 | + /** |
|
| 95 | + * @param ISession $session |
|
| 96 | + * @return ISession |
|
| 97 | + */ |
|
| 98 | + public function wrapSession(ISession $session) { |
|
| 99 | + if (!($session instanceof CryptoSessionData)) { |
|
| 100 | + return new CryptoSessionData($session, $this->crypto, $this->passphrase); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - return $session; |
|
| 104 | - } |
|
| 103 | + return $session; |
|
| 104 | + } |
|
| 105 | 105 | } |
@@ -30,114 +30,114 @@ |
||
| 30 | 30 | * @since 8.0.0 |
| 31 | 31 | */ |
| 32 | 32 | interface IDateTimeFormatter { |
| 33 | - /** |
|
| 34 | - * Formats the date of the given timestamp |
|
| 35 | - * |
|
| 36 | - * @param int|\DateTime $timestamp |
|
| 37 | - * @param string $format Either 'full', 'long', 'medium' or 'short' |
|
| 38 | - * full: e.g. 'EEEE, MMMM d, y' => 'Wednesday, August 20, 2014' |
|
| 39 | - * long: e.g. 'MMMM d, y' => 'August 20, 2014' |
|
| 40 | - * medium: e.g. 'MMM d, y' => 'Aug 20, 2014' |
|
| 41 | - * short: e.g. 'M/d/yy' => '8/20/14' |
|
| 42 | - * The exact format is dependent on the language |
|
| 43 | - * @param \DateTimeZone|null $timeZone The timezone to use |
|
| 44 | - * @param \OCP\IL10N|null $l The locale to use |
|
| 45 | - * @return string Formatted date string |
|
| 46 | - * @since 8.0.0 |
|
| 47 | - */ |
|
| 48 | - public function formatDate($timestamp, $format = 'long', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null); |
|
| 33 | + /** |
|
| 34 | + * Formats the date of the given timestamp |
|
| 35 | + * |
|
| 36 | + * @param int|\DateTime $timestamp |
|
| 37 | + * @param string $format Either 'full', 'long', 'medium' or 'short' |
|
| 38 | + * full: e.g. 'EEEE, MMMM d, y' => 'Wednesday, August 20, 2014' |
|
| 39 | + * long: e.g. 'MMMM d, y' => 'August 20, 2014' |
|
| 40 | + * medium: e.g. 'MMM d, y' => 'Aug 20, 2014' |
|
| 41 | + * short: e.g. 'M/d/yy' => '8/20/14' |
|
| 42 | + * The exact format is dependent on the language |
|
| 43 | + * @param \DateTimeZone|null $timeZone The timezone to use |
|
| 44 | + * @param \OCP\IL10N|null $l The locale to use |
|
| 45 | + * @return string Formatted date string |
|
| 46 | + * @since 8.0.0 |
|
| 47 | + */ |
|
| 48 | + public function formatDate($timestamp, $format = 'long', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null); |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Formats the date of the given timestamp |
|
| 52 | - * |
|
| 53 | - * @param int|\DateTime $timestamp |
|
| 54 | - * @param string $format Either 'full', 'long', 'medium' or 'short' |
|
| 55 | - * full: e.g. 'EEEE, MMMM d, y' => 'Wednesday, August 20, 2014' |
|
| 56 | - * long: e.g. 'MMMM d, y' => 'August 20, 2014' |
|
| 57 | - * medium: e.g. 'MMM d, y' => 'Aug 20, 2014' |
|
| 58 | - * short: e.g. 'M/d/yy' => '8/20/14' |
|
| 59 | - * The exact format is dependent on the language |
|
| 60 | - * Uses 'Today', 'Yesterday' and 'Tomorrow' when applicable |
|
| 61 | - * @param \DateTimeZone|null $timeZone The timezone to use |
|
| 62 | - * @param \OCP\IL10N|null $l The locale to use |
|
| 63 | - * @return string Formatted relative date string |
|
| 64 | - * @since 8.0.0 |
|
| 65 | - */ |
|
| 66 | - public function formatDateRelativeDay($timestamp, $format = 'long', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null); |
|
| 50 | + /** |
|
| 51 | + * Formats the date of the given timestamp |
|
| 52 | + * |
|
| 53 | + * @param int|\DateTime $timestamp |
|
| 54 | + * @param string $format Either 'full', 'long', 'medium' or 'short' |
|
| 55 | + * full: e.g. 'EEEE, MMMM d, y' => 'Wednesday, August 20, 2014' |
|
| 56 | + * long: e.g. 'MMMM d, y' => 'August 20, 2014' |
|
| 57 | + * medium: e.g. 'MMM d, y' => 'Aug 20, 2014' |
|
| 58 | + * short: e.g. 'M/d/yy' => '8/20/14' |
|
| 59 | + * The exact format is dependent on the language |
|
| 60 | + * Uses 'Today', 'Yesterday' and 'Tomorrow' when applicable |
|
| 61 | + * @param \DateTimeZone|null $timeZone The timezone to use |
|
| 62 | + * @param \OCP\IL10N|null $l The locale to use |
|
| 63 | + * @return string Formatted relative date string |
|
| 64 | + * @since 8.0.0 |
|
| 65 | + */ |
|
| 66 | + public function formatDateRelativeDay($timestamp, $format = 'long', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null); |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Gives the relative date of the timestamp |
|
| 70 | - * Only works for past dates |
|
| 71 | - * |
|
| 72 | - * @param int|\DateTime $timestamp |
|
| 73 | - * @param int|\DateTime|null $baseTimestamp Timestamp to compare $timestamp against, defaults to current time |
|
| 74 | - * @param \OCP\IL10N|null $l The locale to use |
|
| 75 | - * @return string Dates returned are: |
|
| 76 | - * < 1 month => Today, Yesterday, n days ago |
|
| 77 | - * < 13 month => last month, n months ago |
|
| 78 | - * >= 13 month => last year, n years ago |
|
| 79 | - * @since 8.0.0 |
|
| 80 | - */ |
|
| 81 | - public function formatDateSpan($timestamp, $baseTimestamp = null, \OCP\IL10N $l = null); |
|
| 68 | + /** |
|
| 69 | + * Gives the relative date of the timestamp |
|
| 70 | + * Only works for past dates |
|
| 71 | + * |
|
| 72 | + * @param int|\DateTime $timestamp |
|
| 73 | + * @param int|\DateTime|null $baseTimestamp Timestamp to compare $timestamp against, defaults to current time |
|
| 74 | + * @param \OCP\IL10N|null $l The locale to use |
|
| 75 | + * @return string Dates returned are: |
|
| 76 | + * < 1 month => Today, Yesterday, n days ago |
|
| 77 | + * < 13 month => last month, n months ago |
|
| 78 | + * >= 13 month => last year, n years ago |
|
| 79 | + * @since 8.0.0 |
|
| 80 | + */ |
|
| 81 | + public function formatDateSpan($timestamp, $baseTimestamp = null, \OCP\IL10N $l = null); |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Formats the time of the given timestamp |
|
| 85 | - * |
|
| 86 | - * @param int|\DateTime $timestamp |
|
| 87 | - * @param string $format Either 'full', 'long', 'medium' or 'short' |
|
| 88 | - * full: e.g. 'h:mm:ss a zzzz' => '11:42:13 AM GMT+0:00' |
|
| 89 | - * long: e.g. 'h:mm:ss a z' => '11:42:13 AM GMT' |
|
| 90 | - * medium: e.g. 'h:mm:ss a' => '11:42:13 AM' |
|
| 91 | - * short: e.g. 'h:mm a' => '11:42 AM' |
|
| 92 | - * The exact format is dependent on the language |
|
| 93 | - * @param \DateTimeZone|null $timeZone The timezone to use |
|
| 94 | - * @param \OCP\IL10N|null $l The locale to use |
|
| 95 | - * @return string Formatted time string |
|
| 96 | - * @since 8.0.0 |
|
| 97 | - */ |
|
| 98 | - public function formatTime($timestamp, $format = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null); |
|
| 83 | + /** |
|
| 84 | + * Formats the time of the given timestamp |
|
| 85 | + * |
|
| 86 | + * @param int|\DateTime $timestamp |
|
| 87 | + * @param string $format Either 'full', 'long', 'medium' or 'short' |
|
| 88 | + * full: e.g. 'h:mm:ss a zzzz' => '11:42:13 AM GMT+0:00' |
|
| 89 | + * long: e.g. 'h:mm:ss a z' => '11:42:13 AM GMT' |
|
| 90 | + * medium: e.g. 'h:mm:ss a' => '11:42:13 AM' |
|
| 91 | + * short: e.g. 'h:mm a' => '11:42 AM' |
|
| 92 | + * The exact format is dependent on the language |
|
| 93 | + * @param \DateTimeZone|null $timeZone The timezone to use |
|
| 94 | + * @param \OCP\IL10N|null $l The locale to use |
|
| 95 | + * @return string Formatted time string |
|
| 96 | + * @since 8.0.0 |
|
| 97 | + */ |
|
| 98 | + public function formatTime($timestamp, $format = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null); |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Gives the relative past time of the timestamp |
|
| 102 | - * |
|
| 103 | - * @param int|\DateTime $timestamp |
|
| 104 | - * @param int|\DateTime|null $baseTimestamp Timestamp to compare $timestamp against, defaults to current time |
|
| 105 | - * @param \OCP\IL10N|null $l The locale to use |
|
| 106 | - * @return string Dates returned are: |
|
| 107 | - * < 60 sec => seconds ago |
|
| 108 | - * < 1 hour => n minutes ago |
|
| 109 | - * < 1 day => n hours ago |
|
| 110 | - * < 1 month => Yesterday, n days ago |
|
| 111 | - * < 13 month => last month, n months ago |
|
| 112 | - * >= 13 month => last year, n years ago |
|
| 113 | - * @since 8.0.0 |
|
| 114 | - */ |
|
| 115 | - public function formatTimeSpan($timestamp, $baseTimestamp = null, \OCP\IL10N $l = null); |
|
| 100 | + /** |
|
| 101 | + * Gives the relative past time of the timestamp |
|
| 102 | + * |
|
| 103 | + * @param int|\DateTime $timestamp |
|
| 104 | + * @param int|\DateTime|null $baseTimestamp Timestamp to compare $timestamp against, defaults to current time |
|
| 105 | + * @param \OCP\IL10N|null $l The locale to use |
|
| 106 | + * @return string Dates returned are: |
|
| 107 | + * < 60 sec => seconds ago |
|
| 108 | + * < 1 hour => n minutes ago |
|
| 109 | + * < 1 day => n hours ago |
|
| 110 | + * < 1 month => Yesterday, n days ago |
|
| 111 | + * < 13 month => last month, n months ago |
|
| 112 | + * >= 13 month => last year, n years ago |
|
| 113 | + * @since 8.0.0 |
|
| 114 | + */ |
|
| 115 | + public function formatTimeSpan($timestamp, $baseTimestamp = null, \OCP\IL10N $l = null); |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Formats the date and time of the given timestamp |
|
| 119 | - * |
|
| 120 | - * @param int|\DateTime $timestamp |
|
| 121 | - * @param string $formatDate See formatDate() for description |
|
| 122 | - * @param string $formatTime See formatTime() for description |
|
| 123 | - * @param \DateTimeZone|null $timeZone The timezone to use |
|
| 124 | - * @param \OCP\IL10N|null $l The locale to use |
|
| 125 | - * @return string Formatted date and time string |
|
| 126 | - * @since 8.0.0 |
|
| 127 | - */ |
|
| 128 | - public function formatDateTime($timestamp, $formatDate = 'long', $formatTime = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null); |
|
| 117 | + /** |
|
| 118 | + * Formats the date and time of the given timestamp |
|
| 119 | + * |
|
| 120 | + * @param int|\DateTime $timestamp |
|
| 121 | + * @param string $formatDate See formatDate() for description |
|
| 122 | + * @param string $formatTime See formatTime() for description |
|
| 123 | + * @param \DateTimeZone|null $timeZone The timezone to use |
|
| 124 | + * @param \OCP\IL10N|null $l The locale to use |
|
| 125 | + * @return string Formatted date and time string |
|
| 126 | + * @since 8.0.0 |
|
| 127 | + */ |
|
| 128 | + public function formatDateTime($timestamp, $formatDate = 'long', $formatTime = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null); |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Formats the date and time of the given timestamp |
|
| 132 | - * |
|
| 133 | - * @param int|\DateTime $timestamp |
|
| 134 | - * @param string $formatDate See formatDate() for description |
|
| 135 | - * Uses 'Today', 'Yesterday' and 'Tomorrow' when applicable |
|
| 136 | - * @param string $formatTime See formatTime() for description |
|
| 137 | - * @param \DateTimeZone|null $timeZone The timezone to use |
|
| 138 | - * @param \OCP\IL10N|null $l The locale to use |
|
| 139 | - * @return string Formatted relative date and time string |
|
| 140 | - * @since 8.0.0 |
|
| 141 | - */ |
|
| 142 | - public function formatDateTimeRelativeDay($timestamp, $formatDate = 'long', $formatTime = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null); |
|
| 130 | + /** |
|
| 131 | + * Formats the date and time of the given timestamp |
|
| 132 | + * |
|
| 133 | + * @param int|\DateTime $timestamp |
|
| 134 | + * @param string $formatDate See formatDate() for description |
|
| 135 | + * Uses 'Today', 'Yesterday' and 'Tomorrow' when applicable |
|
| 136 | + * @param string $formatTime See formatTime() for description |
|
| 137 | + * @param \DateTimeZone|null $timeZone The timezone to use |
|
| 138 | + * @param \OCP\IL10N|null $l The locale to use |
|
| 139 | + * @return string Formatted relative date and time string |
|
| 140 | + * @since 8.0.0 |
|
| 141 | + */ |
|
| 142 | + public function formatDateTimeRelativeDay($timestamp, $formatDate = 'long', $formatTime = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null); |
|
| 143 | 143 | } |