Skip to content
10 changes: 10 additions & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
'OCP\\Files\\FileNameTooLongException' => $baseDir . '/lib/public/Files/FileNameTooLongException.php',
'OCP\\Files\\Folder' => $baseDir . '/lib/public/Files/Folder.php',
'OCP\\Files\\ForbiddenException' => $baseDir . '/lib/public/Files/ForbiddenException.php',
'OCP\\Files\\IAppData' => $baseDir . '/lib/public/Files/IAppData.php',
'OCP\\Files\\IHomeStorage' => $baseDir . '/lib/public/Files/IHomeStorage.php',
'OCP\\Files\\IMimeTypeDetector' => $baseDir . '/lib/public/Files/IMimeTypeDetector.php',
'OCP\\Files\\IMimeTypeLoader' => $baseDir . '/lib/public/Files/IMimeTypeLoader.php',
Expand All @@ -123,6 +124,9 @@
'OCP\\Files\\NotPermittedException' => $baseDir . '/lib/public/Files/NotPermittedException.php',
'OCP\\Files\\ObjectStore\\IObjectStore' => $baseDir . '/lib/public/Files/ObjectStore/IObjectStore.php',
'OCP\\Files\\ReservedWordException' => $baseDir . '/lib/public/Files/ReservedWordException.php',
'OCP\\Files\\SimpleFS\\ISimpleFile' => $baseDir . '/lib/public/Files/SimpleFS/ISimpleFile.php',
'OCP\\Files\\SimpleFS\\ISimpleFolder' => $baseDir . '/lib/public/Files/SimpleFS/ISimpleFolder.php',
'OCP\\Files\\SimpleFS\\ISimpleRoot' => $baseDir . '/lib/public/Files/SimpleFS/ISimpleRoot.php',
'OCP\\Files\\Storage' => $baseDir . '/lib/public/Files/Storage.php',
'OCP\\Files\\StorageAuthException' => $baseDir . '/lib/public/Files/StorageAuthException.php',
'OCP\\Files\\StorageBadConfigException' => $baseDir . '/lib/public/Files/StorageBadConfigException.php',
Expand Down Expand Up @@ -459,6 +463,8 @@
'OC\\Encryption\\Manager' => $baseDir . '/lib/private/Encryption/Manager.php',
'OC\\Encryption\\Update' => $baseDir . '/lib/private/Encryption/Update.php',
'OC\\Encryption\\Util' => $baseDir . '/lib/private/Encryption/Util.php',
'OC\\Files\\AppData\\AppData' => $baseDir . '/lib/private/Files/AppData/AppData.php',
'OC\\Files\\AppData\\Factory' => $baseDir . '/lib/private/Files/AppData/Factory.php',
'OC\\Files\\Cache\\Cache' => $baseDir . '/lib/private/Files/Cache/Cache.php',
'OC\\Files\\Cache\\CacheEntry' => $baseDir . '/lib/private/Files/Cache/CacheEntry.php',
'OC\\Files\\Cache\\FailedCache' => $baseDir . '/lib/private/Files/Cache/FailedCache.php',
Expand Down Expand Up @@ -500,6 +506,8 @@
'OC\\Files\\ObjectStore\\NoopScanner' => $baseDir . '/lib/private/Files/ObjectStore/NoopScanner.php',
'OC\\Files\\ObjectStore\\ObjectStoreStorage' => $baseDir . '/lib/private/Files/ObjectStore/ObjectStoreStorage.php',
'OC\\Files\\ObjectStore\\Swift' => $baseDir . '/lib/private/Files/ObjectStore/Swift.php',
'OC\\Files\\SimpleFS\\SimpleFile' => $baseDir . '/lib/private/Files/SimpleFS/SimpleFile.php',
'OC\\Files\\SimpleFS\\SimpleFolder' => $baseDir . '/lib/private/Files/SimpleFS/SimpleFolder.php',
'OC\\Files\\Storage\\Common' => $baseDir . '/lib/private/Files/Storage/Common.php',
'OC\\Files\\Storage\\CommonTest' => $baseDir . '/lib/private/Files/Storage/CommonTest.php',
'OC\\Files\\Storage\\DAV' => $baseDir . '/lib/private/Files/Storage/DAV.php',
Expand Down Expand Up @@ -638,6 +646,8 @@
'OC\\Repair\\FillETags' => $baseDir . '/lib/private/Repair/FillETags.php',
'OC\\Repair\\InnoDB' => $baseDir . '/lib/private/Repair/InnoDB.php',
'OC\\Repair\\MoveUpdaterStepFile' => $baseDir . '/lib/private/Repair/MoveUpdaterStepFile.php',
'OC\\Repair\\NC11\\MoveAvatars' => $baseDir . '/lib/private/Repair/NC11/MoveAvatars.php',
'OC\\Repair\\NC11\\MoveAvatarsBackgroundJob' => $baseDir . '/lib/private/Repair/NC11/MoveAvatarBackgroundJob.php',
'OC\\Repair\\OldGroupMembershipShares' => $baseDir . '/lib/private/Repair/OldGroupMembershipShares.php',
'OC\\Repair\\Preview' => $baseDir . '/lib/private/Repair/Preview.php',
'OC\\Repair\\RemoveGetETagEntries' => $baseDir . '/lib/private/Repair/RemoveGetETagEntries.php',
Expand Down
10 changes: 10 additions & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Files\\FileNameTooLongException' => __DIR__ . '/../../..' . '/lib/public/Files/FileNameTooLongException.php',
'OCP\\Files\\Folder' => __DIR__ . '/../../..' . '/lib/public/Files/Folder.php',
'OCP\\Files\\ForbiddenException' => __DIR__ . '/../../..' . '/lib/public/Files/ForbiddenException.php',
'OCP\\Files\\IAppData' => __DIR__ . '/../../..' . '/lib/public/Files/IAppData.php',
'OCP\\Files\\IHomeStorage' => __DIR__ . '/../../..' . '/lib/public/Files/IHomeStorage.php',
'OCP\\Files\\IMimeTypeDetector' => __DIR__ . '/../../..' . '/lib/public/Files/IMimeTypeDetector.php',
'OCP\\Files\\IMimeTypeLoader' => __DIR__ . '/../../..' . '/lib/public/Files/IMimeTypeLoader.php',
Expand All @@ -153,6 +154,9 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Files\\NotPermittedException' => __DIR__ . '/../../..' . '/lib/public/Files/NotPermittedException.php',
'OCP\\Files\\ObjectStore\\IObjectStore' => __DIR__ . '/../../..' . '/lib/public/Files/ObjectStore/IObjectStore.php',
'OCP\\Files\\ReservedWordException' => __DIR__ . '/../../..' . '/lib/public/Files/ReservedWordException.php',
'OCP\\Files\\SimpleFS\\ISimpleFile' => __DIR__ . '/../../..' . '/lib/public/Files/SimpleFS/ISimpleFile.php',
'OCP\\Files\\SimpleFS\\ISimpleFolder' => __DIR__ . '/../../..' . '/lib/public/Files/SimpleFS/ISimpleFolder.php',
'OCP\\Files\\SimpleFS\\ISimpleRoot' => __DIR__ . '/../../..' . '/lib/public/Files/SimpleFS/ISimpleRoot.php',
'OCP\\Files\\Storage' => __DIR__ . '/../../..' . '/lib/public/Files/Storage.php',
'OCP\\Files\\StorageAuthException' => __DIR__ . '/../../..' . '/lib/public/Files/StorageAuthException.php',
'OCP\\Files\\StorageBadConfigException' => __DIR__ . '/../../..' . '/lib/public/Files/StorageBadConfigException.php',
Expand Down Expand Up @@ -489,6 +493,8 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Encryption\\Manager' => __DIR__ . '/../../..' . '/lib/private/Encryption/Manager.php',
'OC\\Encryption\\Update' => __DIR__ . '/../../..' . '/lib/private/Encryption/Update.php',
'OC\\Encryption\\Util' => __DIR__ . '/../../..' . '/lib/private/Encryption/Util.php',
'OC\\Files\\AppData\\AppData' => __DIR__ . '/../../..' . '/lib/private/Files/AppData/AppData.php',
'OC\\Files\\AppData\\Factory' => __DIR__ . '/../../..' . '/lib/private/Files/AppData/Factory.php',
'OC\\Files\\Cache\\Cache' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/Cache.php',
'OC\\Files\\Cache\\CacheEntry' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/CacheEntry.php',
'OC\\Files\\Cache\\FailedCache' => __DIR__ . '/../../..' . '/lib/private/Files/Cache/FailedCache.php',
Expand Down Expand Up @@ -530,6 +536,8 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Files\\ObjectStore\\NoopScanner' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/NoopScanner.php',
'OC\\Files\\ObjectStore\\ObjectStoreStorage' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/ObjectStoreStorage.php',
'OC\\Files\\ObjectStore\\Swift' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/Swift.php',
'OC\\Files\\SimpleFS\\SimpleFile' => __DIR__ . '/../../..' . '/lib/private/Files/SimpleFS/SimpleFile.php',
'OC\\Files\\SimpleFS\\SimpleFolder' => __DIR__ . '/../../..' . '/lib/private/Files/SimpleFS/SimpleFolder.php',
'OC\\Files\\Storage\\Common' => __DIR__ . '/../../..' . '/lib/private/Files/Storage/Common.php',
'OC\\Files\\Storage\\CommonTest' => __DIR__ . '/../../..' . '/lib/private/Files/Storage/CommonTest.php',
'OC\\Files\\Storage\\DAV' => __DIR__ . '/../../..' . '/lib/private/Files/Storage/DAV.php',
Expand Down Expand Up @@ -668,6 +676,8 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Repair\\FillETags' => __DIR__ . '/../../..' . '/lib/private/Repair/FillETags.php',
'OC\\Repair\\InnoDB' => __DIR__ . '/../../..' . '/lib/private/Repair/InnoDB.php',
'OC\\Repair\\MoveUpdaterStepFile' => __DIR__ . '/../../..' . '/lib/private/Repair/MoveUpdaterStepFile.php',
'OC\\Repair\\NC11\\MoveAvatars' => __DIR__ . '/../../..' . '/lib/private/Repair/NC11/MoveAvatars.php',
'OC\\Repair\\NC11\\MoveAvatarsBackgroundJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC11/MoveAvatarBackgroundJob.php',
'OC\\Repair\\OldGroupMembershipShares' => __DIR__ . '/../../..' . '/lib/private/Repair/OldGroupMembershipShares.php',
'OC\\Repair\\Preview' => __DIR__ . '/../../..' . '/lib/private/Repair/Preview.php',
'OC\\Repair\\RemoveGetETagEntries' => __DIR__ . '/../../..' . '/lib/private/Repair/RemoveGetETagEntries.php',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use OC\Core\Middleware\TwoFactorMiddleware;
use OCP\AppFramework\IApi;
use OCP\AppFramework\IAppContainer;
use OCP\Files\IAppData;


