Use fallback path if data dir is not available for Storage/Local.php
Found while testing strict types for PHP7+. Signed-off-by: Morris Jobke <hey@morrisjobke.de> Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
a02a7593cf
commit
bcba1a97ad
3 changed files with 15 additions and 7 deletions
|
@ -152,7 +152,7 @@ class MountPoint implements IMountPoint {
|
||||||
// the root storage could not be initialized, show the user!
|
// the root storage could not be initialized, show the user!
|
||||||
throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception);
|
throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception);
|
||||||
} else {
|
} else {
|
||||||
\OCP\Util::writeLog('core', $exception->getMessage(), \OCP\Util::ERROR);
|
\OC::$server->getLogger()->logException($exception, ['level' => \OCP\Util::ERROR]);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace OC\Files\Storage;
|
namespace OC\Files\Storage;
|
||||||
|
|
||||||
use OC\Files\Cache\HomePropagator;
|
use OC\Files\Cache\HomePropagator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,6 +44,7 @@ class Home extends Local implements \OCP\Files\IHomeStorage {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a Home storage instance
|
* Construct a Home storage instance
|
||||||
|
*
|
||||||
* @param array $arguments array with "user" containing the
|
* @param array $arguments array with "user" containing the
|
||||||
* storage owner
|
* storage owner
|
||||||
*/
|
*/
|
||||||
|
@ -51,7 +53,7 @@ class Home extends Local implements \OCP\Files\IHomeStorage {
|
||||||
$datadir = $this->user->getHome();
|
$datadir = $this->user->getHome();
|
||||||
$this->id = 'home::' . $this->user->getUID();
|
$this->id = 'home::' . $this->user->getUID();
|
||||||
|
|
||||||
parent::__construct(array('datadir' => $datadir));
|
parent::__construct(['datadir' => $datadir]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId() {
|
public function getId() {
|
||||||
|
@ -90,6 +92,7 @@ class Home extends Local implements \OCP\Files\IHomeStorage {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the owner of this home storage
|
* Returns the owner of this home storage
|
||||||
|
*
|
||||||
* @return \OC\User\User owner of this home storage
|
* @return \OC\User\User owner of this home storage
|
||||||
*/
|
*/
|
||||||
public function getUser() {
|
public function getUser() {
|
||||||
|
|
|
@ -59,12 +59,13 @@ class Local extends \OC\Files\Storage\Common {
|
||||||
if (!isset($arguments['datadir']) || !is_string($arguments['datadir'])) {
|
if (!isset($arguments['datadir']) || !is_string($arguments['datadir'])) {
|
||||||
throw new \InvalidArgumentException('No data directory set for local storage');
|
throw new \InvalidArgumentException('No data directory set for local storage');
|
||||||
}
|
}
|
||||||
$this->datadir = $arguments['datadir'];
|
$this->datadir = str_replace('//', '/', $arguments['datadir']);
|
||||||
// some crazy code uses a local storage on root...
|
// some crazy code uses a local storage on root...
|
||||||
if ($this->datadir === '/') {
|
if ($this->datadir === '/') {
|
||||||
$this->realDataDir = $this->datadir;
|
$this->realDataDir = $this->datadir;
|
||||||
} else {
|
} else {
|
||||||
$this->realDataDir = rtrim(realpath($this->datadir), '/') . '/';
|
$realPath = realpath($this->datadir) ?: $this->datadir;
|
||||||
|
$this->realDataDir = rtrim($realPath, '/') . '/';
|
||||||
}
|
}
|
||||||
if (substr($this->datadir, -1) !== '/') {
|
if (substr($this->datadir, -1) !== '/') {
|
||||||
$this->datadir .= '/';
|
$this->datadir .= '/';
|
||||||
|
@ -361,14 +362,18 @@ class Local extends \OC\Files\Storage\Common {
|
||||||
*/
|
*/
|
||||||
public function getSourcePath($path) {
|
public function getSourcePath($path) {
|
||||||
$fullPath = $this->datadir . $path;
|
$fullPath = $this->datadir . $path;
|
||||||
if ($this->allowSymlinks || $path === '') {
|
$currentPath = $path;
|
||||||
|
if ($this->allowSymlinks || $currentPath === '') {
|
||||||
return $fullPath;
|
return $fullPath;
|
||||||
}
|
}
|
||||||
$pathToResolve = $fullPath;
|
$pathToResolve = $fullPath;
|
||||||
$realPath = realpath($pathToResolve);
|
$realPath = realpath($pathToResolve);
|
||||||
while ($realPath === false) { // for non existing files check the parent directory
|
while ($realPath === false) { // for non existing files check the parent directory
|
||||||
$pathToResolve = dirname($pathToResolve);
|
$currentPath = dirname($currentPath);
|
||||||
$realPath = realpath($pathToResolve);
|
if ($currentPath === '' || $currentPath === '.') {
|
||||||
|
return $fullPath;
|
||||||
|
}
|
||||||
|
$realPath = realpath($this->datadir . $currentPath);
|
||||||
}
|
}
|
||||||
if ($realPath) {
|
if ($realPath) {
|
||||||
$realPath = $realPath . '/';
|
$realPath = $realPath . '/';
|
||||||
|
|
Loading…
Reference in a new issue