@@ -34,112 +34,112 @@ |
||
| 34 | 34 | use OCP\IUser; |
| 35 | 35 | |
| 36 | 36 | class MountProviderCollection implements IMountProviderCollection, Emitter { |
| 37 | - use EmitterTrait; |
|
| 37 | + use EmitterTrait; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var \OCP\Files\Config\IHomeMountProvider[] |
|
| 41 | - */ |
|
| 42 | - private $homeProviders = []; |
|
| 39 | + /** |
|
| 40 | + * @var \OCP\Files\Config\IHomeMountProvider[] |
|
| 41 | + */ |
|
| 42 | + private $homeProviders = []; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @var \OCP\Files\Config\IMountProvider[] |
|
| 46 | - */ |
|
| 47 | - private $providers = array(); |
|
| 44 | + /** |
|
| 45 | + * @var \OCP\Files\Config\IMountProvider[] |
|
| 46 | + */ |
|
| 47 | + private $providers = array(); |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var \OCP\Files\Storage\IStorageFactory |
|
| 51 | - */ |
|
| 52 | - private $loader; |
|
| 49 | + /** |
|
| 50 | + * @var \OCP\Files\Storage\IStorageFactory |
|
| 51 | + */ |
|
| 52 | + private $loader; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @var \OCP\Files\Config\IUserMountCache |
|
| 56 | - */ |
|
| 57 | - private $mountCache; |
|
| 54 | + /** |
|
| 55 | + * @var \OCP\Files\Config\IUserMountCache |
|
| 56 | + */ |
|
| 57 | + private $mountCache; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @param \OCP\Files\Storage\IStorageFactory $loader |
|
| 61 | - * @param IUserMountCache $mountCache |
|
| 62 | - */ |
|
| 63 | - public function __construct(IStorageFactory $loader, IUserMountCache $mountCache) { |
|
| 64 | - $this->loader = $loader; |
|
| 65 | - $this->mountCache = $mountCache; |
|
| 66 | - } |
|
| 59 | + /** |
|
| 60 | + * @param \OCP\Files\Storage\IStorageFactory $loader |
|
| 61 | + * @param IUserMountCache $mountCache |
|
| 62 | + */ |
|
| 63 | + public function __construct(IStorageFactory $loader, IUserMountCache $mountCache) { |
|
| 64 | + $this->loader = $loader; |
|
| 65 | + $this->mountCache = $mountCache; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Get all configured mount points for the user |
|
| 70 | - * |
|
| 71 | - * @param \OCP\IUser $user |
|
| 72 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
| 73 | - */ |
|
| 74 | - public function getMountsForUser(IUser $user) { |
|
| 75 | - $loader = $this->loader; |
|
| 76 | - $mounts = array_map(function (IMountProvider $provider) use ($user, $loader) { |
|
| 77 | - return $provider->getMountsForUser($user, $loader); |
|
| 78 | - }, $this->providers); |
|
| 79 | - $mounts = array_filter($mounts, function ($result) { |
|
| 80 | - return is_array($result); |
|
| 81 | - }); |
|
| 82 | - return array_reduce($mounts, function (array $mounts, array $providerMounts) { |
|
| 83 | - return array_merge($mounts, $providerMounts); |
|
| 84 | - }, array()); |
|
| 85 | - } |
|
| 68 | + /** |
|
| 69 | + * Get all configured mount points for the user |
|
| 70 | + * |
|
| 71 | + * @param \OCP\IUser $user |
|
| 72 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
| 73 | + */ |
|
| 74 | + public function getMountsForUser(IUser $user) { |
|
| 75 | + $loader = $this->loader; |
|
| 76 | + $mounts = array_map(function (IMountProvider $provider) use ($user, $loader) { |
|
| 77 | + return $provider->getMountsForUser($user, $loader); |
|
| 78 | + }, $this->providers); |
|
| 79 | + $mounts = array_filter($mounts, function ($result) { |
|
| 80 | + return is_array($result); |
|
| 81 | + }); |
|
| 82 | + return array_reduce($mounts, function (array $mounts, array $providerMounts) { |
|
| 83 | + return array_merge($mounts, $providerMounts); |
|
| 84 | + }, array()); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Get the configured home mount for this user |
|
| 89 | - * |
|
| 90 | - * @param \OCP\IUser $user |
|
| 91 | - * @return \OCP\Files\Mount\IMountPoint |
|
| 92 | - * @since 9.1.0 |
|
| 93 | - */ |
|
| 94 | - public function getHomeMountForUser(IUser $user) { |
|
| 95 | - /** @var \OCP\Files\Config\IHomeMountProvider[] $providers */ |
|
| 96 | - $providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin |
|
| 97 | - foreach ($providers as $homeProvider) { |
|
| 98 | - if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) { |
|
| 99 | - $mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect |
|
| 100 | - return $mount; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - throw new \Exception('No home storage configured for user ' . $user); |
|
| 104 | - } |
|
| 87 | + /** |
|
| 88 | + * Get the configured home mount for this user |
|
| 89 | + * |
|
| 90 | + * @param \OCP\IUser $user |
|
| 91 | + * @return \OCP\Files\Mount\IMountPoint |
|
| 92 | + * @since 9.1.0 |
|
| 93 | + */ |
|
| 94 | + public function getHomeMountForUser(IUser $user) { |
|
| 95 | + /** @var \OCP\Files\Config\IHomeMountProvider[] $providers */ |
|
| 96 | + $providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin |
|
| 97 | + foreach ($providers as $homeProvider) { |
|
| 98 | + if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) { |
|
| 99 | + $mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect |
|
| 100 | + return $mount; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + throw new \Exception('No home storage configured for user ' . $user); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Add a provider for mount points |
|
| 108 | - * |
|
| 109 | - * @param \OCP\Files\Config\IMountProvider $provider |
|
| 110 | - */ |
|
| 111 | - public function registerProvider(IMountProvider $provider) { |
|
| 112 | - $this->providers[] = $provider; |
|
| 113 | - $this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]); |
|
| 114 | - } |
|
| 106 | + /** |
|
| 107 | + * Add a provider for mount points |
|
| 108 | + * |
|
| 109 | + * @param \OCP\Files\Config\IMountProvider $provider |
|
| 110 | + */ |
|
| 111 | + public function registerProvider(IMountProvider $provider) { |
|
| 112 | + $this->providers[] = $provider; |
|
| 113 | + $this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * Add a provider for home mount points |
|
| 118 | - * |
|
| 119 | - * @param \OCP\Files\Config\IHomeMountProvider $provider |
|
| 120 | - * @since 9.1.0 |
|
| 121 | - */ |
|
| 122 | - public function registerHomeProvider(IHomeMountProvider $provider) { |
|
| 123 | - $this->homeProviders[] = $provider; |
|
| 124 | - $this->emit('\OC\Files\Config', 'registerHomeMountProvider', [$provider]); |
|
| 125 | - } |
|
| 116 | + /** |
|
| 117 | + * Add a provider for home mount points |
|
| 118 | + * |
|
| 119 | + * @param \OCP\Files\Config\IHomeMountProvider $provider |
|
| 120 | + * @since 9.1.0 |
|
| 121 | + */ |
|
| 122 | + public function registerHomeProvider(IHomeMountProvider $provider) { |
|
| 123 | + $this->homeProviders[] = $provider; |
|
| 124 | + $this->emit('\OC\Files\Config', 'registerHomeMountProvider', [$provider]); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * Cache mounts for user |
|
| 129 | - * |
|
| 130 | - * @param IUser $user |
|
| 131 | - * @param IMountPoint[] $mountPoints |
|
| 132 | - */ |
|
| 133 | - public function registerMounts(IUser $user, array $mountPoints) { |
|
| 134 | - $this->mountCache->registerMounts($user, $mountPoints); |
|
| 135 | - } |
|
| 127 | + /** |
|
| 128 | + * Cache mounts for user |
|
| 129 | + * |
|
| 130 | + * @param IUser $user |
|
| 131 | + * @param IMountPoint[] $mountPoints |
|
| 132 | + */ |
|
| 133 | + public function registerMounts(IUser $user, array $mountPoints) { |
|
| 134 | + $this->mountCache->registerMounts($user, $mountPoints); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * Get the mount cache which can be used to search for mounts without setting up the filesystem |
|
| 139 | - * |
|
| 140 | - * @return IUserMountCache |
|
| 141 | - */ |
|
| 142 | - public function getMountCache() { |
|
| 143 | - return $this->mountCache; |
|
| 144 | - } |
|
| 137 | + /** |
|
| 138 | + * Get the mount cache which can be used to search for mounts without setting up the filesystem |
|
| 139 | + * |
|
| 140 | + * @return IUserMountCache |
|
| 141 | + */ |
|
| 142 | + public function getMountCache() { |
|
| 143 | + return $this->mountCache; |
|
| 144 | + } |
|
| 145 | 145 | } |
@@ -73,13 +73,13 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public function getMountsForUser(IUser $user) { |
| 75 | 75 | $loader = $this->loader; |
| 76 | - $mounts = array_map(function (IMountProvider $provider) use ($user, $loader) { |
|
| 76 | + $mounts = array_map(function(IMountProvider $provider) use ($user, $loader) { |
|
| 77 | 77 | return $provider->getMountsForUser($user, $loader); |
| 78 | 78 | }, $this->providers); |
| 79 | - $mounts = array_filter($mounts, function ($result) { |
|
| 79 | + $mounts = array_filter($mounts, function($result) { |
|
| 80 | 80 | return is_array($result); |
| 81 | 81 | }); |
| 82 | - return array_reduce($mounts, function (array $mounts, array $providerMounts) { |
|
| 82 | + return array_reduce($mounts, function(array $mounts, array $providerMounts) { |
|
| 83 | 83 | return array_merge($mounts, $providerMounts); |
| 84 | 84 | }, array()); |
| 85 | 85 | } |
@@ -96,11 +96,11 @@ discard block |
||
| 96 | 96 | $providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin |
| 97 | 97 | foreach ($providers as $homeProvider) { |
| 98 | 98 | if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) { |
| 99 | - $mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect |
|
| 99 | + $mount->setMountPoint('/'.$user->getUID()); //make sure the mountpoint is what we expect |
|
| 100 | 100 | return $mount; |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | - throw new \Exception('No home storage configured for user ' . $user); |
|
| 103 | + throw new \Exception('No home storage configured for user '.$user); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -29,21 +29,21 @@ |
||
| 29 | 29 | * Listen to hooks and update the mount cache as needed |
| 30 | 30 | */ |
| 31 | 31 | class UserMountCacheListener { |
| 32 | - /** |
|
| 33 | - * @var IUserMountCache |
|
| 34 | - */ |
|
| 35 | - private $userMountCache; |
|
| 32 | + /** |
|
| 33 | + * @var IUserMountCache |
|
| 34 | + */ |
|
| 35 | + private $userMountCache; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * UserMountCacheListener constructor. |
|
| 39 | - * |
|
| 40 | - * @param IUserMountCache $userMountCache |
|
| 41 | - */ |
|
| 42 | - public function __construct(IUserMountCache $userMountCache) { |
|
| 43 | - $this->userMountCache = $userMountCache; |
|
| 44 | - } |
|
| 37 | + /** |
|
| 38 | + * UserMountCacheListener constructor. |
|
| 39 | + * |
|
| 40 | + * @param IUserMountCache $userMountCache |
|
| 41 | + */ |
|
| 42 | + public function __construct(IUserMountCache $userMountCache) { |
|
| 43 | + $this->userMountCache = $userMountCache; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function listen(Manager $manager) { |
|
| 47 | - $manager->listen('\OC\User', 'postDelete', [$this->userMountCache, 'removeUserMounts']); |
|
| 48 | - } |
|
| 46 | + public function listen(Manager $manager) { |
|
| 47 | + $manager->listen('\OC\User', 'postDelete', [$this->userMountCache, 'removeUserMounts']); |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -99,17 +99,17 @@ discard block |
||
| 99 | 99 | protected function attachListener($mount) { |
| 100 | 100 | $scanner = $mount->getStorage()->getScanner(); |
| 101 | 101 | $emitter = $this; |
| 102 | - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount, $emitter) { |
|
| 103 | - $emitter->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint() . $path)); |
|
| 102 | + $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function($path) use ($mount, $emitter) { |
|
| 103 | + $emitter->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint().$path)); |
|
| 104 | 104 | }); |
| 105 | - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount, $emitter) { |
|
| 106 | - $emitter->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint() . $path)); |
|
| 105 | + $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function($path) use ($mount, $emitter) { |
|
| 106 | + $emitter->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint().$path)); |
|
| 107 | 107 | }); |
| 108 | - $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFile', function ($path) use ($mount, $emitter) { |
|
| 109 | - $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFile', array($mount->getMountPoint() . $path)); |
|
| 108 | + $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFile', function($path) use ($mount, $emitter) { |
|
| 109 | + $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFile', array($mount->getMountPoint().$path)); |
|
| 110 | 110 | }); |
| 111 | - $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFolder', function ($path) use ($mount, $emitter) { |
|
| 112 | - $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFolder', array($mount->getMountPoint() . $path)); |
|
| 111 | + $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFolder', function($path) use ($mount, $emitter) { |
|
| 112 | + $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFolder', array($mount->getMountPoint().$path)); |
|
| 113 | 113 | }); |
| 114 | 114 | } |
| 115 | 115 | |
@@ -135,13 +135,13 @@ discard block |
||
| 135 | 135 | $scanner = $storage->getScanner(); |
| 136 | 136 | $this->attachListener($mount); |
| 137 | 137 | |
| 138 | - $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
| 138 | + $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function($path) use ($storage) { |
|
| 139 | 139 | $this->triggerPropagator($storage, $path); |
| 140 | 140 | }); |
| 141 | - $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
| 141 | + $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function($path) use ($storage) { |
|
| 142 | 142 | $this->triggerPropagator($storage, $path); |
| 143 | 143 | }); |
| 144 | - $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
| 144 | + $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function($path) use ($storage) { |
|
| 145 | 145 | $this->triggerPropagator($storage, $path); |
| 146 | 146 | }); |
| 147 | 147 | |
@@ -188,13 +188,13 @@ discard block |
||
| 188 | 188 | $this->attachListener($mount); |
| 189 | 189 | $isDbLocking = \OC::$server->getLockingProvider() instanceof DBLockingProvider; |
| 190 | 190 | |
| 191 | - $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
| 191 | + $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function($path) use ($storage) { |
|
| 192 | 192 | $this->triggerPropagator($storage, $path); |
| 193 | 193 | }); |
| 194 | - $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
| 194 | + $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function($path) use ($storage) { |
|
| 195 | 195 | $this->triggerPropagator($storage, $path); |
| 196 | 196 | }); |
| 197 | - $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
| 197 | + $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function($path) use ($storage) { |
|
| 198 | 198 | $this->triggerPropagator($storage, $path); |
| 199 | 199 | }); |
| 200 | 200 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | } |
| 213 | 213 | $propagator->commitBatch(); |
| 214 | 214 | } catch (StorageNotAvailableException $e) { |
| 215 | - $this->logger->error('Storage ' . $storage->getId() . ' not available'); |
|
| 215 | + $this->logger->error('Storage '.$storage->getId().' not available'); |
|
| 216 | 216 | $this->logger->logException($e); |
| 217 | 217 | $this->emit('\OC\Files\Utils\Scanner', 'StorageNotAvailable', [$e]); |
| 218 | 218 | } |
@@ -45,174 +45,174 @@ |
||
| 45 | 45 | * @package OC\Files\Utils |
| 46 | 46 | */ |
| 47 | 47 | class Scanner extends PublicEmitter { |
| 48 | - /** |
|
| 49 | - * @var string $user |
|
| 50 | - */ |
|
| 51 | - private $user; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var \OCP\IDBConnection |
|
| 55 | - */ |
|
| 56 | - protected $db; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var ILogger |
|
| 60 | - */ |
|
| 61 | - protected $logger; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @param string $user |
|
| 65 | - * @param \OCP\IDBConnection $db |
|
| 66 | - * @param ILogger $logger |
|
| 67 | - */ |
|
| 68 | - public function __construct($user, $db, ILogger $logger) { |
|
| 69 | - $this->logger = $logger; |
|
| 70 | - $this->user = $user; |
|
| 71 | - $this->db = $db; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * get all storages for $dir |
|
| 76 | - * |
|
| 77 | - * @param string $dir |
|
| 78 | - * @return \OC\Files\Mount\MountPoint[] |
|
| 79 | - */ |
|
| 80 | - protected function getMounts($dir) { |
|
| 81 | - //TODO: move to the node based fileapi once that's done |
|
| 82 | - \OC_Util::tearDownFS(); |
|
| 83 | - \OC_Util::setupFS($this->user); |
|
| 84 | - |
|
| 85 | - $mountManager = Filesystem::getMountManager(); |
|
| 86 | - $mounts = $mountManager->findIn($dir); |
|
| 87 | - $mounts[] = $mountManager->find($dir); |
|
| 88 | - $mounts = array_reverse($mounts); //start with the mount of $dir |
|
| 89 | - |
|
| 90 | - return $mounts; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * attach listeners to the scanner |
|
| 95 | - * |
|
| 96 | - * @param \OC\Files\Mount\MountPoint $mount |
|
| 97 | - */ |
|
| 98 | - protected function attachListener($mount) { |
|
| 99 | - $scanner = $mount->getStorage()->getScanner(); |
|
| 100 | - $emitter = $this; |
|
| 101 | - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount, $emitter) { |
|
| 102 | - $emitter->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint() . $path)); |
|
| 103 | - }); |
|
| 104 | - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount, $emitter) { |
|
| 105 | - $emitter->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint() . $path)); |
|
| 106 | - }); |
|
| 107 | - $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFile', function ($path) use ($mount, $emitter) { |
|
| 108 | - $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFile', array($mount->getMountPoint() . $path)); |
|
| 109 | - }); |
|
| 110 | - $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFolder', function ($path) use ($mount, $emitter) { |
|
| 111 | - $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFolder', array($mount->getMountPoint() . $path)); |
|
| 112 | - }); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @param string $dir |
|
| 117 | - */ |
|
| 118 | - public function backgroundScan($dir) { |
|
| 119 | - $mounts = $this->getMounts($dir); |
|
| 120 | - foreach ($mounts as $mount) { |
|
| 121 | - if (is_null($mount->getStorage())) { |
|
| 122 | - continue; |
|
| 123 | - } |
|
| 124 | - // don't scan the root storage |
|
| 125 | - if ($mount->getStorage()->instanceOfStorage('\OC\Files\Storage\Local') && $mount->getMountPoint() === '/') { |
|
| 126 | - continue; |
|
| 127 | - } |
|
| 128 | - $storage = $mount->getStorage(); |
|
| 129 | - $scanner = $storage->getScanner(); |
|
| 130 | - $this->attachListener($mount); |
|
| 131 | - |
|
| 132 | - $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
| 133 | - $this->triggerPropagator($storage, $path); |
|
| 134 | - }); |
|
| 135 | - $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
| 136 | - $this->triggerPropagator($storage, $path); |
|
| 137 | - }); |
|
| 138 | - $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
| 139 | - $this->triggerPropagator($storage, $path); |
|
| 140 | - }); |
|
| 141 | - |
|
| 142 | - $propagator = $storage->getPropagator(); |
|
| 143 | - $propagator->beginBatch(); |
|
| 144 | - $scanner->backgroundScan(); |
|
| 145 | - $propagator->commitBatch(); |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @param string $dir |
|
| 151 | - * @throws \OC\ForbiddenException |
|
| 152 | - */ |
|
| 153 | - public function scan($dir = '') { |
|
| 154 | - if (!Filesystem::isValidPath($dir)) { |
|
| 155 | - throw new \InvalidArgumentException('Invalid path to scan'); |
|
| 156 | - } |
|
| 157 | - $mounts = $this->getMounts($dir); |
|
| 158 | - foreach ($mounts as $mount) { |
|
| 159 | - if (is_null($mount->getStorage())) { |
|
| 160 | - continue; |
|
| 161 | - } |
|
| 162 | - $storage = $mount->getStorage(); |
|
| 163 | - // if the home storage isn't writable then the scanner is run as the wrong user |
|
| 164 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') and |
|
| 165 | - (!$storage->isCreatable('') or !$storage->isCreatable('files')) |
|
| 166 | - ) { |
|
| 167 | - if ($storage->file_exists('') or $storage->getCache()->inCache('')) { |
|
| 168 | - throw new ForbiddenException(); |
|
| 169 | - } else {// if the root exists in neither the cache nor the storage the user isn't setup yet |
|
| 170 | - break; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - } |
|
| 174 | - $relativePath = $mount->getInternalPath($dir); |
|
| 175 | - $scanner = $storage->getScanner(); |
|
| 176 | - $scanner->setUseTransactions(false); |
|
| 177 | - $this->attachListener($mount); |
|
| 178 | - $isDbLocking = \OC::$server->getLockingProvider() instanceof DBLockingProvider; |
|
| 179 | - |
|
| 180 | - $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
| 181 | - $this->triggerPropagator($storage, $path); |
|
| 182 | - }); |
|
| 183 | - $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
| 184 | - $this->triggerPropagator($storage, $path); |
|
| 185 | - }); |
|
| 186 | - $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
| 187 | - $this->triggerPropagator($storage, $path); |
|
| 188 | - }); |
|
| 189 | - |
|
| 190 | - if (!$isDbLocking) { |
|
| 191 | - $this->db->beginTransaction(); |
|
| 192 | - } |
|
| 193 | - try { |
|
| 194 | - $propagator = $storage->getPropagator(); |
|
| 195 | - $propagator->beginBatch(); |
|
| 196 | - $scanner->scan($relativePath, \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE); |
|
| 197 | - $cache = $storage->getCache(); |
|
| 198 | - if ($cache instanceof Cache) { |
|
| 199 | - // only re-calculate for the root folder we scanned, anything below that is taken care of by the scanner |
|
| 200 | - $cache->correctFolderSize($relativePath); |
|
| 201 | - } |
|
| 202 | - $propagator->commitBatch(); |
|
| 203 | - } catch (StorageNotAvailableException $e) { |
|
| 204 | - $this->logger->error('Storage ' . $storage->getId() . ' not available'); |
|
| 205 | - $this->logger->logException($e); |
|
| 206 | - $this->emit('\OC\Files\Utils\Scanner', 'StorageNotAvailable', [$e]); |
|
| 207 | - } |
|
| 208 | - if (!$isDbLocking) { |
|
| 209 | - $this->db->commit(); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - private function triggerPropagator(IStorage $storage, $internalPath) { |
|
| 215 | - $storage->getPropagator()->propagateChange($internalPath, time()); |
|
| 216 | - } |
|
| 48 | + /** |
|
| 49 | + * @var string $user |
|
| 50 | + */ |
|
| 51 | + private $user; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var \OCP\IDBConnection |
|
| 55 | + */ |
|
| 56 | + protected $db; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var ILogger |
|
| 60 | + */ |
|
| 61 | + protected $logger; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @param string $user |
|
| 65 | + * @param \OCP\IDBConnection $db |
|
| 66 | + * @param ILogger $logger |
|
| 67 | + */ |
|
| 68 | + public function __construct($user, $db, ILogger $logger) { |
|
| 69 | + $this->logger = $logger; |
|
| 70 | + $this->user = $user; |
|
| 71 | + $this->db = $db; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * get all storages for $dir |
|
| 76 | + * |
|
| 77 | + * @param string $dir |
|
| 78 | + * @return \OC\Files\Mount\MountPoint[] |
|
| 79 | + */ |
|
| 80 | + protected function getMounts($dir) { |
|
| 81 | + //TODO: move to the node based fileapi once that's done |
|
| 82 | + \OC_Util::tearDownFS(); |
|
| 83 | + \OC_Util::setupFS($this->user); |
|
| 84 | + |
|
| 85 | + $mountManager = Filesystem::getMountManager(); |
|
| 86 | + $mounts = $mountManager->findIn($dir); |
|
| 87 | + $mounts[] = $mountManager->find($dir); |
|
| 88 | + $mounts = array_reverse($mounts); //start with the mount of $dir |
|
| 89 | + |
|
| 90 | + return $mounts; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * attach listeners to the scanner |
|
| 95 | + * |
|
| 96 | + * @param \OC\Files\Mount\MountPoint $mount |
|
| 97 | + */ |
|
| 98 | + protected function attachListener($mount) { |
|
| 99 | + $scanner = $mount->getStorage()->getScanner(); |
|
| 100 | + $emitter = $this; |
|
| 101 | + $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount, $emitter) { |
|
| 102 | + $emitter->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint() . $path)); |
|
| 103 | + }); |
|
| 104 | + $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount, $emitter) { |
|
| 105 | + $emitter->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint() . $path)); |
|
| 106 | + }); |
|
| 107 | + $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFile', function ($path) use ($mount, $emitter) { |
|
| 108 | + $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFile', array($mount->getMountPoint() . $path)); |
|
| 109 | + }); |
|
| 110 | + $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFolder', function ($path) use ($mount, $emitter) { |
|
| 111 | + $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFolder', array($mount->getMountPoint() . $path)); |
|
| 112 | + }); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @param string $dir |
|
| 117 | + */ |
|
| 118 | + public function backgroundScan($dir) { |
|
| 119 | + $mounts = $this->getMounts($dir); |
|
| 120 | + foreach ($mounts as $mount) { |
|
| 121 | + if (is_null($mount->getStorage())) { |
|
| 122 | + continue; |
|
| 123 | + } |
|
| 124 | + // don't scan the root storage |
|
| 125 | + if ($mount->getStorage()->instanceOfStorage('\OC\Files\Storage\Local') && $mount->getMountPoint() === '/') { |
|
| 126 | + continue; |
|
| 127 | + } |
|
| 128 | + $storage = $mount->getStorage(); |
|
| 129 | + $scanner = $storage->getScanner(); |
|
| 130 | + $this->attachListener($mount); |
|
| 131 | + |
|
| 132 | + $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
| 133 | + $this->triggerPropagator($storage, $path); |
|
| 134 | + }); |
|
| 135 | + $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
| 136 | + $this->triggerPropagator($storage, $path); |
|
| 137 | + }); |
|
| 138 | + $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
| 139 | + $this->triggerPropagator($storage, $path); |
|
| 140 | + }); |
|
| 141 | + |
|
| 142 | + $propagator = $storage->getPropagator(); |
|
| 143 | + $propagator->beginBatch(); |
|
| 144 | + $scanner->backgroundScan(); |
|
| 145 | + $propagator->commitBatch(); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @param string $dir |
|
| 151 | + * @throws \OC\ForbiddenException |
|
| 152 | + */ |
|
| 153 | + public function scan($dir = '') { |
|
| 154 | + if (!Filesystem::isValidPath($dir)) { |
|
| 155 | + throw new \InvalidArgumentException('Invalid path to scan'); |
|
| 156 | + } |
|
| 157 | + $mounts = $this->getMounts($dir); |
|
| 158 | + foreach ($mounts as $mount) { |
|
| 159 | + if (is_null($mount->getStorage())) { |
|
| 160 | + continue; |
|
| 161 | + } |
|
| 162 | + $storage = $mount->getStorage(); |
|
| 163 | + // if the home storage isn't writable then the scanner is run as the wrong user |
|
| 164 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Home') and |
|
| 165 | + (!$storage->isCreatable('') or !$storage->isCreatable('files')) |
|
| 166 | + ) { |
|
| 167 | + if ($storage->file_exists('') or $storage->getCache()->inCache('')) { |
|
| 168 | + throw new ForbiddenException(); |
|
| 169 | + } else {// if the root exists in neither the cache nor the storage the user isn't setup yet |
|
| 170 | + break; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + } |
|
| 174 | + $relativePath = $mount->getInternalPath($dir); |
|
| 175 | + $scanner = $storage->getScanner(); |
|
| 176 | + $scanner->setUseTransactions(false); |
|
| 177 | + $this->attachListener($mount); |
|
| 178 | + $isDbLocking = \OC::$server->getLockingProvider() instanceof DBLockingProvider; |
|
| 179 | + |
|
| 180 | + $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
| 181 | + $this->triggerPropagator($storage, $path); |
|
| 182 | + }); |
|
| 183 | + $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
| 184 | + $this->triggerPropagator($storage, $path); |
|
| 185 | + }); |
|
| 186 | + $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
| 187 | + $this->triggerPropagator($storage, $path); |
|
| 188 | + }); |
|
| 189 | + |
|
| 190 | + if (!$isDbLocking) { |
|
| 191 | + $this->db->beginTransaction(); |
|
| 192 | + } |
|
| 193 | + try { |
|
| 194 | + $propagator = $storage->getPropagator(); |
|
| 195 | + $propagator->beginBatch(); |
|
| 196 | + $scanner->scan($relativePath, \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE); |
|
| 197 | + $cache = $storage->getCache(); |
|
| 198 | + if ($cache instanceof Cache) { |
|
| 199 | + // only re-calculate for the root folder we scanned, anything below that is taken care of by the scanner |
|
| 200 | + $cache->correctFolderSize($relativePath); |
|
| 201 | + } |
|
| 202 | + $propagator->commitBatch(); |
|
| 203 | + } catch (StorageNotAvailableException $e) { |
|
| 204 | + $this->logger->error('Storage ' . $storage->getId() . ' not available'); |
|
| 205 | + $this->logger->logException($e); |
|
| 206 | + $this->emit('\OC\Files\Utils\Scanner', 'StorageNotAvailable', [$e]); |
|
| 207 | + } |
|
| 208 | + if (!$isDbLocking) { |
|
| 209 | + $this->db->commit(); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + private function triggerPropagator(IStorage $storage, $internalPath) { |
|
| 215 | + $storage->getPropagator()->propagateChange($internalPath, time()); |
|
| 216 | + } |
|
| 217 | 217 | } |
| 218 | 218 | |
@@ -28,42 +28,42 @@ |
||
| 28 | 28 | |
| 29 | 29 | class HomeObjectStoreStorage extends ObjectStoreStorage implements \OCP\Files\IHomeStorage { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * The home user storage requires a user object to create a unique storage id |
|
| 33 | - * @param array $params |
|
| 34 | - */ |
|
| 35 | - public function __construct($params) { |
|
| 36 | - if ( ! isset($params['user']) || ! $params['user'] instanceof User) { |
|
| 37 | - throw new \Exception('missing user object in parameters'); |
|
| 38 | - } |
|
| 39 | - $this->user = $params['user']; |
|
| 40 | - parent::__construct($params); |
|
| 41 | - } |
|
| 31 | + /** |
|
| 32 | + * The home user storage requires a user object to create a unique storage id |
|
| 33 | + * @param array $params |
|
| 34 | + */ |
|
| 35 | + public function __construct($params) { |
|
| 36 | + if ( ! isset($params['user']) || ! $params['user'] instanceof User) { |
|
| 37 | + throw new \Exception('missing user object in parameters'); |
|
| 38 | + } |
|
| 39 | + $this->user = $params['user']; |
|
| 40 | + parent::__construct($params); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function getId () { |
|
| 44 | - return 'object::user:' . $this->user->getUID(); |
|
| 45 | - } |
|
| 43 | + public function getId () { |
|
| 44 | + return 'object::user:' . $this->user->getUID(); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * get the owner of a path |
|
| 49 | - * |
|
| 50 | - * @param string $path The path to get the owner |
|
| 51 | - * @return false|string uid |
|
| 52 | - */ |
|
| 53 | - public function getOwner($path) { |
|
| 54 | - if (is_object($this->user)) { |
|
| 55 | - return $this->user->getUID(); |
|
| 56 | - } |
|
| 57 | - return false; |
|
| 58 | - } |
|
| 47 | + /** |
|
| 48 | + * get the owner of a path |
|
| 49 | + * |
|
| 50 | + * @param string $path The path to get the owner |
|
| 51 | + * @return false|string uid |
|
| 52 | + */ |
|
| 53 | + public function getOwner($path) { |
|
| 54 | + if (is_object($this->user)) { |
|
| 55 | + return $this->user->getUID(); |
|
| 56 | + } |
|
| 57 | + return false; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @param string $path, optional |
|
| 62 | - * @return \OC\User\User |
|
| 63 | - */ |
|
| 64 | - public function getUser($path = null) { |
|
| 65 | - return $this->user; |
|
| 66 | - } |
|
| 60 | + /** |
|
| 61 | + * @param string $path, optional |
|
| 62 | + * @return \OC\User\User |
|
| 63 | + */ |
|
| 64 | + public function getUser($path = null) { |
|
| 65 | + return $this->user; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | 69 | } |
| 70 | 70 | \ No newline at end of file |
@@ -33,15 +33,15 @@ |
||
| 33 | 33 | * @param array $params |
| 34 | 34 | */ |
| 35 | 35 | public function __construct($params) { |
| 36 | - if ( ! isset($params['user']) || ! $params['user'] instanceof User) { |
|
| 36 | + if (!isset($params['user']) || !$params['user'] instanceof User) { |
|
| 37 | 37 | throw new \Exception('missing user object in parameters'); |
| 38 | 38 | } |
| 39 | 39 | $this->user = $params['user']; |
| 40 | 40 | parent::__construct($params); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - public function getId () { |
|
| 44 | - return 'object::user:' . $this->user->getUID(); |
|
| 43 | + public function getId() { |
|
| 44 | + return 'object::user:'.$this->user->getUID(); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -29,52 +29,52 @@ |
||
| 29 | 29 | |
| 30 | 30 | class NoopScanner extends Scanner { |
| 31 | 31 | |
| 32 | - public function __construct(Storage $storage) { |
|
| 33 | - //we don't need the storage, so do nothing here |
|
| 34 | - } |
|
| 32 | + public function __construct(Storage $storage) { |
|
| 33 | + //we don't need the storage, so do nothing here |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * scan a single file and store it in the cache |
|
| 38 | - * |
|
| 39 | - * @param string $file |
|
| 40 | - * @param int $reuseExisting |
|
| 41 | - * @param int $parentId |
|
| 42 | - * @param array|null $cacheData existing data in the cache for the file to be scanned |
|
| 43 | - * @return array an array of metadata of the scanned file |
|
| 44 | - */ |
|
| 45 | - public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) { |
|
| 46 | - return array(); |
|
| 47 | - } |
|
| 36 | + /** |
|
| 37 | + * scan a single file and store it in the cache |
|
| 38 | + * |
|
| 39 | + * @param string $file |
|
| 40 | + * @param int $reuseExisting |
|
| 41 | + * @param int $parentId |
|
| 42 | + * @param array|null $cacheData existing data in the cache for the file to be scanned |
|
| 43 | + * @return array an array of metadata of the scanned file |
|
| 44 | + */ |
|
| 45 | + public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) { |
|
| 46 | + return array(); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * scan a folder and all it's children |
|
| 51 | - * |
|
| 52 | - * @param string $path |
|
| 53 | - * @param bool $recursive |
|
| 54 | - * @param int $reuse |
|
| 55 | - * @return array with the meta data of the scanned file or folder |
|
| 56 | - */ |
|
| 57 | - public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) { |
|
| 58 | - return array(); |
|
| 59 | - } |
|
| 49 | + /** |
|
| 50 | + * scan a folder and all it's children |
|
| 51 | + * |
|
| 52 | + * @param string $path |
|
| 53 | + * @param bool $recursive |
|
| 54 | + * @param int $reuse |
|
| 55 | + * @return array with the meta data of the scanned file or folder |
|
| 56 | + */ |
|
| 57 | + public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) { |
|
| 58 | + return array(); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * scan all the files and folders in a folder |
|
| 63 | - * |
|
| 64 | - * @param string $path |
|
| 65 | - * @param bool $recursive |
|
| 66 | - * @param int $reuse |
|
| 67 | - * @param array $folderData existing cache data for the folder to be scanned |
|
| 68 | - * @return int the size of the scanned folder or -1 if the size is unknown at this stage |
|
| 69 | - */ |
|
| 70 | - protected function scanChildren($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $folderData = null, $lock = true) { |
|
| 71 | - return 0; |
|
| 72 | - } |
|
| 61 | + /** |
|
| 62 | + * scan all the files and folders in a folder |
|
| 63 | + * |
|
| 64 | + * @param string $path |
|
| 65 | + * @param bool $recursive |
|
| 66 | + * @param int $reuse |
|
| 67 | + * @param array $folderData existing cache data for the folder to be scanned |
|
| 68 | + * @return int the size of the scanned folder or -1 if the size is unknown at this stage |
|
| 69 | + */ |
|
| 70 | + protected function scanChildren($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $folderData = null, $lock = true) { |
|
| 71 | + return 0; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * walk over any folders that are not fully scanned yet and scan them |
|
| 76 | - */ |
|
| 77 | - public function backgroundScan() { |
|
| 78 | - //noop |
|
| 79 | - } |
|
| 74 | + /** |
|
| 75 | + * walk over any folders that are not fully scanned yet and scan them |
|
| 76 | + */ |
|
| 77 | + public function backgroundScan() { |
|
| 78 | + //noop |
|
| 79 | + } |
|
| 80 | 80 | } |
@@ -135,7 +135,7 @@ |
||
| 135 | 135 | |
| 136 | 136 | $stream = $objectContent->getStream(); |
| 137 | 137 | // save the object content in the context of the stream to prevent it being gc'd until the stream is closed |
| 138 | - stream_context_set_option($stream, 'swift','content', $objectContent); |
|
| 138 | + stream_context_set_option($stream, 'swift', 'content', $objectContent); |
|
| 139 | 139 | |
| 140 | 140 | return $stream; |
| 141 | 141 | } |
@@ -30,126 +30,126 @@ |
||
| 30 | 30 | use OpenCloud\Rackspace; |
| 31 | 31 | |
| 32 | 32 | class Swift implements IObjectStore { |
| 33 | - /** |
|
| 34 | - * @var \OpenCloud\OpenStack |
|
| 35 | - */ |
|
| 36 | - private $client; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 41 | - private $params; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var \OpenCloud\ObjectStore\Service |
|
| 45 | - */ |
|
| 46 | - private $objectStoreService; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var \OpenCloud\ObjectStore\Resource\Container |
|
| 50 | - */ |
|
| 51 | - private $container; |
|
| 52 | - |
|
| 53 | - public function __construct($params) { |
|
| 54 | - if (!isset($params['container'])) { |
|
| 55 | - $params['container'] = 'owncloud'; |
|
| 56 | - } |
|
| 57 | - if (!isset($params['autocreate'])) { |
|
| 58 | - // should only be true for tests |
|
| 59 | - $params['autocreate'] = false; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - if (isset($params['apiKey'])) { |
|
| 63 | - $this->client = new Rackspace($params['url'], $params); |
|
| 64 | - } else { |
|
| 65 | - $this->client = new OpenStack($params['url'], $params); |
|
| 66 | - } |
|
| 67 | - $this->params = $params; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - protected function init() { |
|
| 71 | - if ($this->container) { |
|
| 72 | - return; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // the OpenCloud client library will default to 'cloudFiles' if $serviceName is null |
|
| 76 | - $serviceName = null; |
|
| 77 | - if (isset($this->params['serviceName'])) { |
|
| 78 | - $serviceName = $this->params['serviceName']; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - // the OpenCloud client library will default to 'publicURL' if $urlType is null |
|
| 82 | - $urlType = null; |
|
| 83 | - if (isset($this->params['urlType'])) { |
|
| 84 | - $urlType = $this->params['urlType']; |
|
| 85 | - } |
|
| 86 | - $this->objectStoreService = $this->client->objectStoreService($serviceName, $this->params['region'], $urlType); |
|
| 87 | - |
|
| 88 | - try { |
|
| 89 | - $this->container = $this->objectStoreService->getContainer($this->params['container']); |
|
| 90 | - } catch (ClientErrorResponseException $ex) { |
|
| 91 | - // if the container does not exist and autocreate is true try to create the container on the fly |
|
| 92 | - if (isset($this->params['autocreate']) && $this->params['autocreate'] === true) { |
|
| 93 | - $this->container = $this->objectStoreService->createContainer($this->params['container']); |
|
| 94 | - } else { |
|
| 95 | - throw $ex; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @return string the container name where objects are stored |
|
| 102 | - */ |
|
| 103 | - public function getStorageId() { |
|
| 104 | - return $this->params['container']; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param string $urn the unified resource name used to identify the object |
|
| 109 | - * @param resource $stream stream with the data to write |
|
| 110 | - * @throws Exception from openstack lib when something goes wrong |
|
| 111 | - */ |
|
| 112 | - public function writeObject($urn, $stream) { |
|
| 113 | - $this->init(); |
|
| 114 | - $this->container->uploadObject($urn, $stream); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @param string $urn the unified resource name used to identify the object |
|
| 119 | - * @return resource stream with the read data |
|
| 120 | - * @throws Exception from openstack lib when something goes wrong |
|
| 121 | - */ |
|
| 122 | - public function readObject($urn) { |
|
| 123 | - $this->init(); |
|
| 124 | - $object = $this->container->getObject($urn); |
|
| 125 | - |
|
| 126 | - // we need to keep a reference to objectContent or |
|
| 127 | - // the stream will be closed before we can do anything with it |
|
| 128 | - /** @var $objectContent \Guzzle\Http\EntityBody * */ |
|
| 129 | - $objectContent = $object->getContent(); |
|
| 130 | - $objectContent->rewind(); |
|
| 131 | - |
|
| 132 | - $stream = $objectContent->getStream(); |
|
| 133 | - // save the object content in the context of the stream to prevent it being gc'd until the stream is closed |
|
| 134 | - stream_context_set_option($stream, 'swift','content', $objectContent); |
|
| 135 | - |
|
| 136 | - return $stream; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param string $urn Unified Resource Name |
|
| 141 | - * @return void |
|
| 142 | - * @throws Exception from openstack lib when something goes wrong |
|
| 143 | - */ |
|
| 144 | - public function deleteObject($urn) { |
|
| 145 | - $this->init(); |
|
| 146 | - // see https://github.com/rackspace/php-opencloud/issues/243#issuecomment-30032242 |
|
| 147 | - $this->container->dataObject()->setName($urn)->delete(); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - public function deleteContainer($recursive = false) { |
|
| 151 | - $this->init(); |
|
| 152 | - $this->container->delete($recursive); |
|
| 153 | - } |
|
| 33 | + /** |
|
| 34 | + * @var \OpenCloud\OpenStack |
|
| 35 | + */ |
|
| 36 | + private $client; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | + private $params; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var \OpenCloud\ObjectStore\Service |
|
| 45 | + */ |
|
| 46 | + private $objectStoreService; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var \OpenCloud\ObjectStore\Resource\Container |
|
| 50 | + */ |
|
| 51 | + private $container; |
|
| 52 | + |
|
| 53 | + public function __construct($params) { |
|
| 54 | + if (!isset($params['container'])) { |
|
| 55 | + $params['container'] = 'owncloud'; |
|
| 56 | + } |
|
| 57 | + if (!isset($params['autocreate'])) { |
|
| 58 | + // should only be true for tests |
|
| 59 | + $params['autocreate'] = false; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + if (isset($params['apiKey'])) { |
|
| 63 | + $this->client = new Rackspace($params['url'], $params); |
|
| 64 | + } else { |
|
| 65 | + $this->client = new OpenStack($params['url'], $params); |
|
| 66 | + } |
|
| 67 | + $this->params = $params; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + protected function init() { |
|
| 71 | + if ($this->container) { |
|
| 72 | + return; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // the OpenCloud client library will default to 'cloudFiles' if $serviceName is null |
|
| 76 | + $serviceName = null; |
|
| 77 | + if (isset($this->params['serviceName'])) { |
|
| 78 | + $serviceName = $this->params['serviceName']; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + // the OpenCloud client library will default to 'publicURL' if $urlType is null |
|
| 82 | + $urlType = null; |
|
| 83 | + if (isset($this->params['urlType'])) { |
|
| 84 | + $urlType = $this->params['urlType']; |
|
| 85 | + } |
|
| 86 | + $this->objectStoreService = $this->client->objectStoreService($serviceName, $this->params['region'], $urlType); |
|
| 87 | + |
|
| 88 | + try { |
|
| 89 | + $this->container = $this->objectStoreService->getContainer($this->params['container']); |
|
| 90 | + } catch (ClientErrorResponseException $ex) { |
|
| 91 | + // if the container does not exist and autocreate is true try to create the container on the fly |
|
| 92 | + if (isset($this->params['autocreate']) && $this->params['autocreate'] === true) { |
|
| 93 | + $this->container = $this->objectStoreService->createContainer($this->params['container']); |
|
| 94 | + } else { |
|
| 95 | + throw $ex; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @return string the container name where objects are stored |
|
| 102 | + */ |
|
| 103 | + public function getStorageId() { |
|
| 104 | + return $this->params['container']; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param string $urn the unified resource name used to identify the object |
|
| 109 | + * @param resource $stream stream with the data to write |
|
| 110 | + * @throws Exception from openstack lib when something goes wrong |
|
| 111 | + */ |
|
| 112 | + public function writeObject($urn, $stream) { |
|
| 113 | + $this->init(); |
|
| 114 | + $this->container->uploadObject($urn, $stream); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @param string $urn the unified resource name used to identify the object |
|
| 119 | + * @return resource stream with the read data |
|
| 120 | + * @throws Exception from openstack lib when something goes wrong |
|
| 121 | + */ |
|
| 122 | + public function readObject($urn) { |
|
| 123 | + $this->init(); |
|
| 124 | + $object = $this->container->getObject($urn); |
|
| 125 | + |
|
| 126 | + // we need to keep a reference to objectContent or |
|
| 127 | + // the stream will be closed before we can do anything with it |
|
| 128 | + /** @var $objectContent \Guzzle\Http\EntityBody * */ |
|
| 129 | + $objectContent = $object->getContent(); |
|
| 130 | + $objectContent->rewind(); |
|
| 131 | + |
|
| 132 | + $stream = $objectContent->getStream(); |
|
| 133 | + // save the object content in the context of the stream to prevent it being gc'd until the stream is closed |
|
| 134 | + stream_context_set_option($stream, 'swift','content', $objectContent); |
|
| 135 | + |
|
| 136 | + return $stream; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param string $urn Unified Resource Name |
|
| 141 | + * @return void |
|
| 142 | + * @throws Exception from openstack lib when something goes wrong |
|
| 143 | + */ |
|
| 144 | + public function deleteObject($urn) { |
|
| 145 | + $this->init(); |
|
| 146 | + // see https://github.com/rackspace/php-opencloud/issues/243#issuecomment-30032242 |
|
| 147 | + $this->container->dataObject()->setName($urn)->delete(); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + public function deleteContainer($recursive = false) { |
|
| 151 | + $this->init(); |
|
| 152 | + $this->container->delete($recursive); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | 155 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | // Update the alternative mimetypes to avoid having to look them up each time. |
| 104 | 104 | foreach ($this->mimetypes as $mimeType) { |
| 105 | - $this->secureMimeTypes[$mimeType[0]] = isset($mimeType[1]) ? $mimeType[1]: $mimeType[0]; |
|
| 105 | + $this->secureMimeTypes[$mimeType[0]] = isset($mimeType[1]) ? $mimeType[1] : $mimeType[0]; |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | |
@@ -114,10 +114,10 @@ discard block |
||
| 114 | 114 | return; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - $this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypealiases.dist.json'), true); |
|
| 117 | + $this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir.'/mimetypealiases.dist.json'), true); |
|
| 118 | 118 | |
| 119 | - if (file_exists($this->customConfigDir . '/mimetypealiases.json')) { |
|
| 120 | - $custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypealiases.json'), true); |
|
| 119 | + if (file_exists($this->customConfigDir.'/mimetypealiases.json')) { |
|
| 120 | + $custom = json_decode(file_get_contents($this->customConfigDir.'/mimetypealiases.json'), true); |
|
| 121 | 121 | $this->mimeTypeAlias = array_merge($this->mimeTypeAlias, $custom); |
| 122 | 122 | } |
| 123 | 123 | } |
@@ -138,11 +138,11 @@ discard block |
||
| 138 | 138 | return; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - $mimetypeMapping = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypemapping.dist.json'), true); |
|
| 141 | + $mimetypeMapping = json_decode(file_get_contents($this->defaultConfigDir.'/mimetypemapping.dist.json'), true); |
|
| 142 | 142 | |
| 143 | 143 | //Check if need to load custom mappings |
| 144 | - if (file_exists($this->customConfigDir . '/mimetypemapping.json')) { |
|
| 145 | - $custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypemapping.json'), true); |
|
| 144 | + if (file_exists($this->customConfigDir.'/mimetypemapping.json')) { |
|
| 145 | + $custom = json_decode(file_get_contents($this->customConfigDir.'/mimetypemapping.json'), true); |
|
| 146 | 146 | $mimetypeMapping = array_merge($mimetypeMapping, $custom); |
| 147 | 147 | } |
| 148 | 148 | |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | |
| 307 | 307 | // Icon exists? |
| 308 | 308 | try { |
| 309 | - $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $icon . '.svg'); |
|
| 309 | + $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/'.$icon.'.svg'); |
|
| 310 | 310 | return $this->mimetypeIcons[$mimetype]; |
| 311 | 311 | } catch (\RuntimeException $e) { |
| 312 | 312 | // Specified image not found |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | // Try only the first part of the filetype |
| 316 | 316 | $mimePart = substr($icon, 0, strpos($icon, '-')); |
| 317 | 317 | try { |
| 318 | - $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $mimePart . '.svg'); |
|
| 318 | + $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/'.$mimePart.'.svg'); |
|
| 319 | 319 | return $this->mimetypeIcons[$mimetype]; |
| 320 | 320 | } catch (\RuntimeException $e) { |
| 321 | 321 | // Image for the first part of the mimetype not found |
@@ -41,283 +41,283 @@ |
||
| 41 | 41 | * @package OC\Files\Type |
| 42 | 42 | */ |
| 43 | 43 | class Detection implements IMimeTypeDetector { |
| 44 | - protected $mimetypes = []; |
|
| 45 | - protected $secureMimeTypes = []; |
|
| 46 | - |
|
| 47 | - protected $mimetypeIcons = []; |
|
| 48 | - /** @var string[] */ |
|
| 49 | - protected $mimeTypeAlias = []; |
|
| 50 | - |
|
| 51 | - /** @var IURLGenerator */ |
|
| 52 | - private $urlGenerator; |
|
| 53 | - |
|
| 54 | - /** @var string */ |
|
| 55 | - private $customConfigDir; |
|
| 56 | - |
|
| 57 | - /** @var string */ |
|
| 58 | - private $defaultConfigDir; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @param IURLGenerator $urlGenerator |
|
| 62 | - * @param string $customConfigDir |
|
| 63 | - * @param string $defaultConfigDir |
|
| 64 | - */ |
|
| 65 | - public function __construct(IURLGenerator $urlGenerator, |
|
| 66 | - $customConfigDir, |
|
| 67 | - $defaultConfigDir) { |
|
| 68 | - $this->urlGenerator = $urlGenerator; |
|
| 69 | - $this->customConfigDir = $customConfigDir; |
|
| 70 | - $this->defaultConfigDir = $defaultConfigDir; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Add an extension -> mimetype mapping |
|
| 75 | - * |
|
| 76 | - * $mimetype is the assumed correct mime type |
|
| 77 | - * The optional $secureMimeType is an alternative to send to send |
|
| 78 | - * to avoid potential XSS. |
|
| 79 | - * |
|
| 80 | - * @param string $extension |
|
| 81 | - * @param string $mimetype |
|
| 82 | - * @param string|null $secureMimeType |
|
| 83 | - */ |
|
| 84 | - public function registerType($extension, |
|
| 85 | - $mimetype, |
|
| 86 | - $secureMimeType = null) { |
|
| 87 | - $this->mimetypes[$extension] = array($mimetype, $secureMimeType); |
|
| 88 | - $this->secureMimeTypes[$mimetype] = $secureMimeType ?: $mimetype; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Add an array of extension -> mimetype mappings |
|
| 93 | - * |
|
| 94 | - * The mimetype value is in itself an array where the first index is |
|
| 95 | - * the assumed correct mimetype and the second is either a secure alternative |
|
| 96 | - * or null if the correct is considered secure. |
|
| 97 | - * |
|
| 98 | - * @param array $types |
|
| 99 | - */ |
|
| 100 | - public function registerTypeArray($types) { |
|
| 101 | - $this->mimetypes = array_merge($this->mimetypes, $types); |
|
| 102 | - |
|
| 103 | - // Update the alternative mimetypes to avoid having to look them up each time. |
|
| 104 | - foreach ($this->mimetypes as $mimeType) { |
|
| 105 | - $this->secureMimeTypes[$mimeType[0]] = isset($mimeType[1]) ? $mimeType[1]: $mimeType[0]; |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Add the mimetype aliases if they are not yet present |
|
| 111 | - */ |
|
| 112 | - private function loadAliases() { |
|
| 113 | - if (!empty($this->mimeTypeAlias)) { |
|
| 114 | - return; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypealiases.dist.json'), true); |
|
| 118 | - |
|
| 119 | - if (file_exists($this->customConfigDir . '/mimetypealiases.json')) { |
|
| 120 | - $custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypealiases.json'), true); |
|
| 121 | - $this->mimeTypeAlias = array_merge($this->mimeTypeAlias, $custom); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @return string[] |
|
| 127 | - */ |
|
| 128 | - public function getAllAliases() { |
|
| 129 | - $this->loadAliases(); |
|
| 130 | - return $this->mimeTypeAlias; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Add mimetype mappings if they are not yet present |
|
| 135 | - */ |
|
| 136 | - private function loadMappings() { |
|
| 137 | - if (!empty($this->mimetypes)) { |
|
| 138 | - return; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - $mimetypeMapping = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypemapping.dist.json'), true); |
|
| 142 | - |
|
| 143 | - //Check if need to load custom mappings |
|
| 144 | - if (file_exists($this->customConfigDir . '/mimetypemapping.json')) { |
|
| 145 | - $custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypemapping.json'), true); |
|
| 146 | - $mimetypeMapping = array_merge($mimetypeMapping, $custom); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $this->registerTypeArray($mimetypeMapping); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @return array |
|
| 154 | - */ |
|
| 155 | - public function getAllMappings() { |
|
| 156 | - $this->loadMappings(); |
|
| 157 | - return $this->mimetypes; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * detect mimetype only based on filename, content of file is not used |
|
| 162 | - * |
|
| 163 | - * @param string $path |
|
| 164 | - * @return string |
|
| 165 | - */ |
|
| 166 | - public function detectPath($path) { |
|
| 167 | - $this->loadMappings(); |
|
| 168 | - |
|
| 169 | - $fileName = basename($path); |
|
| 170 | - // note: leading dot doesn't qualify as extension |
|
| 171 | - if (strpos($fileName, '.') > 0) { |
|
| 172 | - //try to guess the type by the file extension |
|
| 173 | - $extension = strtolower(strrchr($fileName, '.')); |
|
| 174 | - $extension = substr($extension, 1); //remove leading . |
|
| 175 | - return (isset($this->mimetypes[$extension]) && isset($this->mimetypes[$extension][0])) |
|
| 176 | - ? $this->mimetypes[$extension][0] |
|
| 177 | - : 'application/octet-stream'; |
|
| 178 | - } else { |
|
| 179 | - return 'application/octet-stream'; |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * detect mimetype based on both filename and content |
|
| 185 | - * |
|
| 186 | - * @param string $path |
|
| 187 | - * @return string |
|
| 188 | - */ |
|
| 189 | - public function detect($path) { |
|
| 190 | - $this->loadMappings(); |
|
| 191 | - |
|
| 192 | - if (@is_dir($path)) { |
|
| 193 | - // directories are easy |
|
| 194 | - return "httpd/unix-directory"; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - $mimeType = $this->detectPath($path); |
|
| 198 | - |
|
| 199 | - if ($mimeType === 'application/octet-stream' and function_exists('finfo_open') |
|
| 200 | - and function_exists('finfo_file') and $finfo = finfo_open(FILEINFO_MIME) |
|
| 201 | - ) { |
|
| 202 | - $info = @strtolower(finfo_file($finfo, $path)); |
|
| 203 | - finfo_close($finfo); |
|
| 204 | - if ($info) { |
|
| 205 | - $mimeType = strpos($info, ';') !== false ? substr($info, 0, strpos($info, ';')) : $info; |
|
| 206 | - return empty($mimeType) ? 'application/octet-stream' : $mimeType; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - } |
|
| 210 | - $isWrapped = (strpos($path, '://') !== false) and (substr($path, 0, 7) === 'file://'); |
|
| 211 | - if (!$isWrapped and $mimeType === 'application/octet-stream' && function_exists("mime_content_type")) { |
|
| 212 | - // use mime magic extension if available |
|
| 213 | - $mimeType = mime_content_type($path); |
|
| 214 | - } |
|
| 215 | - if (!$isWrapped and $mimeType === 'application/octet-stream' && \OC_Helper::canExecute("file")) { |
|
| 216 | - // it looks like we have a 'file' command, |
|
| 217 | - // lets see if it does have mime support |
|
| 218 | - $path = escapeshellarg($path); |
|
| 219 | - $fp = popen("file -b --mime-type $path 2>/dev/null", "r"); |
|
| 220 | - $reply = fgets($fp); |
|
| 221 | - pclose($fp); |
|
| 222 | - |
|
| 223 | - //trim the newline |
|
| 224 | - $mimeType = trim($reply); |
|
| 225 | - |
|
| 226 | - if (empty($mimeType)) { |
|
| 227 | - $mimeType = 'application/octet-stream'; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - } |
|
| 231 | - return $mimeType; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * detect mimetype based on the content of a string |
|
| 236 | - * |
|
| 237 | - * @param string $data |
|
| 238 | - * @return string |
|
| 239 | - */ |
|
| 240 | - public function detectString($data) { |
|
| 241 | - if (function_exists('finfo_open') and function_exists('finfo_file')) { |
|
| 242 | - $finfo = finfo_open(FILEINFO_MIME); |
|
| 243 | - $info = finfo_buffer($finfo, $data); |
|
| 244 | - return strpos($info, ';') !== false ? substr($info, 0, strpos($info, ';')) : $info; |
|
| 245 | - } else { |
|
| 246 | - $tmpFile = \OC::$server->getTempManager()->getTemporaryFile(); |
|
| 247 | - $fh = fopen($tmpFile, 'wb'); |
|
| 248 | - fwrite($fh, $data, 8024); |
|
| 249 | - fclose($fh); |
|
| 250 | - $mime = $this->detect($tmpFile); |
|
| 251 | - unset($tmpFile); |
|
| 252 | - return $mime; |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * Get a secure mimetype that won't expose potential XSS. |
|
| 258 | - * |
|
| 259 | - * @param string $mimeType |
|
| 260 | - * @return string |
|
| 261 | - */ |
|
| 262 | - public function getSecureMimeType($mimeType) { |
|
| 263 | - $this->loadMappings(); |
|
| 264 | - |
|
| 265 | - return isset($this->secureMimeTypes[$mimeType]) |
|
| 266 | - ? $this->secureMimeTypes[$mimeType] |
|
| 267 | - : 'application/octet-stream'; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Get path to the icon of a file type |
|
| 272 | - * @param string $mimetype the MIME type |
|
| 273 | - * @return string the url |
|
| 274 | - */ |
|
| 275 | - public function mimeTypeIcon($mimetype) { |
|
| 276 | - $this->loadAliases(); |
|
| 277 | - |
|
| 278 | - while (isset($this->mimeTypeAlias[$mimetype])) { |
|
| 279 | - $mimetype = $this->mimeTypeAlias[$mimetype]; |
|
| 280 | - } |
|
| 281 | - if (isset($this->mimetypeIcons[$mimetype])) { |
|
| 282 | - return $this->mimetypeIcons[$mimetype]; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - // Replace slash and backslash with a minus |
|
| 286 | - $icon = str_replace('/', '-', $mimetype); |
|
| 287 | - $icon = str_replace('\\', '-', $icon); |
|
| 288 | - |
|
| 289 | - // Is it a dir? |
|
| 290 | - if ($mimetype === 'dir') { |
|
| 291 | - $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder.svg'); |
|
| 292 | - return $this->mimetypeIcons[$mimetype]; |
|
| 293 | - } |
|
| 294 | - if ($mimetype === 'dir-shared') { |
|
| 295 | - $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder-shared.svg'); |
|
| 296 | - return $this->mimetypeIcons[$mimetype]; |
|
| 297 | - } |
|
| 298 | - if ($mimetype === 'dir-external') { |
|
| 299 | - $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder-external.svg'); |
|
| 300 | - return $this->mimetypeIcons[$mimetype]; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - // Icon exists? |
|
| 304 | - try { |
|
| 305 | - $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $icon . '.svg'); |
|
| 306 | - return $this->mimetypeIcons[$mimetype]; |
|
| 307 | - } catch (\RuntimeException $e) { |
|
| 308 | - // Specified image not found |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - // Try only the first part of the filetype |
|
| 312 | - $mimePart = substr($icon, 0, strpos($icon, '-')); |
|
| 313 | - try { |
|
| 314 | - $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $mimePart . '.svg'); |
|
| 315 | - return $this->mimetypeIcons[$mimetype]; |
|
| 316 | - } catch (\RuntimeException $e) { |
|
| 317 | - // Image for the first part of the mimetype not found |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/file.svg'); |
|
| 321 | - return $this->mimetypeIcons[$mimetype]; |
|
| 322 | - } |
|
| 44 | + protected $mimetypes = []; |
|
| 45 | + protected $secureMimeTypes = []; |
|
| 46 | + |
|
| 47 | + protected $mimetypeIcons = []; |
|
| 48 | + /** @var string[] */ |
|
| 49 | + protected $mimeTypeAlias = []; |
|
| 50 | + |
|
| 51 | + /** @var IURLGenerator */ |
|
| 52 | + private $urlGenerator; |
|
| 53 | + |
|
| 54 | + /** @var string */ |
|
| 55 | + private $customConfigDir; |
|
| 56 | + |
|
| 57 | + /** @var string */ |
|
| 58 | + private $defaultConfigDir; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @param IURLGenerator $urlGenerator |
|
| 62 | + * @param string $customConfigDir |
|
| 63 | + * @param string $defaultConfigDir |
|
| 64 | + */ |
|
| 65 | + public function __construct(IURLGenerator $urlGenerator, |
|
| 66 | + $customConfigDir, |
|
| 67 | + $defaultConfigDir) { |
|
| 68 | + $this->urlGenerator = $urlGenerator; |
|
| 69 | + $this->customConfigDir = $customConfigDir; |
|
| 70 | + $this->defaultConfigDir = $defaultConfigDir; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Add an extension -> mimetype mapping |
|
| 75 | + * |
|
| 76 | + * $mimetype is the assumed correct mime type |
|
| 77 | + * The optional $secureMimeType is an alternative to send to send |
|
| 78 | + * to avoid potential XSS. |
|
| 79 | + * |
|
| 80 | + * @param string $extension |
|
| 81 | + * @param string $mimetype |
|
| 82 | + * @param string|null $secureMimeType |
|
| 83 | + */ |
|
| 84 | + public function registerType($extension, |
|
| 85 | + $mimetype, |
|
| 86 | + $secureMimeType = null) { |
|
| 87 | + $this->mimetypes[$extension] = array($mimetype, $secureMimeType); |
|
| 88 | + $this->secureMimeTypes[$mimetype] = $secureMimeType ?: $mimetype; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Add an array of extension -> mimetype mappings |
|
| 93 | + * |
|
| 94 | + * The mimetype value is in itself an array where the first index is |
|
| 95 | + * the assumed correct mimetype and the second is either a secure alternative |
|
| 96 | + * or null if the correct is considered secure. |
|
| 97 | + * |
|
| 98 | + * @param array $types |
|
| 99 | + */ |
|
| 100 | + public function registerTypeArray($types) { |
|
| 101 | + $this->mimetypes = array_merge($this->mimetypes, $types); |
|
| 102 | + |
|
| 103 | + // Update the alternative mimetypes to avoid having to look them up each time. |
|
| 104 | + foreach ($this->mimetypes as $mimeType) { |
|
| 105 | + $this->secureMimeTypes[$mimeType[0]] = isset($mimeType[1]) ? $mimeType[1]: $mimeType[0]; |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Add the mimetype aliases if they are not yet present |
|
| 111 | + */ |
|
| 112 | + private function loadAliases() { |
|
| 113 | + if (!empty($this->mimeTypeAlias)) { |
|
| 114 | + return; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypealiases.dist.json'), true); |
|
| 118 | + |
|
| 119 | + if (file_exists($this->customConfigDir . '/mimetypealiases.json')) { |
|
| 120 | + $custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypealiases.json'), true); |
|
| 121 | + $this->mimeTypeAlias = array_merge($this->mimeTypeAlias, $custom); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @return string[] |
|
| 127 | + */ |
|
| 128 | + public function getAllAliases() { |
|
| 129 | + $this->loadAliases(); |
|
| 130 | + return $this->mimeTypeAlias; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Add mimetype mappings if they are not yet present |
|
| 135 | + */ |
|
| 136 | + private function loadMappings() { |
|
| 137 | + if (!empty($this->mimetypes)) { |
|
| 138 | + return; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + $mimetypeMapping = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypemapping.dist.json'), true); |
|
| 142 | + |
|
| 143 | + //Check if need to load custom mappings |
|
| 144 | + if (file_exists($this->customConfigDir . '/mimetypemapping.json')) { |
|
| 145 | + $custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypemapping.json'), true); |
|
| 146 | + $mimetypeMapping = array_merge($mimetypeMapping, $custom); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $this->registerTypeArray($mimetypeMapping); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @return array |
|
| 154 | + */ |
|
| 155 | + public function getAllMappings() { |
|
| 156 | + $this->loadMappings(); |
|
| 157 | + return $this->mimetypes; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * detect mimetype only based on filename, content of file is not used |
|
| 162 | + * |
|
| 163 | + * @param string $path |
|
| 164 | + * @return string |
|
| 165 | + */ |
|
| 166 | + public function detectPath($path) { |
|
| 167 | + $this->loadMappings(); |
|
| 168 | + |
|
| 169 | + $fileName = basename($path); |
|
| 170 | + // note: leading dot doesn't qualify as extension |
|
| 171 | + if (strpos($fileName, '.') > 0) { |
|
| 172 | + //try to guess the type by the file extension |
|
| 173 | + $extension = strtolower(strrchr($fileName, '.')); |
|
| 174 | + $extension = substr($extension, 1); //remove leading . |
|
| 175 | + return (isset($this->mimetypes[$extension]) && isset($this->mimetypes[$extension][0])) |
|
| 176 | + ? $this->mimetypes[$extension][0] |
|
| 177 | + : 'application/octet-stream'; |
|
| 178 | + } else { |
|
| 179 | + return 'application/octet-stream'; |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * detect mimetype based on both filename and content |
|
| 185 | + * |
|
| 186 | + * @param string $path |
|
| 187 | + * @return string |
|
| 188 | + */ |
|
| 189 | + public function detect($path) { |
|
| 190 | + $this->loadMappings(); |
|
| 191 | + |
|
| 192 | + if (@is_dir($path)) { |
|
| 193 | + // directories are easy |
|
| 194 | + return "httpd/unix-directory"; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + $mimeType = $this->detectPath($path); |
|
| 198 | + |
|
| 199 | + if ($mimeType === 'application/octet-stream' and function_exists('finfo_open') |
|
| 200 | + and function_exists('finfo_file') and $finfo = finfo_open(FILEINFO_MIME) |
|
| 201 | + ) { |
|
| 202 | + $info = @strtolower(finfo_file($finfo, $path)); |
|
| 203 | + finfo_close($finfo); |
|
| 204 | + if ($info) { |
|
| 205 | + $mimeType = strpos($info, ';') !== false ? substr($info, 0, strpos($info, ';')) : $info; |
|
| 206 | + return empty($mimeType) ? 'application/octet-stream' : $mimeType; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + } |
|
| 210 | + $isWrapped = (strpos($path, '://') !== false) and (substr($path, 0, 7) === 'file://'); |
|
| 211 | + if (!$isWrapped and $mimeType === 'application/octet-stream' && function_exists("mime_content_type")) { |
|
| 212 | + // use mime magic extension if available |
|
| 213 | + $mimeType = mime_content_type($path); |
|
| 214 | + } |
|
| 215 | + if (!$isWrapped and $mimeType === 'application/octet-stream' && \OC_Helper::canExecute("file")) { |
|
| 216 | + // it looks like we have a 'file' command, |
|
| 217 | + // lets see if it does have mime support |
|
| 218 | + $path = escapeshellarg($path); |
|
| 219 | + $fp = popen("file -b --mime-type $path 2>/dev/null", "r"); |
|
| 220 | + $reply = fgets($fp); |
|
| 221 | + pclose($fp); |
|
| 222 | + |
|
| 223 | + //trim the newline |
|
| 224 | + $mimeType = trim($reply); |
|
| 225 | + |
|
| 226 | + if (empty($mimeType)) { |
|
| 227 | + $mimeType = 'application/octet-stream'; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + } |
|
| 231 | + return $mimeType; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * detect mimetype based on the content of a string |
|
| 236 | + * |
|
| 237 | + * @param string $data |
|
| 238 | + * @return string |
|
| 239 | + */ |
|
| 240 | + public function detectString($data) { |
|
| 241 | + if (function_exists('finfo_open') and function_exists('finfo_file')) { |
|
| 242 | + $finfo = finfo_open(FILEINFO_MIME); |
|
| 243 | + $info = finfo_buffer($finfo, $data); |
|
| 244 | + return strpos($info, ';') !== false ? substr($info, 0, strpos($info, ';')) : $info; |
|
| 245 | + } else { |
|
| 246 | + $tmpFile = \OC::$server->getTempManager()->getTemporaryFile(); |
|
| 247 | + $fh = fopen($tmpFile, 'wb'); |
|
| 248 | + fwrite($fh, $data, 8024); |
|
| 249 | + fclose($fh); |
|
| 250 | + $mime = $this->detect($tmpFile); |
|
| 251 | + unset($tmpFile); |
|
| 252 | + return $mime; |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * Get a secure mimetype that won't expose potential XSS. |
|
| 258 | + * |
|
| 259 | + * @param string $mimeType |
|
| 260 | + * @return string |
|
| 261 | + */ |
|
| 262 | + public function getSecureMimeType($mimeType) { |
|
| 263 | + $this->loadMappings(); |
|
| 264 | + |
|
| 265 | + return isset($this->secureMimeTypes[$mimeType]) |
|
| 266 | + ? $this->secureMimeTypes[$mimeType] |
|
| 267 | + : 'application/octet-stream'; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Get path to the icon of a file type |
|
| 272 | + * @param string $mimetype the MIME type |
|
| 273 | + * @return string the url |
|
| 274 | + */ |
|
| 275 | + public function mimeTypeIcon($mimetype) { |
|
| 276 | + $this->loadAliases(); |
|
| 277 | + |
|
| 278 | + while (isset($this->mimeTypeAlias[$mimetype])) { |
|
| 279 | + $mimetype = $this->mimeTypeAlias[$mimetype]; |
|
| 280 | + } |
|
| 281 | + if (isset($this->mimetypeIcons[$mimetype])) { |
|
| 282 | + return $this->mimetypeIcons[$mimetype]; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + // Replace slash and backslash with a minus |
|
| 286 | + $icon = str_replace('/', '-', $mimetype); |
|
| 287 | + $icon = str_replace('\\', '-', $icon); |
|
| 288 | + |
|
| 289 | + // Is it a dir? |
|
| 290 | + if ($mimetype === 'dir') { |
|
| 291 | + $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder.svg'); |
|
| 292 | + return $this->mimetypeIcons[$mimetype]; |
|
| 293 | + } |
|
| 294 | + if ($mimetype === 'dir-shared') { |
|
| 295 | + $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder-shared.svg'); |
|
| 296 | + return $this->mimetypeIcons[$mimetype]; |
|
| 297 | + } |
|
| 298 | + if ($mimetype === 'dir-external') { |
|
| 299 | + $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder-external.svg'); |
|
| 300 | + return $this->mimetypeIcons[$mimetype]; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + // Icon exists? |
|
| 304 | + try { |
|
| 305 | + $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $icon . '.svg'); |
|
| 306 | + return $this->mimetypeIcons[$mimetype]; |
|
| 307 | + } catch (\RuntimeException $e) { |
|
| 308 | + // Specified image not found |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + // Try only the first part of the filetype |
|
| 312 | + $mimePart = substr($icon, 0, strpos($icon, '-')); |
|
| 313 | + try { |
|
| 314 | + $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $mimePart . '.svg'); |
|
| 315 | + return $this->mimetypeIcons[$mimetype]; |
|
| 316 | + } catch (\RuntimeException $e) { |
|
| 317 | + // Image for the first part of the mimetype not found |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/file.svg'); |
|
| 321 | + return $this->mimetypeIcons[$mimetype]; |
|
| 322 | + } |
|
| 323 | 323 | } |
@@ -25,38 +25,38 @@ |
||
| 25 | 25 | namespace OC\Files\Type; |
| 26 | 26 | |
| 27 | 27 | class TemplateManager { |
| 28 | - protected $templates = array(); |
|
| 28 | + protected $templates = array(); |
|
| 29 | 29 | |
| 30 | - public function registerTemplate($mimetype, $path) { |
|
| 31 | - $this->templates[$mimetype] = $path; |
|
| 32 | - } |
|
| 30 | + public function registerTemplate($mimetype, $path) { |
|
| 31 | + $this->templates[$mimetype] = $path; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * get the path of the template for a mimetype |
|
| 36 | - * |
|
| 37 | - * @param string $mimetype |
|
| 38 | - * @return string|null |
|
| 39 | - */ |
|
| 40 | - public function getTemplatePath($mimetype) { |
|
| 41 | - if (isset($this->templates[$mimetype])) { |
|
| 42 | - return $this->templates[$mimetype]; |
|
| 43 | - } else { |
|
| 44 | - return null; |
|
| 45 | - } |
|
| 46 | - } |
|
| 34 | + /** |
|
| 35 | + * get the path of the template for a mimetype |
|
| 36 | + * |
|
| 37 | + * @param string $mimetype |
|
| 38 | + * @return string|null |
|
| 39 | + */ |
|
| 40 | + public function getTemplatePath($mimetype) { |
|
| 41 | + if (isset($this->templates[$mimetype])) { |
|
| 42 | + return $this->templates[$mimetype]; |
|
| 43 | + } else { |
|
| 44 | + return null; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * get the template content for a mimetype |
|
| 50 | - * |
|
| 51 | - * @param string $mimetype |
|
| 52 | - * @return string |
|
| 53 | - */ |
|
| 54 | - public function getTemplate($mimetype) { |
|
| 55 | - $path = $this->getTemplatePath($mimetype); |
|
| 56 | - if ($path) { |
|
| 57 | - return file_get_contents($path); |
|
| 58 | - } else { |
|
| 59 | - return ''; |
|
| 60 | - } |
|
| 61 | - } |
|
| 48 | + /** |
|
| 49 | + * get the template content for a mimetype |
|
| 50 | + * |
|
| 51 | + * @param string $mimetype |
|
| 52 | + * @return string |
|
| 53 | + */ |
|
| 54 | + public function getTemplate($mimetype) { |
|
| 55 | + $path = $this->getTemplatePath($mimetype); |
|
| 56 | + if ($path) { |
|
| 57 | + return file_get_contents($path); |
|
| 58 | + } else { |
|
| 59 | + return ''; |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | 62 | } |
@@ -28,439 +28,439 @@ |
||
| 28 | 28 | * Throws a StorageNotAvailableException for storages with known failures |
| 29 | 29 | */ |
| 30 | 30 | class Availability extends Wrapper { |
| 31 | - const RECHECK_TTL_SEC = 600; // 10 minutes |
|
| 32 | - |
|
| 33 | - public static function shouldRecheck($availability) { |
|
| 34 | - if (!$availability['available']) { |
|
| 35 | - // trigger a recheck if TTL reached |
|
| 36 | - if ((time() - $availability['last_checked']) > self::RECHECK_TTL_SEC) { |
|
| 37 | - return true; |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - return false; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Only called if availability === false |
|
| 45 | - * |
|
| 46 | - * @return bool |
|
| 47 | - */ |
|
| 48 | - private function updateAvailability() { |
|
| 49 | - // reset availability to false so that multiple requests don't recheck concurrently |
|
| 50 | - $this->setAvailability(false); |
|
| 51 | - try { |
|
| 52 | - $result = $this->test(); |
|
| 53 | - } catch (\Exception $e) { |
|
| 54 | - $result = false; |
|
| 55 | - } |
|
| 56 | - $this->setAvailability($result); |
|
| 57 | - return $result; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @return bool |
|
| 62 | - */ |
|
| 63 | - private function isAvailable() { |
|
| 64 | - $availability = $this->getAvailability(); |
|
| 65 | - if (self::shouldRecheck($availability)) { |
|
| 66 | - return $this->updateAvailability(); |
|
| 67 | - } |
|
| 68 | - return $availability['available']; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @throws \OCP\Files\StorageNotAvailableException |
|
| 73 | - */ |
|
| 74 | - private function checkAvailability() { |
|
| 75 | - if (!$this->isAvailable()) { |
|
| 76 | - throw new \OCP\Files\StorageNotAvailableException(); |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** {@inheritdoc} */ |
|
| 81 | - public function mkdir($path) { |
|
| 82 | - $this->checkAvailability(); |
|
| 83 | - try { |
|
| 84 | - return parent::mkdir($path); |
|
| 85 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 86 | - $this->setAvailability(false); |
|
| 87 | - throw $e; |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** {@inheritdoc} */ |
|
| 92 | - public function rmdir($path) { |
|
| 93 | - $this->checkAvailability(); |
|
| 94 | - try { |
|
| 95 | - return parent::rmdir($path); |
|
| 96 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 97 | - $this->setAvailability(false); |
|
| 98 | - throw $e; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** {@inheritdoc} */ |
|
| 103 | - public function opendir($path) { |
|
| 104 | - $this->checkAvailability(); |
|
| 105 | - try { |
|
| 106 | - return parent::opendir($path); |
|
| 107 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 108 | - $this->setAvailability(false); |
|
| 109 | - throw $e; |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** {@inheritdoc} */ |
|
| 114 | - public function is_dir($path) { |
|
| 115 | - $this->checkAvailability(); |
|
| 116 | - try { |
|
| 117 | - return parent::is_dir($path); |
|
| 118 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 119 | - $this->setAvailability(false); |
|
| 120 | - throw $e; |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** {@inheritdoc} */ |
|
| 125 | - public function is_file($path) { |
|
| 126 | - $this->checkAvailability(); |
|
| 127 | - try { |
|
| 128 | - return parent::is_file($path); |
|
| 129 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 130 | - $this->setAvailability(false); |
|
| 131 | - throw $e; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** {@inheritdoc} */ |
|
| 136 | - public function stat($path) { |
|
| 137 | - $this->checkAvailability(); |
|
| 138 | - try { |
|
| 139 | - return parent::stat($path); |
|
| 140 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 141 | - $this->setAvailability(false); |
|
| 142 | - throw $e; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** {@inheritdoc} */ |
|
| 147 | - public function filetype($path) { |
|
| 148 | - $this->checkAvailability(); |
|
| 149 | - try { |
|
| 150 | - return parent::filetype($path); |
|
| 151 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 152 | - $this->setAvailability(false); |
|
| 153 | - throw $e; |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** {@inheritdoc} */ |
|
| 158 | - public function filesize($path) { |
|
| 159 | - $this->checkAvailability(); |
|
| 160 | - try { |
|
| 161 | - return parent::filesize($path); |
|
| 162 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 163 | - $this->setAvailability(false); |
|
| 164 | - throw $e; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** {@inheritdoc} */ |
|
| 169 | - public function isCreatable($path) { |
|
| 170 | - $this->checkAvailability(); |
|
| 171 | - try { |
|
| 172 | - return parent::isCreatable($path); |
|
| 173 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 174 | - $this->setAvailability(false); |
|
| 175 | - throw $e; |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** {@inheritdoc} */ |
|
| 180 | - public function isReadable($path) { |
|
| 181 | - $this->checkAvailability(); |
|
| 182 | - try { |
|
| 183 | - return parent::isReadable($path); |
|
| 184 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 185 | - $this->setAvailability(false); |
|
| 186 | - throw $e; |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** {@inheritdoc} */ |
|
| 191 | - public function isUpdatable($path) { |
|
| 192 | - $this->checkAvailability(); |
|
| 193 | - try { |
|
| 194 | - return parent::isUpdatable($path); |
|
| 195 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 196 | - $this->setAvailability(false); |
|
| 197 | - throw $e; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** {@inheritdoc} */ |
|
| 202 | - public function isDeletable($path) { |
|
| 203 | - $this->checkAvailability(); |
|
| 204 | - try { |
|
| 205 | - return parent::isDeletable($path); |
|
| 206 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 207 | - $this->setAvailability(false); |
|
| 208 | - throw $e; |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** {@inheritdoc} */ |
|
| 213 | - public function isSharable($path) { |
|
| 214 | - $this->checkAvailability(); |
|
| 215 | - try { |
|
| 216 | - return parent::isSharable($path); |
|
| 217 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 218 | - $this->setAvailability(false); |
|
| 219 | - throw $e; |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** {@inheritdoc} */ |
|
| 224 | - public function getPermissions($path) { |
|
| 225 | - $this->checkAvailability(); |
|
| 226 | - try { |
|
| 227 | - return parent::getPermissions($path); |
|
| 228 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 229 | - $this->setAvailability(false); |
|
| 230 | - throw $e; |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** {@inheritdoc} */ |
|
| 235 | - public function file_exists($path) { |
|
| 236 | - if ($path === '') { |
|
| 237 | - return true; |
|
| 238 | - } |
|
| 239 | - $this->checkAvailability(); |
|
| 240 | - try { |
|
| 241 | - return parent::file_exists($path); |
|
| 242 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 243 | - $this->setAvailability(false); |
|
| 244 | - throw $e; |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** {@inheritdoc} */ |
|
| 249 | - public function filemtime($path) { |
|
| 250 | - $this->checkAvailability(); |
|
| 251 | - try { |
|
| 252 | - return parent::filemtime($path); |
|
| 253 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 254 | - $this->setAvailability(false); |
|
| 255 | - throw $e; |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** {@inheritdoc} */ |
|
| 260 | - public function file_get_contents($path) { |
|
| 261 | - $this->checkAvailability(); |
|
| 262 | - try { |
|
| 263 | - return parent::file_get_contents($path); |
|
| 264 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 265 | - $this->setAvailability(false); |
|
| 266 | - throw $e; |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** {@inheritdoc} */ |
|
| 271 | - public function file_put_contents($path, $data) { |
|
| 272 | - $this->checkAvailability(); |
|
| 273 | - try { |
|
| 274 | - return parent::file_put_contents($path, $data); |
|
| 275 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 276 | - $this->setAvailability(false); |
|
| 277 | - throw $e; |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** {@inheritdoc} */ |
|
| 282 | - public function unlink($path) { |
|
| 283 | - $this->checkAvailability(); |
|
| 284 | - try { |
|
| 285 | - return parent::unlink($path); |
|
| 286 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 287 | - $this->setAvailability(false); |
|
| 288 | - throw $e; |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** {@inheritdoc} */ |
|
| 293 | - public function rename($path1, $path2) { |
|
| 294 | - $this->checkAvailability(); |
|
| 295 | - try { |
|
| 296 | - return parent::rename($path1, $path2); |
|
| 297 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 298 | - $this->setAvailability(false); |
|
| 299 | - throw $e; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - /** {@inheritdoc} */ |
|
| 304 | - public function copy($path1, $path2) { |
|
| 305 | - $this->checkAvailability(); |
|
| 306 | - try { |
|
| 307 | - return parent::copy($path1, $path2); |
|
| 308 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 309 | - $this->setAvailability(false); |
|
| 310 | - throw $e; |
|
| 311 | - } |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - /** {@inheritdoc} */ |
|
| 315 | - public function fopen($path, $mode) { |
|
| 316 | - $this->checkAvailability(); |
|
| 317 | - try { |
|
| 318 | - return parent::fopen($path, $mode); |
|
| 319 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 320 | - $this->setAvailability(false); |
|
| 321 | - throw $e; |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - /** {@inheritdoc} */ |
|
| 326 | - public function getMimeType($path) { |
|
| 327 | - $this->checkAvailability(); |
|
| 328 | - try { |
|
| 329 | - return parent::getMimeType($path); |
|
| 330 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 331 | - $this->setAvailability(false); |
|
| 332 | - throw $e; |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** {@inheritdoc} */ |
|
| 337 | - public function hash($type, $path, $raw = false) { |
|
| 338 | - $this->checkAvailability(); |
|
| 339 | - try { |
|
| 340 | - return parent::hash($type, $path, $raw); |
|
| 341 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 342 | - $this->setAvailability(false); |
|
| 343 | - throw $e; |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** {@inheritdoc} */ |
|
| 348 | - public function free_space($path) { |
|
| 349 | - $this->checkAvailability(); |
|
| 350 | - try { |
|
| 351 | - return parent::free_space($path); |
|
| 352 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 353 | - $this->setAvailability(false); |
|
| 354 | - throw $e; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** {@inheritdoc} */ |
|
| 359 | - public function search($query) { |
|
| 360 | - $this->checkAvailability(); |
|
| 361 | - try { |
|
| 362 | - return parent::search($query); |
|
| 363 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 364 | - $this->setAvailability(false); |
|
| 365 | - throw $e; |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** {@inheritdoc} */ |
|
| 370 | - public function touch($path, $mtime = null) { |
|
| 371 | - $this->checkAvailability(); |
|
| 372 | - try { |
|
| 373 | - return parent::touch($path, $mtime); |
|
| 374 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 375 | - $this->setAvailability(false); |
|
| 376 | - throw $e; |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** {@inheritdoc} */ |
|
| 381 | - public function getLocalFile($path) { |
|
| 382 | - $this->checkAvailability(); |
|
| 383 | - try { |
|
| 384 | - return parent::getLocalFile($path); |
|
| 385 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 386 | - $this->setAvailability(false); |
|
| 387 | - throw $e; |
|
| 388 | - } |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - /** {@inheritdoc} */ |
|
| 392 | - public function hasUpdated($path, $time) { |
|
| 393 | - $this->checkAvailability(); |
|
| 394 | - try { |
|
| 395 | - return parent::hasUpdated($path, $time); |
|
| 396 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 397 | - $this->setAvailability(false); |
|
| 398 | - throw $e; |
|
| 399 | - } |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - /** {@inheritdoc} */ |
|
| 403 | - public function getOwner($path) { |
|
| 404 | - try { |
|
| 405 | - return parent::getOwner($path); |
|
| 406 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 407 | - $this->setAvailability(false); |
|
| 408 | - throw $e; |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** {@inheritdoc} */ |
|
| 413 | - public function getETag($path) { |
|
| 414 | - $this->checkAvailability(); |
|
| 415 | - try { |
|
| 416 | - return parent::getETag($path); |
|
| 417 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 418 | - $this->setAvailability(false); |
|
| 419 | - throw $e; |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** {@inheritdoc} */ |
|
| 424 | - public function getDirectDownload($path) { |
|
| 425 | - $this->checkAvailability(); |
|
| 426 | - try { |
|
| 427 | - return parent::getDirectDownload($path); |
|
| 428 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 429 | - $this->setAvailability(false); |
|
| 430 | - throw $e; |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** {@inheritdoc} */ |
|
| 435 | - public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|
| 436 | - $this->checkAvailability(); |
|
| 437 | - try { |
|
| 438 | - return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); |
|
| 439 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 440 | - $this->setAvailability(false); |
|
| 441 | - throw $e; |
|
| 442 | - } |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - /** {@inheritdoc} */ |
|
| 446 | - public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|
| 447 | - $this->checkAvailability(); |
|
| 448 | - try { |
|
| 449 | - return parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); |
|
| 450 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 451 | - $this->setAvailability(false); |
|
| 452 | - throw $e; |
|
| 453 | - } |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - /** {@inheritdoc} */ |
|
| 457 | - public function getMetaData($path) { |
|
| 458 | - $this->checkAvailability(); |
|
| 459 | - try { |
|
| 460 | - return parent::getMetaData($path); |
|
| 461 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 462 | - $this->setAvailability(false); |
|
| 463 | - throw $e; |
|
| 464 | - } |
|
| 465 | - } |
|
| 31 | + const RECHECK_TTL_SEC = 600; // 10 minutes |
|
| 32 | + |
|
| 33 | + public static function shouldRecheck($availability) { |
|
| 34 | + if (!$availability['available']) { |
|
| 35 | + // trigger a recheck if TTL reached |
|
| 36 | + if ((time() - $availability['last_checked']) > self::RECHECK_TTL_SEC) { |
|
| 37 | + return true; |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + return false; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Only called if availability === false |
|
| 45 | + * |
|
| 46 | + * @return bool |
|
| 47 | + */ |
|
| 48 | + private function updateAvailability() { |
|
| 49 | + // reset availability to false so that multiple requests don't recheck concurrently |
|
| 50 | + $this->setAvailability(false); |
|
| 51 | + try { |
|
| 52 | + $result = $this->test(); |
|
| 53 | + } catch (\Exception $e) { |
|
| 54 | + $result = false; |
|
| 55 | + } |
|
| 56 | + $this->setAvailability($result); |
|
| 57 | + return $result; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @return bool |
|
| 62 | + */ |
|
| 63 | + private function isAvailable() { |
|
| 64 | + $availability = $this->getAvailability(); |
|
| 65 | + if (self::shouldRecheck($availability)) { |
|
| 66 | + return $this->updateAvailability(); |
|
| 67 | + } |
|
| 68 | + return $availability['available']; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @throws \OCP\Files\StorageNotAvailableException |
|
| 73 | + */ |
|
| 74 | + private function checkAvailability() { |
|
| 75 | + if (!$this->isAvailable()) { |
|
| 76 | + throw new \OCP\Files\StorageNotAvailableException(); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** {@inheritdoc} */ |
|
| 81 | + public function mkdir($path) { |
|
| 82 | + $this->checkAvailability(); |
|
| 83 | + try { |
|
| 84 | + return parent::mkdir($path); |
|
| 85 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 86 | + $this->setAvailability(false); |
|
| 87 | + throw $e; |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** {@inheritdoc} */ |
|
| 92 | + public function rmdir($path) { |
|
| 93 | + $this->checkAvailability(); |
|
| 94 | + try { |
|
| 95 | + return parent::rmdir($path); |
|
| 96 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 97 | + $this->setAvailability(false); |
|
| 98 | + throw $e; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** {@inheritdoc} */ |
|
| 103 | + public function opendir($path) { |
|
| 104 | + $this->checkAvailability(); |
|
| 105 | + try { |
|
| 106 | + return parent::opendir($path); |
|
| 107 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 108 | + $this->setAvailability(false); |
|
| 109 | + throw $e; |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** {@inheritdoc} */ |
|
| 114 | + public function is_dir($path) { |
|
| 115 | + $this->checkAvailability(); |
|
| 116 | + try { |
|
| 117 | + return parent::is_dir($path); |
|
| 118 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 119 | + $this->setAvailability(false); |
|
| 120 | + throw $e; |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** {@inheritdoc} */ |
|
| 125 | + public function is_file($path) { |
|
| 126 | + $this->checkAvailability(); |
|
| 127 | + try { |
|
| 128 | + return parent::is_file($path); |
|
| 129 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 130 | + $this->setAvailability(false); |
|
| 131 | + throw $e; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** {@inheritdoc} */ |
|
| 136 | + public function stat($path) { |
|
| 137 | + $this->checkAvailability(); |
|
| 138 | + try { |
|
| 139 | + return parent::stat($path); |
|
| 140 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 141 | + $this->setAvailability(false); |
|
| 142 | + throw $e; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** {@inheritdoc} */ |
|
| 147 | + public function filetype($path) { |
|
| 148 | + $this->checkAvailability(); |
|
| 149 | + try { |
|
| 150 | + return parent::filetype($path); |
|
| 151 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 152 | + $this->setAvailability(false); |
|
| 153 | + throw $e; |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** {@inheritdoc} */ |
|
| 158 | + public function filesize($path) { |
|
| 159 | + $this->checkAvailability(); |
|
| 160 | + try { |
|
| 161 | + return parent::filesize($path); |
|
| 162 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 163 | + $this->setAvailability(false); |
|
| 164 | + throw $e; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** {@inheritdoc} */ |
|
| 169 | + public function isCreatable($path) { |
|
| 170 | + $this->checkAvailability(); |
|
| 171 | + try { |
|
| 172 | + return parent::isCreatable($path); |
|
| 173 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 174 | + $this->setAvailability(false); |
|
| 175 | + throw $e; |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** {@inheritdoc} */ |
|
| 180 | + public function isReadable($path) { |
|
| 181 | + $this->checkAvailability(); |
|
| 182 | + try { |
|
| 183 | + return parent::isReadable($path); |
|
| 184 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 185 | + $this->setAvailability(false); |
|
| 186 | + throw $e; |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** {@inheritdoc} */ |
|
| 191 | + public function isUpdatable($path) { |
|
| 192 | + $this->checkAvailability(); |
|
| 193 | + try { |
|
| 194 | + return parent::isUpdatable($path); |
|
| 195 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 196 | + $this->setAvailability(false); |
|
| 197 | + throw $e; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** {@inheritdoc} */ |
|
| 202 | + public function isDeletable($path) { |
|
| 203 | + $this->checkAvailability(); |
|
| 204 | + try { |
|
| 205 | + return parent::isDeletable($path); |
|
| 206 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 207 | + $this->setAvailability(false); |
|
| 208 | + throw $e; |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** {@inheritdoc} */ |
|
| 213 | + public function isSharable($path) { |
|
| 214 | + $this->checkAvailability(); |
|
| 215 | + try { |
|
| 216 | + return parent::isSharable($path); |
|
| 217 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 218 | + $this->setAvailability(false); |
|
| 219 | + throw $e; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** {@inheritdoc} */ |
|
| 224 | + public function getPermissions($path) { |
|
| 225 | + $this->checkAvailability(); |
|
| 226 | + try { |
|
| 227 | + return parent::getPermissions($path); |
|
| 228 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 229 | + $this->setAvailability(false); |
|
| 230 | + throw $e; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** {@inheritdoc} */ |
|
| 235 | + public function file_exists($path) { |
|
| 236 | + if ($path === '') { |
|
| 237 | + return true; |
|
| 238 | + } |
|
| 239 | + $this->checkAvailability(); |
|
| 240 | + try { |
|
| 241 | + return parent::file_exists($path); |
|
| 242 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 243 | + $this->setAvailability(false); |
|
| 244 | + throw $e; |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** {@inheritdoc} */ |
|
| 249 | + public function filemtime($path) { |
|
| 250 | + $this->checkAvailability(); |
|
| 251 | + try { |
|
| 252 | + return parent::filemtime($path); |
|
| 253 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 254 | + $this->setAvailability(false); |
|
| 255 | + throw $e; |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** {@inheritdoc} */ |
|
| 260 | + public function file_get_contents($path) { |
|
| 261 | + $this->checkAvailability(); |
|
| 262 | + try { |
|
| 263 | + return parent::file_get_contents($path); |
|
| 264 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 265 | + $this->setAvailability(false); |
|
| 266 | + throw $e; |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** {@inheritdoc} */ |
|
| 271 | + public function file_put_contents($path, $data) { |
|
| 272 | + $this->checkAvailability(); |
|
| 273 | + try { |
|
| 274 | + return parent::file_put_contents($path, $data); |
|
| 275 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 276 | + $this->setAvailability(false); |
|
| 277 | + throw $e; |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** {@inheritdoc} */ |
|
| 282 | + public function unlink($path) { |
|
| 283 | + $this->checkAvailability(); |
|
| 284 | + try { |
|
| 285 | + return parent::unlink($path); |
|
| 286 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 287 | + $this->setAvailability(false); |
|
| 288 | + throw $e; |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** {@inheritdoc} */ |
|
| 293 | + public function rename($path1, $path2) { |
|
| 294 | + $this->checkAvailability(); |
|
| 295 | + try { |
|
| 296 | + return parent::rename($path1, $path2); |
|
| 297 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 298 | + $this->setAvailability(false); |
|
| 299 | + throw $e; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + /** {@inheritdoc} */ |
|
| 304 | + public function copy($path1, $path2) { |
|
| 305 | + $this->checkAvailability(); |
|
| 306 | + try { |
|
| 307 | + return parent::copy($path1, $path2); |
|
| 308 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 309 | + $this->setAvailability(false); |
|
| 310 | + throw $e; |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + /** {@inheritdoc} */ |
|
| 315 | + public function fopen($path, $mode) { |
|
| 316 | + $this->checkAvailability(); |
|
| 317 | + try { |
|
| 318 | + return parent::fopen($path, $mode); |
|
| 319 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 320 | + $this->setAvailability(false); |
|
| 321 | + throw $e; |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + /** {@inheritdoc} */ |
|
| 326 | + public function getMimeType($path) { |
|
| 327 | + $this->checkAvailability(); |
|
| 328 | + try { |
|
| 329 | + return parent::getMimeType($path); |
|
| 330 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 331 | + $this->setAvailability(false); |
|
| 332 | + throw $e; |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** {@inheritdoc} */ |
|
| 337 | + public function hash($type, $path, $raw = false) { |
|
| 338 | + $this->checkAvailability(); |
|
| 339 | + try { |
|
| 340 | + return parent::hash($type, $path, $raw); |
|
| 341 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 342 | + $this->setAvailability(false); |
|
| 343 | + throw $e; |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** {@inheritdoc} */ |
|
| 348 | + public function free_space($path) { |
|
| 349 | + $this->checkAvailability(); |
|
| 350 | + try { |
|
| 351 | + return parent::free_space($path); |
|
| 352 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 353 | + $this->setAvailability(false); |
|
| 354 | + throw $e; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** {@inheritdoc} */ |
|
| 359 | + public function search($query) { |
|
| 360 | + $this->checkAvailability(); |
|
| 361 | + try { |
|
| 362 | + return parent::search($query); |
|
| 363 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 364 | + $this->setAvailability(false); |
|
| 365 | + throw $e; |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + /** {@inheritdoc} */ |
|
| 370 | + public function touch($path, $mtime = null) { |
|
| 371 | + $this->checkAvailability(); |
|
| 372 | + try { |
|
| 373 | + return parent::touch($path, $mtime); |
|
| 374 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 375 | + $this->setAvailability(false); |
|
| 376 | + throw $e; |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** {@inheritdoc} */ |
|
| 381 | + public function getLocalFile($path) { |
|
| 382 | + $this->checkAvailability(); |
|
| 383 | + try { |
|
| 384 | + return parent::getLocalFile($path); |
|
| 385 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 386 | + $this->setAvailability(false); |
|
| 387 | + throw $e; |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + /** {@inheritdoc} */ |
|
| 392 | + public function hasUpdated($path, $time) { |
|
| 393 | + $this->checkAvailability(); |
|
| 394 | + try { |
|
| 395 | + return parent::hasUpdated($path, $time); |
|
| 396 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 397 | + $this->setAvailability(false); |
|
| 398 | + throw $e; |
|
| 399 | + } |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + /** {@inheritdoc} */ |
|
| 403 | + public function getOwner($path) { |
|
| 404 | + try { |
|
| 405 | + return parent::getOwner($path); |
|
| 406 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 407 | + $this->setAvailability(false); |
|
| 408 | + throw $e; |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** {@inheritdoc} */ |
|
| 413 | + public function getETag($path) { |
|
| 414 | + $this->checkAvailability(); |
|
| 415 | + try { |
|
| 416 | + return parent::getETag($path); |
|
| 417 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 418 | + $this->setAvailability(false); |
|
| 419 | + throw $e; |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** {@inheritdoc} */ |
|
| 424 | + public function getDirectDownload($path) { |
|
| 425 | + $this->checkAvailability(); |
|
| 426 | + try { |
|
| 427 | + return parent::getDirectDownload($path); |
|
| 428 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 429 | + $this->setAvailability(false); |
|
| 430 | + throw $e; |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** {@inheritdoc} */ |
|
| 435 | + public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|
| 436 | + $this->checkAvailability(); |
|
| 437 | + try { |
|
| 438 | + return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); |
|
| 439 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 440 | + $this->setAvailability(false); |
|
| 441 | + throw $e; |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + /** {@inheritdoc} */ |
|
| 446 | + public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|
| 447 | + $this->checkAvailability(); |
|
| 448 | + try { |
|
| 449 | + return parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); |
|
| 450 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 451 | + $this->setAvailability(false); |
|
| 452 | + throw $e; |
|
| 453 | + } |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + /** {@inheritdoc} */ |
|
| 457 | + public function getMetaData($path) { |
|
| 458 | + $this->checkAvailability(); |
|
| 459 | + try { |
|
| 460 | + return parent::getMetaData($path); |
|
| 461 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
| 462 | + $this->setAvailability(false); |
|
| 463 | + throw $e; |
|
| 464 | + } |
|
| 465 | + } |
|
| 466 | 466 | } |