diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-03-20 11:31:28 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-03-20 11:31:28 +0100 |
commit | 36c0f08ec0c5327f9b38f1078ee0d6ef8823b8da (patch) | |
tree | f87533f1a2338101b9b37067071109c9b89dc7c3 /lib | |
parent | 970878b5815da97df517688b811265531c7e152f (diff) | |
parent | 082c4cda50c6dbb9ba9ca96c641f0db1eeb7ff1a (diff) | |
download | nextcloud-server-36c0f08ec0c5327f9b38f1078ee0d6ef8823b8da.tar.gz nextcloud-server-36c0f08ec0c5327f9b38f1078ee0d6ef8823b8da.zip |
Merge pull request #7732 from owncloud/datafolderexistence
Added .ocdata file to check for data folder validity
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 1 | ||||
-rw-r--r-- | lib/private/response.php | 4 | ||||
-rw-r--r-- | lib/private/setup.php | 4 | ||||
-rw-r--r-- | lib/private/updater.php | 5 | ||||
-rwxr-xr-x | lib/private/util.php | 32 |
5 files changed, 42 insertions, 4 deletions
diff --git a/lib/base.php b/lib/base.php index 73553ff6417..cc710fc7207 100644 --- a/lib/base.php +++ b/lib/base.php @@ -518,6 +518,7 @@ class OC { echo $error['hint'] . "\n\n"; } } else { + OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); OC_Template::printGuestPage('', 'error', array('errors' => $errors)); } exit; diff --git a/lib/private/response.php b/lib/private/response.php index 71c538fb311..983c682bf3f 100644 --- a/lib/private/response.php +++ b/lib/private/response.php @@ -12,6 +12,7 @@ class OC_Response { const STATUS_TEMPORARY_REDIRECT = 307; const STATUS_NOT_FOUND = 404; const STATUS_INTERNAL_SERVER_ERROR = 500; + const STATUS_SERVICE_UNAVAILABLE = 503; /** * @brief Enable response caching by sending correct HTTP headers @@ -74,6 +75,9 @@ class OC_Response { case self::STATUS_INTERNAL_SERVER_ERROR; $status = $status . ' Internal Server Error'; break; + case self::STATUS_SERVICE_UNAVAILABLE; + $status = $status . ' Service Unavailable'; + break; } header($protocol.' '.$status); } diff --git a/lib/private/setup.php b/lib/private/setup.php index 0d5bf424b33..b1061b3a25b 100644 --- a/lib/private/setup.php +++ b/lib/private/setup.php @@ -106,6 +106,10 @@ class OC_Setup { //guess what this does OC_Installer::installShippedApps(); + // create empty file in data dir, so we can later find + // out that this is indeed an ownCloud data directory + file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/.ocdata', ''); + //create htaccess files for apache hosts if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { self::createHtaccess(); diff --git a/lib/private/updater.php b/lib/private/updater.php index 1354f3fd2f8..18864c17ec9 100644 --- a/lib/private/updater.php +++ b/lib/private/updater.php @@ -102,6 +102,11 @@ class Updater extends BasicEmitter { } $this->emit('\OC\Updater', 'maintenanceStart'); + // create empty file in data dir, so we can later find + // out that this is indeed an ownCloud data directory + // (in case it didn't exist before) + file_put_contents(\OC_Config::getValue('datadirectory', \OC::$SERVERROOT.'/data').'/.ocdata', ''); + /* * START CONFIG CHANGES FOR OLDER VERSIONS */ diff --git a/lib/private/util.php b/lib/private/util.php index fc78566e456..70dadb1befd 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -290,13 +290,19 @@ class OC_Util { * @return array arrays with error messages and hints */ public static function checkServer() { + $errors = array(); + $CONFIG_DATADIRECTORY = OC_Config::getValue('datadirectory', OC::$SERVERROOT . '/data'); + + if (!\OC::needUpgrade() && OC_Config::getValue('installed', false)) { + // this check needs to be done every time + $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); + } + // Assume that if checkServer() succeeded before in this session, then all is fine. if(\OC::$session->exists('checkServer_suceeded') && \OC::$session->get('checkServer_suceeded')) { - return array(); + return $errors; } - $errors = array(); - $defaults = new \OC_Defaults(); $webServerRestart = false; @@ -341,7 +347,6 @@ class OC_Util { ); } } - $CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); // Create root dir. if(!is_dir($CONFIG_DATADIRECTORY)) { $success=@mkdir($CONFIG_DATADIRECTORY); @@ -541,6 +546,25 @@ class OC_Util { } /** + * Check that the data directory exists and is valid by + * checking the existence of the ".ocdata" file. + * + * @param string $dataDirectory data directory path + * @return bool true if the data directory is valid, false otherwise + */ + public static function checkDataDirectoryValidity($dataDirectory) { + $errors = array(); + if (!file_exists($dataDirectory.'/.ocdata')) { + $errors[] = array( + 'error' => 'Data directory (' . $dataDirectory . ') is invalid', + 'hint' => 'Please check that the data directory contains a file' . + ' ".ocdata" in its root.' + ); + } + return $errors; + } + + /** * @return void */ public static function displayLoginPage($errors = array()) { |