class DIContainer extends SimpleContainer implements IAppContainer {
Expand Down Expand Up @@ -164,6 +165,10 @@ public function __construct($appName, $urlParams = array()){
return $this->getServer()->getHTTPClientService();
});

$this->registerService(IAppData::class, function (SimpleContainer $c) {
return $this->getServer()->getAppDataDir($c->query('AppName'));
});

$this->registerService('OCP\\IGroupManager', function($c) {
return $this->getServer()->getGroupManager();
});
Expand Down
23 changes: 12 additions & 11 deletions lib/private/Avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
namespace OC;

use OC\User\User;
use OCP\Files\Folder;
use OCP\Files\File;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\IAvatar;
use OCP\IConfig;
use OCP\IImage;
Expand All @@ -45,7 +45,7 @@
*/

class Avatar implements IAvatar {
/** @var Folder */
/** @var ISimpleFolder */
private $folder;
/** @var IL10N */
private $l;
Expand All @@ -59,13 +59,13 @@ class Avatar implements IAvatar {
/**
* constructor
*
* @param Folder $folder The folder where the avatars are
* @param ISimpleFolder $folder The folder where the avatars are
* @param IL10N $l
* @param User $user
* @param ILogger $logger
* @param IConfig $config
*/
public function __construct(Folder $folder,
public function __construct(ISimpleFolder $folder,
IL10N $l,
$user,
ILogger $logger,
Expand Down Expand Up @@ -98,7 +98,8 @@ public function get ($size = 64) {
* @return bool
*/
public function exists() {
return $this->folder->nodeExists('avatar.jpg') || $this->folder->nodeExists('avatar.png');

return $this->folder->fileExists('avatar.jpg') || $this->folder->fileExists('avatar.png');
}

/**
Expand Down Expand Up @@ -170,15 +171,15 @@ public function getFile($size) {
}

try {
$file = $this->folder->get($path);
$file = $this->folder->getFile($path);
} catch (NotFoundException $e) {
if ($size <= 0) {
throw new NotFoundException;
}

$avatar = new OC_Image();
/** @var File $file */
$file = $this->folder->get('avatar.' . $ext);
/** @var ISimpleFile $file */
$file = $this->folder->getFile('avatar.' . $ext);
$avatar->loadFromData($file->getContent());
if ($size !== -1) {
$avatar->resize($size);
Expand All @@ -201,9 +202,9 @@ public function getFile($size) {
* @throws NotFoundException
*/
private function getExtension() {
if ($this->folder->nodeExists('avatar.jpg')) {
if ($this->folder->fileExists('avatar.jpg')) {
return 'jpg';
} elseif ($this->folder->nodeExists('avatar.png')) {
} elseif ($this->folder->fileExists('avatar.png')) {
return 'png';
}
throw new NotFoundException;
Expand Down
29 changes: 10 additions & 19 deletions lib/private/AvatarManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@

namespace OC;

use OCP\Files\Folder;
use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IUserManager;
use OCP\Files\IRootFolder;
use OCP\IL10N;

/**
Expand All @@ -44,8 +43,8 @@ class AvatarManager implements IAvatarManager {
/** @var IUserManager */
private $userManager;

/** @var IRootFolder */
private $rootFolder;
/** @var IAppData */
private $appData;

/** @var IL10N */
private $l;
Expand All @@ -60,19 +59,19 @@ class AvatarManager implements IAvatarManager {
* AvatarManager constructor.
*
* @param IUserManager $userManager
* @param IRootFolder $rootFolder
* @param IAppData $appData
* @param IL10N $l
* @param ILogger $logger
* @param IConfig $config
*/
public function __construct(
IUserManager $userManager,
IRootFolder $rootFolder,
IAppData $appData,
IL10N $l,
ILogger $logger,
IConfig $config) {
$this->userManager = $userManager;
$this->rootFolder = $rootFolder;
$this->appData = $appData;
$this->l = $l;
$this->logger = $logger;
$this->config = $config;
Expand All @@ -95,20 +94,12 @@ public function getAvatar($userId) {
// sanitize userID - fixes casing issue (needed for the filesystem stuff that is done below)
$userId = $user->getUID();

/*
* Fix for #22119
* Basically we do not want to copy the skeleton folder.
*
* For unit test purposes this is ignored when run in PHPUnit.
*/
if(!defined('PHPUNIT_RUN')) {
\OC\Files\Filesystem::initMountPoints($userId);
try {
$folder = $this->appData->getFolder($userId);
} catch (NotFoundException $e) {
$folder = $this->appData->newFolder($userId);
}

$dir = '/' . $userId;
/** @var Folder $folder */
$folder = $this->rootFolder->get($dir);

return new Avatar($folder, $this->l, $user, $this->logger, $this->config);
}
}
131 changes: 131 additions & 0 deletions lib/private/Files/AppData/AppData.php
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!');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc block please

}

$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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a NOP since the entries are either an instance of SimpleFolder or null.

If no callback is supplied, all entries of array equal to FALSE (see converting to boolean) will be removed.

(from http://php.net/manual/en/function.array-filter.php)

Copy link
Member Author

Choose a reason for hiding this comment

The 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);
}
}
Loading