From 2a2f1b9a00f515585426aade80aea9220da5b6b4 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 22 Aug 2016 12:23:55 +0200 Subject: [PATCH 1/6] Allow storage wrappers to lazily initialize the source storage --- lib/private/Files/Storage/Wrapper/Wrapper.php | 110 +++++++++--------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/lib/private/Files/Storage/Wrapper/Wrapper.php b/lib/private/Files/Storage/Wrapper/Wrapper.php index 706023a289..c52b339483 100644 --- a/lib/private/Files/Storage/Wrapper/Wrapper.php +++ b/lib/private/Files/Storage/Wrapper/Wrapper.php @@ -64,7 +64,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return string */ public function getId() { - return $this->storage->getId(); + return $this->getWrapperStorage()->getId(); } /** @@ -74,7 +74,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return bool */ public function mkdir($path) { - return $this->storage->mkdir($path); + return $this->getWrapperStorage()->mkdir($path); } /** @@ -84,7 +84,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return bool */ public function rmdir($path) { - return $this->storage->rmdir($path); + return $this->getWrapperStorage()->rmdir($path); } /** @@ -94,7 +94,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return resource */ public function opendir($path) { - return $this->storage->opendir($path); + return $this->getWrapperStorage()->opendir($path); } /** @@ -104,7 +104,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return bool */ public function is_dir($path) { - return $this->storage->is_dir($path); + return $this->getWrapperStorage()->is_dir($path); } /** @@ -114,7 +114,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return bool */ public function is_file($path) { - return $this->storage->is_file($path); + return $this->getWrapperStorage()->is_file($path); } /** @@ -125,7 +125,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return array */ public function stat($path) { - return $this->storage->stat($path); + return $this->getWrapperStorage()->stat($path); } /** @@ -135,7 +135,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return bool */ public function filetype($path) { - return $this->storage->filetype($path); + return $this->getWrapperStorage()->filetype($path); } /** @@ -146,7 +146,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return int */ public function filesize($path) { - return $this->storage->filesize($path); + return $this->getWrapperStorage()->filesize($path); } /** @@ -156,7 +156,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return bool */ public function isCreatable($path) { - return $this->storage->isCreatable($path); + return $this->getWrapperStorage()->isCreatable($path); } /** @@ -166,7 +166,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return bool */ public function isReadable($path) { - return $this->storage->isReadable($path); + return $this->getWrapperStorage()->isReadable($path); } /** @@ -176,7 +176,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return bool */ public function isUpdatable($path) { - return $this->storage->isUpdatable($path); + return $this->getWrapperStorage()->isUpdatable($path); } /** @@ -186,7 +186,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return bool */ public function isDeletable($path) { - return $this->storage->isDeletable($path); + return $this->getWrapperStorage()->isDeletable($path); } /** @@ -196,7 +196,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return bool */ public function isSharable($path) { - return $this->storage->isSharable($path); + return $this->getWrapperStorage()->isSharable($path); } /** @@ -207,7 +207,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return int */ public function getPermissions($path) { - return $this->storage->getPermissions($path); + return $this->getWrapperStorage()->getPermissions($path); } /** @@ -217,7 +217,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return bool */ public function file_exists($path) { - return $this->storage->file_exists($path); + return $this->getWrapperStorage()->file_exists($path); } /** @@ -227,7 +227,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return int */ public function filemtime($path) { - return $this->storage->filemtime($path); + return $this->getWrapperStorage()->filemtime($path); } /** @@ -237,7 +237,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return string */ public function file_get_contents($path) { - return $this->storage->file_get_contents($path); + return $this->getWrapperStorage()->file_get_contents($path); } /** @@ -248,7 +248,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return bool */ public function file_put_contents($path, $data) { - return $this->storage->file_put_contents($path, $data); + return $this->getWrapperStorage()->file_put_contents($path, $data); } /** @@ -258,7 +258,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return bool */ public function unlink($path) { - return $this->storage->unlink($path); + return $this->getWrapperStorage()->unlink($path); } /** @@ -269,7 +269,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return bool */ public function rename($path1, $path2) { - return $this->storage->rename($path1, $path2); + return $this->getWrapperStorage()->rename($path1, $path2); } /** @@ -280,7 +280,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return bool */ public function copy($path1, $path2) { - return $this->storage->copy($path1, $path2); + return $this->getWrapperStorage()->copy($path1, $path2); } /** @@ -291,7 +291,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return resource */ public function fopen($path, $mode) { - return $this->storage->fopen($path, $mode); + return $this->getWrapperStorage()->fopen($path, $mode); } /** @@ -302,7 +302,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return string */ public function getMimeType($path) { - return $this->storage->getMimeType($path); + return $this->getWrapperStorage()->getMimeType($path); } /** @@ -314,7 +314,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return string */ public function hash($type, $path, $raw = false) { - return $this->storage->hash($type, $path, $raw); + return $this->getWrapperStorage()->hash($type, $path, $raw); } /** @@ -324,7 +324,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return int */ public function free_space($path) { - return $this->storage->free_space($path); + return $this->getWrapperStorage()->free_space($path); } /** @@ -334,7 +334,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return array */ public function search($query) { - return $this->storage->search($query); + return $this->getWrapperStorage()->search($query); } /** @@ -346,7 +346,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return bool */ public function touch($path, $mtime = null) { - return $this->storage->touch($path, $mtime); + return $this->getWrapperStorage()->touch($path, $mtime); } /** @@ -357,7 +357,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return string */ public function getLocalFile($path) { - return $this->storage->getLocalFile($path); + return $this->getWrapperStorage()->getLocalFile($path); } /** @@ -371,7 +371,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * returning true for other changes in the folder is optional */ public function hasUpdated($path, $time) { - return $this->storage->hasUpdated($path, $time); + return $this->getWrapperStorage()->hasUpdated($path, $time); } /** @@ -385,7 +385,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { if (!$storage) { $storage = $this; } - return $this->storage->getCache($path, $storage); + return $this->getWrapperStorage()->getCache($path, $storage); } /** @@ -399,7 +399,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { if (!$storage) { $storage = $this; } - return $this->storage->getScanner($path, $storage); + return $this->getWrapperStorage()->getScanner($path, $storage); } @@ -410,7 +410,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return string */ public function getOwner($path) { - return $this->storage->getOwner($path); + return $this->getWrapperStorage()->getOwner($path); } /** @@ -424,28 +424,28 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { if (!$storage) { $storage = $this; } - return $this->storage->getWatcher($path, $storage); + return $this->getWrapperStorage()->getWatcher($path, $storage); } public function getPropagator($storage = null) { if (!$storage) { $storage = $this; } - return $this->storage->getPropagator($storage); + return $this->getWrapperStorage()->getPropagator($storage); } public function getUpdater($storage = null) { if (!$storage) { $storage = $this; } - return $this->storage->getUpdater($storage); + return $this->getWrapperStorage()->getUpdater($storage); } /** * @return \OC\Files\Cache\Storage */ public function getStorageCache() { - return $this->storage->getStorageCache(); + return $this->getWrapperStorage()->getStorageCache(); } /** @@ -455,7 +455,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return string */ public function getETag($path) { - return $this->storage->getETag($path); + return $this->getWrapperStorage()->getETag($path); } /** @@ -464,7 +464,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return true */ public function test() { - return $this->storage->test(); + return $this->getWrapperStorage()->test(); } /** @@ -473,7 +473,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return bool wrapped storage's isLocal() value */ public function isLocal() { - return $this->storage->isLocal(); + return $this->getWrapperStorage()->isLocal(); } /** @@ -483,7 +483,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return bool */ public function instanceOfStorage($class) { - return is_a($this, $class) or $this->storage->instanceOfStorage($class); + return is_a($this, $class) or $this->getWrapperStorage()->instanceOfStorage($class); } /** @@ -494,7 +494,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return mixed */ public function __call($method, $args) { - return call_user_func_array(array($this->storage, $method), $args); + return call_user_func_array(array($this->getWrapperStorage(), $method), $args); } /** @@ -506,7 +506,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return array */ public function getDirectDownload($path) { - return $this->storage->getDirectDownload($path); + return $this->getWrapperStorage()->getDirectDownload($path); } /** @@ -515,7 +515,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return array [ available, last_checked ] */ public function getAvailability() { - return $this->storage->getAvailability(); + return $this->getWrapperStorage()->getAvailability(); } /** @@ -524,7 +524,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @param bool $isAvailable */ public function setAvailability($isAvailable) { - $this->storage->setAvailability($isAvailable); + $this->getWrapperStorage()->setAvailability($isAvailable); } /** @@ -534,7 +534,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @throws InvalidPathException */ public function verifyPath($path, $fileName) { - $this->storage->verifyPath($path, $fileName); + $this->getWrapperStorage()->verifyPath($path, $fileName); } /** @@ -548,7 +548,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { return $this->copy($sourceInternalPath, $targetInternalPath); } - return $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); + return $this->getWrapperStorage()->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } /** @@ -562,7 +562,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { return $this->rename($sourceInternalPath, $targetInternalPath); } - return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); + return $this->getWrapperStorage()->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } /** @@ -570,7 +570,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @return array */ public function getMetaData($path) { - return $this->storage->getMetaData($path); + return $this->getWrapperStorage()->getMetaData($path); } /** @@ -580,8 +580,8 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @throws \OCP\Lock\LockedException */ public function acquireLock($path, $type, ILockingProvider $provider) { - if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { - $this->storage->acquireLock($path, $type, $provider); + if ($this->getWrapperStorage()->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { + $this->getWrapperStorage()->acquireLock($path, $type, $provider); } } @@ -591,8 +591,8 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @param \OCP\Lock\ILockingProvider $provider */ public function releaseLock($path, $type, ILockingProvider $provider) { - if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { - $this->storage->releaseLock($path, $type, $provider); + if ($this->getWrapperStorage()->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { + $this->getWrapperStorage()->releaseLock($path, $type, $provider); } } @@ -602,8 +602,8 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { * @param \OCP\Lock\ILockingProvider $provider */ public function changeLock($path, $type, ILockingProvider $provider) { - if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { - $this->storage->changeLock($path, $type, $provider); + if ($this->getWrapperStorage()->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { + $this->getWrapperStorage()->changeLock($path, $type, $provider); } } } From a1fd9d275fe06abde67d080206e077fa5dee418b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 22 Aug 2016 12:26:27 +0200 Subject: [PATCH 2/6] Allow jail wrappers to lazily initialize the source storage --- lib/private/Files/Storage/Wrapper/Jail.php | 82 +++++++++++----------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php index 80c7552374..8615d73f34 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -68,7 +68,7 @@ class Jail extends Wrapper { * @return bool */ public function mkdir($path) { - return $this->storage->mkdir($this->getSourcePath($path)); + return $this->getWrapperStorage()->mkdir($this->getSourcePath($path)); } /** @@ -78,7 +78,7 @@ class Jail extends Wrapper { * @return bool */ public function rmdir($path) { - return $this->storage->rmdir($this->getSourcePath($path)); + return $this->getWrapperStorage()->rmdir($this->getSourcePath($path)); } /** @@ -88,7 +88,7 @@ class Jail extends Wrapper { * @return resource */ public function opendir($path) { - return $this->storage->opendir($this->getSourcePath($path)); + return $this->getWrapperStorage()->opendir($this->getSourcePath($path)); } /** @@ -98,7 +98,7 @@ class Jail extends Wrapper { * @return bool */ public function is_dir($path) { - return $this->storage->is_dir($this->getSourcePath($path)); + return $this->getWrapperStorage()->is_dir($this->getSourcePath($path)); } /** @@ -108,7 +108,7 @@ class Jail extends Wrapper { * @return bool */ public function is_file($path) { - return $this->storage->is_file($this->getSourcePath($path)); + return $this->getWrapperStorage()->is_file($this->getSourcePath($path)); } /** @@ -119,7 +119,7 @@ class Jail extends Wrapper { * @return array */ public function stat($path) { - return $this->storage->stat($this->getSourcePath($path)); + return $this->getWrapperStorage()->stat($this->getSourcePath($path)); } /** @@ -129,7 +129,7 @@ class Jail extends Wrapper { * @return bool */ public function filetype($path) { - return $this->storage->filetype($this->getSourcePath($path)); + return $this->getWrapperStorage()->filetype($this->getSourcePath($path)); } /** @@ -140,7 +140,7 @@ class Jail extends Wrapper { * @return int */ public function filesize($path) { - return $this->storage->filesize($this->getSourcePath($path)); + return $this->getWrapperStorage()->filesize($this->getSourcePath($path)); } /** @@ -150,7 +150,7 @@ class Jail extends Wrapper { * @return bool */ public function isCreatable($path) { - return $this->storage->isCreatable($this->getSourcePath($path)); + return $this->getWrapperStorage()->isCreatable($this->getSourcePath($path)); } /** @@ -160,7 +160,7 @@ class Jail extends Wrapper { * @return bool */ public function isReadable($path) { - return $this->storage->isReadable($this->getSourcePath($path)); + return $this->getWrapperStorage()->isReadable($this->getSourcePath($path)); } /** @@ -170,7 +170,7 @@ class Jail extends Wrapper { * @return bool */ public function isUpdatable($path) { - return $this->storage->isUpdatable($this->getSourcePath($path)); + return $this->getWrapperStorage()->isUpdatable($this->getSourcePath($path)); } /** @@ -180,7 +180,7 @@ class Jail extends Wrapper { * @return bool */ public function isDeletable($path) { - return $this->storage->isDeletable($this->getSourcePath($path)); + return $this->getWrapperStorage()->isDeletable($this->getSourcePath($path)); } /** @@ -190,7 +190,7 @@ class Jail extends Wrapper { * @return bool */ public function isSharable($path) { - return $this->storage->isSharable($this->getSourcePath($path)); + return $this->getWrapperStorage()->isSharable($this->getSourcePath($path)); } /** @@ -201,7 +201,7 @@ class Jail extends Wrapper { * @return int */ public function getPermissions($path) { - return $this->storage->getPermissions($this->getSourcePath($path)); + return $this->getWrapperStorage()->getPermissions($this->getSourcePath($path)); } /** @@ -211,7 +211,7 @@ class Jail extends Wrapper { * @return bool */ public function file_exists($path) { - return $this->storage->file_exists($this->getSourcePath($path)); + return $this->getWrapperStorage()->file_exists($this->getSourcePath($path)); } /** @@ -221,7 +221,7 @@ class Jail extends Wrapper { * @return int */ public function filemtime($path) { - return $this->storage->filemtime($this->getSourcePath($path)); + return $this->getWrapperStorage()->filemtime($this->getSourcePath($path)); } /** @@ -231,7 +231,7 @@ class Jail extends Wrapper { * @return string */ public function file_get_contents($path) { - return $this->storage->file_get_contents($this->getSourcePath($path)); + return $this->getWrapperStorage()->file_get_contents($this->getSourcePath($path)); } /** @@ -242,7 +242,7 @@ class Jail extends Wrapper { * @return bool */ public function file_put_contents($path, $data) { - return $this->storage->file_put_contents($this->getSourcePath($path), $data); + return $this->getWrapperStorage()->file_put_contents($this->getSourcePath($path), $data); } /** @@ -252,7 +252,7 @@ class Jail extends Wrapper { * @return bool */ public function unlink($path) { - return $this->storage->unlink($this->getSourcePath($path)); + return $this->getWrapperStorage()->unlink($this->getSourcePath($path)); } /** @@ -263,7 +263,7 @@ class Jail extends Wrapper { * @return bool */ public function rename($path1, $path2) { - return $this->storage->rename($this->getSourcePath($path1), $this->getSourcePath($path2)); + return $this->getWrapperStorage()->rename($this->getSourcePath($path1), $this->getSourcePath($path2)); } /** @@ -274,7 +274,7 @@ class Jail extends Wrapper { * @return bool */ public function copy($path1, $path2) { - return $this->storage->copy($this->getSourcePath($path1), $this->getSourcePath($path2)); + return $this->getWrapperStorage()->copy($this->getSourcePath($path1), $this->getSourcePath($path2)); } /** @@ -285,7 +285,7 @@ class Jail extends Wrapper { * @return resource */ public function fopen($path, $mode) { - return $this->storage->fopen($this->getSourcePath($path), $mode); + return $this->getWrapperStorage()->fopen($this->getSourcePath($path), $mode); } /** @@ -296,7 +296,7 @@ class Jail extends Wrapper { * @return string */ public function getMimeType($path) { - return $this->storage->getMimeType($this->getSourcePath($path)); + return $this->getWrapperStorage()->getMimeType($this->getSourcePath($path)); } /** @@ -308,7 +308,7 @@ class Jail extends Wrapper { * @return string */ public function hash($type, $path, $raw = false) { - return $this->storage->hash($type, $this->getSourcePath($path), $raw); + return $this->getWrapperStorage()->hash($type, $this->getSourcePath($path), $raw); } /** @@ -318,7 +318,7 @@ class Jail extends Wrapper { * @return int */ public function free_space($path) { - return $this->storage->free_space($this->getSourcePath($path)); + return $this->getWrapperStorage()->free_space($this->getSourcePath($path)); } /** @@ -328,7 +328,7 @@ class Jail extends Wrapper { * @return array */ public function search($query) { - return $this->storage->search($query); + return $this->getWrapperStorage()->search($query); } /** @@ -340,7 +340,7 @@ class Jail extends Wrapper { * @return bool */ public function touch($path, $mtime = null) { - return $this->storage->touch($this->getSourcePath($path), $mtime); + return $this->getWrapperStorage()->touch($this->getSourcePath($path), $mtime); } /** @@ -351,7 +351,7 @@ class Jail extends Wrapper { * @return string */ public function getLocalFile($path) { - return $this->storage->getLocalFile($this->getSourcePath($path)); + return $this->getWrapperStorage()->getLocalFile($this->getSourcePath($path)); } /** @@ -365,7 +365,7 @@ class Jail extends Wrapper { * returning true for other changes in the folder is optional */ public function hasUpdated($path, $time) { - return $this->storage->hasUpdated($this->getSourcePath($path), $time); + return $this->getWrapperStorage()->hasUpdated($this->getSourcePath($path), $time); } /** @@ -377,9 +377,9 @@ class Jail extends Wrapper { */ public function getCache($path = '', $storage = null) { if (!$storage) { - $storage = $this; + $storage = $this->getWrapperStorage(); } - $sourceCache = $this->storage->getCache($this->getSourcePath($path), $storage); + $sourceCache = $this->getWrapperStorage()->getCache($this->getSourcePath($path), $storage); return new CacheJail($sourceCache, $this->rootPath); } @@ -390,7 +390,7 @@ class Jail extends Wrapper { * @return string */ public function getOwner($path) { - return $this->storage->getOwner($this->getSourcePath($path)); + return $this->getWrapperStorage()->getOwner($this->getSourcePath($path)); } /** @@ -404,7 +404,7 @@ class Jail extends Wrapper { if (!$storage) { $storage = $this; } - return $this->storage->getWatcher($this->getSourcePath($path), $storage); + return $this->getWrapperStorage()->getWatcher($this->getSourcePath($path), $storage); } /** @@ -414,7 +414,7 @@ class Jail extends Wrapper { * @return string */ public function getETag($path) { - return $this->storage->getETag($this->getSourcePath($path)); + return $this->getWrapperStorage()->getETag($this->getSourcePath($path)); } /** @@ -422,7 +422,7 @@ class Jail extends Wrapper { * @return array */ public function getMetaData($path) { - return $this->storage->getMetaData($this->getSourcePath($path)); + return $this->getWrapperStorage()->getMetaData($this->getSourcePath($path)); } /** @@ -432,7 +432,7 @@ class Jail extends Wrapper { * @throws \OCP\Lock\LockedException */ public function acquireLock($path, $type, ILockingProvider $provider) { - $this->storage->acquireLock($this->getSourcePath($path), $type, $provider); + $this->getWrapperStorage()->acquireLock($this->getSourcePath($path), $type, $provider); } /** @@ -441,7 +441,7 @@ class Jail extends Wrapper { * @param \OCP\Lock\ILockingProvider $provider */ public function releaseLock($path, $type, ILockingProvider $provider) { - $this->storage->releaseLock($this->getSourcePath($path), $type, $provider); + $this->getWrapperStorage()->releaseLock($this->getSourcePath($path), $type, $provider); } /** @@ -450,7 +450,7 @@ class Jail extends Wrapper { * @param \OCP\Lock\ILockingProvider $provider */ public function changeLock($path, $type, ILockingProvider $provider) { - $this->storage->changeLock($this->getSourcePath($path), $type, $provider); + $this->getWrapperStorage()->changeLock($this->getSourcePath($path), $type, $provider); } /** @@ -460,7 +460,7 @@ class Jail extends Wrapper { * @return array */ public function resolvePath($path) { - return [$this->storage, $this->getSourcePath($path)]; + return [$this->getWrapperStorage(), $this->getSourcePath($path)]; } /** @@ -473,7 +473,7 @@ class Jail extends Wrapper { if ($sourceStorage === $this) { return $this->copy($sourceInternalPath, $targetInternalPath); } - return $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $this->getSourcePath($targetInternalPath)); + return $this->getWrapperStorage()->copyFromStorage($sourceStorage, $sourceInternalPath, $this->getSourcePath($targetInternalPath)); } /** @@ -486,6 +486,6 @@ class Jail extends Wrapper { if ($sourceStorage === $this) { return $this->rename($sourceInternalPath, $targetInternalPath); } - return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $this->getSourcePath($targetInternalPath)); + return $this->getWrapperStorage()->moveFromStorage($sourceStorage, $sourceInternalPath, $this->getSourcePath($targetInternalPath)); } } From 89d4684ef14cffef54c70748a2f6e2f184cf0e15 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 22 Aug 2016 12:27:20 +0200 Subject: [PATCH 3/6] reuse existing root id --- apps/files_sharing/lib/SharedMount.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php index d160eb2422..2b562c4b4f 100644 --- a/apps/files_sharing/lib/SharedMount.php +++ b/apps/files_sharing/lib/SharedMount.php @@ -244,7 +244,7 @@ class SharedMount extends MountPoint implements MoveableMount { $query = $builder->select('storage') ->from('filecache') - ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($this->getShare()->getNodeId()))); + ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($this->getStorageRootId()))); return $query->execute()->fetchColumn(); } From f4e89c15bf0ae68a94cbde3aa7069d5471054b16 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 22 Aug 2016 12:27:56 +0200 Subject: [PATCH 4/6] Lazy init shared storage --- apps/files_sharing/lib/sharedstorage.php | 26 ++++++++---------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 92900ccda6..7a7bb58982 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -61,11 +61,6 @@ class Shared extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage { */ private $sourceRootInfo; - /** - * @var IStorage - */ - private $sourceStorage; - /** @var string */ private $user; @@ -83,13 +78,9 @@ class Shared extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage { $this->user = $arguments['user']; - Filesystem::initMountPoints($this->superShare->getShareOwner()); - $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); - list($storage, $internalPath) = $this->ownerView->resolvePath($sourcePath); - parent::__construct([ - 'storage' => $storage, - 'root' => $internalPath, + 'storage' => null, + 'root' => null, ]); } @@ -101,8 +92,8 @@ class Shared extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage { try { Filesystem::initMountPoints($this->superShare->getShareOwner()); $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); - list($this->sourceStorage, $sourceInternalPath) = $this->ownerView->resolvePath($sourcePath); - $this->sourceRootInfo = $this->sourceStorage->getCache()->get($sourceInternalPath); + list($this->storage, $this->rootPath) = $this->ownerView->resolvePath($sourcePath); + $this->sourceRootInfo = $this->storage->getCache()->get($this->rootPath); } catch (\Exception $e) { $this->logger->logException($e); } @@ -302,13 +293,13 @@ class Shared extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage { public function getCache($path = '', $storage = null) { $this->init(); - if (is_null($this->sourceStorage)) { + if (is_null($this->storage)) { return new FailedCache(false); } if (!$storage) { $storage = $this; } - return new \OCA\Files_Sharing\Cache($storage, $this->sourceStorage, $this->sourceRootInfo); + return new \OCA\Files_Sharing\Cache($storage, $this->storage, $this->sourceRootInfo); } public function getScanner($path = '', $storage = null) { @@ -408,8 +399,9 @@ class Shared extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage { // shares do not participate in availability logic } - public function getSourceStorage() { - return $this->sourceStorage; + public function getWrapperStorage() { + $this->init(); + return $this->storage; } public function file_get_contents($path) { From 58b810a5477fc18c2b99a714da7f84199cc02ee6 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 22 Aug 2016 12:32:39 +0200 Subject: [PATCH 5/6] handle failed shares --- apps/files_sharing/lib/sharedstorage.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 7a7bb58982..b67c9c5efb 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -95,6 +95,8 @@ class Shared extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage { list($this->storage, $this->rootPath) = $this->ownerView->resolvePath($sourcePath); $this->sourceRootInfo = $this->storage->getCache()->get($this->rootPath); } catch (\Exception $e) { + $this->storage = new FailedStorage(['exception' => $e]); + $this->rootPath = ''; $this->logger->logException($e); } } @@ -293,7 +295,7 @@ class Shared extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage { public function getCache($path = '', $storage = null) { $this->init(); - if (is_null($this->storage)) { + if (is_null($this->storage) || $this->storage instanceof FailedStorage) { return new FailedCache(false); } if (!$storage) { From fa980af53c2ec3f024a5f4e25d2011e95c6e83e7 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 22 Aug 2016 15:12:39 +0200 Subject: [PATCH 6/6] prevent infinite recursion while getting storage from mount --- apps/files_sharing/lib/sharedstorage.php | 4 ++++ lib/private/Files/Mount/MountPoint.php | 18 ++++++++++-------- tests/lib/Files/Mount/MountPointTest.php | 8 ++++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index b67c9c5efb..6dec020982 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -401,6 +401,10 @@ class Shared extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage { // shares do not participate in availability logic } + public function getSourceStorage() { + return $this->getWrapperStorage(); + } + public function getWrapperStorage() { $this->init(); return $this->storage; diff --git a/lib/private/Files/Mount/MountPoint.php b/lib/private/Files/Mount/MountPoint.php index 8b8f0574ae..4aef340149 100644 --- a/lib/private/Files/Mount/MountPoint.php +++ b/lib/private/Files/Mount/MountPoint.php @@ -70,7 +70,7 @@ class MountPoint implements IMountPoint { */ private $invalidStorage = false; - /** @var int|null */ + /** @var int|null */ protected $mountId; /** @@ -132,18 +132,20 @@ class MountPoint implements IMountPoint { /** * create the storage that is mounted - * - * @return \OC\Files\Storage\Storage */ private function createStorage() { if ($this->invalidStorage) { - return null; + return; } if (class_exists($this->class)) { try { - return $this->loader->getInstance($this, $this->class, $this->arguments); + $class = $this->class; + // prevent recursion by setting the storage before applying wrappers + $this->storage = new $class($this->arguments); + $this->storage = $this->loader->wrap($this, $this->storage); } catch (\Exception $exception) { + $this->storage = null; $this->invalidStorage = true; if ($this->mountPoint === '/') { // the root storage could not be initialized, show the user! @@ -151,12 +153,12 @@ class MountPoint implements IMountPoint { } else { \OCP\Util::writeLog('core', $exception->getMessage(), \OCP\Util::ERROR); } - return null; + return; } } else { \OCP\Util::writeLog('core', 'storage backend ' . $this->class . ' not found', \OCP\Util::ERROR); $this->invalidStorage = true; - return null; + return; } } @@ -165,7 +167,7 @@ class MountPoint implements IMountPoint { */ public function getStorage() { if (is_null($this->storage)) { - $this->storage = $this->createStorage(); + $this->createStorage(); } return $this->storage; } diff --git a/tests/lib/Files/Mount/MountPointTest.php b/tests/lib/Files/Mount/MountPointTest.php index 392f10c717..799f441a1a 100644 --- a/tests/lib/Files/Mount/MountPointTest.php +++ b/tests/lib/Files/Mount/MountPointTest.php @@ -16,9 +16,9 @@ class MountPointTest extends \Test\TestCase { ->method('getId') ->will($this->returnValue(123)); - $loader = $this->getMock('\OCP\Files\Storage\IStorageFactory'); + $loader = $this->getMock('\OC\Files\Storage\StorageFactory'); $loader->expects($this->once()) - ->method('getInstance') + ->method('wrap') ->will($this->returnValue($storage)); $mountPoint = new \OC\Files\Mount\MountPoint( @@ -38,9 +38,9 @@ class MountPointTest extends \Test\TestCase { } public function testInvalidStorage() { - $loader = $this->getMock('\OCP\Files\Storage\IStorageFactory'); + $loader = $this->getMock('\OC\Files\Storage\StorageFactory'); $loader->expects($this->once()) - ->method('getInstance') + ->method('wrap') ->will($this->throwException(new \Exception('Test storage init exception'))); $called = false;