diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-03-28 11:28:33 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-03-28 11:28:33 +0100 |
commit | 3f891c2650ce587bc9a3a52b25cac1a9b93f261c (patch) | |
tree | cbc96a9411453ad3b9785c83703dfdcc22c7fbf0 | |
parent | 8b9b6006445f651ab050d18eb87a3b4ca5340e57 (diff) | |
parent | 1511a42da78bc4fbc2c202112bf10d249e3dc92f (diff) | |
download | nextcloud-server-3f891c2650ce587bc9a3a52b25cac1a9b93f261c.tar.gz nextcloud-server-3f891c2650ce587bc9a3a52b25cac1a9b93f261c.zip |
Merge pull request #15288 from owncloud/check-datadir-relative
Check for relative datadirectory path
-rw-r--r-- | lib/private/util.php | 16 | ||||
-rw-r--r-- | tests/lib/util.php | 19 |
2 files changed, 30 insertions, 5 deletions
diff --git a/lib/private/util.php b/lib/private/util.php index a0ef491d9db..5aa65401b9a 100644 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -886,17 +886,23 @@ class OC_Util { * checking the existence of the ".ocdata" file. * * @param string $dataDirectory data directory path - * @return bool true if the data directory is valid, false otherwise + * @return array errors found */ public static function checkDataDirectoryValidity($dataDirectory) { $l = \OC::$server->getL10N('lib'); - $errors = array(); + $errors = []; + if (!self::runningOnWindows() && $dataDirectory[0] !== '/') { + $errors[] = [ + 'error' => $l->t('Data directory (%s) must be an absolute path', [$dataDirectory]), + 'hint' => $l->t('Check the value of "datadirectory" in your configuration') + ]; + } if (!file_exists($dataDirectory . '/.ocdata')) { - $errors[] = array( - 'error' => $l->t('Data directory (%s) is invalid', array($dataDirectory)), + $errors[] = [ + 'error' => $l->t('Data directory (%s) is invalid', [$dataDirectory]), 'hint' => $l->t('Please check that the data directory contains a file' . ' ".ocdata" in its root.') - ); + ]; } return $errors; } diff --git a/tests/lib/util.php b/tests/lib/util.php index 4082c28f050..7d9064e0a2f 100644 --- a/tests/lib/util.php +++ b/tests/lib/util.php @@ -419,6 +419,25 @@ class Test_Util extends \Test\TestCase { $this->assertFalse(\OCP\Util::needUpgrade()); } + + public function testCheckDataDirectoryValidity() { + $dataDir = \OCP\Files::tmpFolder(); + touch($dataDir . '/.ocdata'); + $errors = \OC_Util::checkDataDirectoryValidity($dataDir); + $this->assertEmpty($errors); + \OCP\Files::rmdirr($dataDir); + + $dataDir = \OCP\Files::tmpFolder(); + // no touch + $errors = \OC_Util::checkDataDirectoryValidity($dataDir); + $this->assertNotEmpty($errors); + \OCP\Files::rmdirr($dataDir); + + if (!\OC_Util::runningOnWindows()) { + $errors = \OC_Util::checkDataDirectoryValidity('relative/path'); + $this->assertNotEmpty($errors); + } + } } /** |