-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Introducing AppData #1306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introducing AppData #1306
Changes from all commits
5d8b941
ac38a3a
6807cb6
92dc9e6
3260f69
f23390e
a961354
851769a
735abbc
537af9b
2578a81
a7be37d
7512683
316db0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| <?php | ||
| /** | ||
| * @copyright 2016 Roeland Jago Douma <roeland@famdouma.nl> | ||
| * | ||
| * @author Roeland Jago Douma <roeland@famdouma.nl> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| namespace OC\Files\AppData; | ||
|
|
||
| use OC\Files\SimpleFS\SimpleFolder; | ||
| use OCP\Files\IAppData; | ||
| use OCP\Files\IRootFolder; | ||
| use OCP\Files\Folder; | ||
| use OC\SystemConfig; | ||
| use OCP\Files\Node; | ||
| use OCP\Files\NotFoundException; | ||
| use OCP\Files\NotPermittedException; | ||
|
|
||
| class AppData implements IAppData { | ||
|
|
||
| /** @var IRootFolder */ | ||
| private $rootFolder; | ||
|
|
||
| /** @var SystemConfig */ | ||
| private $config; | ||
|
|
||
| /** @var string */ | ||
| private $appId; | ||
|
|
||
| /** @var Folder */ | ||
| private $folder; | ||
|
|
||
| /** | ||
| * AppData constructor. | ||
| * | ||
| * @param IRootFolder $rootFolder | ||
| * @param SystemConfig $systemConfig | ||
| * @param string $appId | ||
| */ | ||
| public function __construct(IRootFolder $rootFolder, | ||
| SystemConfig $systemConfig, | ||
| $appId) { | ||
|
|
||
| $this->rootFolder = $rootFolder; | ||
| $this->config = $systemConfig; | ||
| $this->appId = $appId; | ||
| } | ||
|
|
||
| /** | ||
| * @return Folder | ||
| * @throws \RuntimeException | ||
| */ | ||
| private function getAppDataFolder() { | ||
| if ($this->folder === null) { | ||
| $instanceId = $this->config->getValue('instanceid', null); | ||
| if ($instanceId === null) { | ||
| throw new \RuntimeException('no instance id!'); | ||
| } | ||
|
|
||
| $name = 'appdata_' . $instanceId; | ||
|
|
||
| try { | ||
| $appDataFolder = $this->rootFolder->get($name); | ||
| } catch (NotFoundException $e) { | ||
| try { | ||
| $appDataFolder = $this->rootFolder->newFolder($name); | ||
| } catch (NotPermittedException $e) { | ||
| throw new \RuntimeException('Could not get appdata folder'); | ||
| } | ||
| } | ||
|
|
||
| try { | ||
| $appDataFolder = $appDataFolder->get($this->appId); | ||
| } catch (NotFoundException $e) { | ||
| try { | ||
| $appDataFolder = $appDataFolder->newFolder($this->appId); | ||
| } catch (NotPermittedException $e) { | ||
| throw new \RuntimeException('Could not get appdata folder for ' . $this->appId); | ||
| } | ||
| } | ||
|
|
||
| $this->folder = $appDataFolder; | ||
| } | ||
|
|
||
| return $this->folder; | ||
| } | ||
|
|
||
| public function getFolder($name) { | ||
| $node = $this->getAppDataFolder()->get($name); | ||
|
|
||
| /** @var Folder $node */ | ||
| return new SimpleFolder($node); | ||
| } | ||
|
|
||
| public function newFolder($name) { | ||
| $folder = $this->getAppDataFolder()->newFolder($name); | ||
|
|
||
| return new SimpleFolder($folder); | ||
| } | ||
|
|
||
| public function getDirectoryListing() { | ||
| $listing = $this->getAppDataFolder()->getDirectoryListing(); | ||
|
|
||
| $fileListing = array_map(function(Node $folder) { | ||
| if ($folder instanceof Folder) { | ||
| return new SimpleFolder($folder); | ||
| } | ||
| return null; | ||
| }, $listing); | ||
|
|
||
| $fileListing = array_filter($fileListing); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like a NOP since the entries are either an instance of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is a typo in the docs to my knowledge... should be 'all entries of the array that equal to false' |
||
|
|
||
| return array_values($fileListing); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc block please