Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions lib/private/Avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
namespace OC;

use OC\User\User;
use OCP\Files\Folder;
use OCP\Files\File;
use OCP\Files\SimpleFS\Folder;
use OCP\Files\SimpleFS\File;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\IAvatar;
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);
$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
22 changes: 7 additions & 15 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 @@ -92,14 +91,7 @@ public function getAvatar($userId) {
throw new \Exception('user does not exist');
}

/*
* Fix for #22119
* Basically we do not want to copy the skeleton folder
*/
\OC\Files\Filesystem::initMountPoints($userId);
$dir = '/' . $userId;
/** @var Folder $folder */
$folder = $this->rootFolder->get($dir);
$folder = $this->appData->getFolder($userId);

return new Avatar($folder, $this->l, $user, $this->logger, $this->config);
}
Expand Down
31 changes: 31 additions & 0 deletions lib/private/Files/AppData/AppData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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\Root;
use OCP\Files\IAppData;

class AppData extends Root implements IAppData {

}
97 changes: 97 additions & 0 deletions lib/private/Files/AppData/Factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?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\SystemConfig;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;

class Factory {

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

/** @var Folder */
private $appDataFolder;

/** @var SystemConfig */
private $config;

public function __construct(IRootFolder $rootFolder,
SystemConfig $systemConfig) {

$this->rootFolder = $rootFolder;
$this->config = $systemConfig;
}

/**
* @return Folder
*/
private function getAppDataFolder() {
if ($this->appDataFolder === null) {
$instanceId = $this->config->getValue('instanceid', null);
if ($instanceId === null) {
throw new \RuntimeException('no instance id!');
}

/** @var string $instanceId */
try {
$appDataFolder = $this->rootFolder->get($instanceId);
} catch (NotFoundException $e) {
try {
$appDataFolder = $this->rootFolder->newFolder($instanceId);
} catch (NotPermittedException $e) {
// Log
return null;
}
}

$this->appDataFolder = $appDataFolder;
}

return $this->appDataFolder;
}

/**
* @param string $appId
* @return AppData
*/
public function get($appId) {
$appDataFolder = $this->getAppDataFolder();

try {
$appFolder = $appDataFolder->get($appId);
} catch (NotFoundException $e) {
try {
$appFolder = $appDataFolder->newFolder($appId);
} catch (NotPermittedException $e) {
// Log
return null;
}
}

return new AppData($appFolder);
}
}
113 changes: 113 additions & 0 deletions lib/private/Files/SimpleFS/File.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?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\SimpleFS;

use OCP\Files\NotPermittedException;

class File implements \OCP\Files\SimpleFS\File {

/** @var \OCP\Files\File $file */
private $file;

/**
* File constructor.
*
* @param \OCP\Files\File $file
*/
public function __construct(\OCP\Files\File $file) {
$this->file = $file;
}

/**
* Get the name
*
* @return string
*/
public function getName() {
return $this->file->getName();
}

/**
* Get the size in bytes
*
* @return int
*/
public function getSize() {
return $this->file->getSize();
}

/**
* Get the ETag
*
* @return string
*/
public function getETag() {
return $this->file->getEtag();
}

/**
* Get the last modification time
*
* @return int
*/
public function getMTime() {
return $this->file->getMTime();
}

/**
* Get the content
*
* @return string
*/
public function getContent() {
return $this->file->getContent();
}

/**
* Overwrite the file
*
* @param string $data
* @throws NotPermittedException
*/
public function putContent($data) {
$this->file->putContent($data);
}

/**
* Delete the file
*
* @throws NotPermittedException
*/
public function delete() {
$this->file->delete();
}

/**
* Get the MimeType
*
* @return string
*/
public function getMimeType() {
return $this->file->getMimeType();
}
}
Loading