Browse Source

NFS-friendly is_writable() checks (#4780)

#fix https://github.com/FreshRSS/FreshRSS/issues/4779
Alexandre Alapetite 3 years ago
parent
commit
8864d514c8
4 changed files with 13 additions and 13 deletions
  1. 3 3
      app/Controllers/updateController.php
  2. 1 1
      app/Utils/feverUtil.php
  3. 4 4
      lib/lib_install.php
  4. 5 5
      lib/lib_rss.php

+ 3 - 3
app/Controllers/updateController.php

@@ -14,7 +14,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController {
 	public static function migrateToGitEdge() {
 		$errorMessage = 'Error during git checkout to edge branch. Please change branch manually!';
 
-		if (!is_writable(FRESHRSS_PATH . '/.git/')) {
+		if (!is_writable(FRESHRSS_PATH . '/.git/config')) {
 			throw new Exception($errorMessage);
 		}
 
@@ -118,7 +118,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController {
 			if ($version == '') {
 				$version = 'unknown';
 			}
-			if (is_writable(FRESHRSS_PATH)) {
+			if (touch(FRESHRSS_PATH . '/index.html')) {
 				$this->view->update_to_apply = true;
 				$this->view->message = array(
 					'status' => 'good',
@@ -217,7 +217,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController {
 	}
 
 	public function applyAction() {
-		if (!file_exists(UPDATE_FILENAME) || !is_writable(FRESHRSS_PATH) || Minz_Configuration::get('system')->disable_update) {
+		if (Minz_Configuration::get('system')->disable_update || !file_exists(UPDATE_FILENAME) || !touch(FRESHRSS_PATH . '/index.html')) {
 			Minz_Request::forward(array('c' => 'update'), true);
 		}
 

+ 1 - 1
app/Utils/feverUtil.php

@@ -13,7 +13,7 @@ class FreshRSS_fever_Util {
 			@mkdir(self::FEVER_PATH, 0770, true);
 		}
 
-		$ok = is_writable(self::FEVER_PATH);
+		$ok = touch(self::FEVER_PATH . '/index.html');	// is_writable() is not reliable for a folder on NFS
 		if (!$ok) {
 			Minz_Log::error("Could not save Fever API credentials. The directory does not have write access.");
 		}

+ 4 - 4
lib/lib_install.php

@@ -42,14 +42,14 @@ function checkRequirements($dbType = '') {
 	$json = function_exists('json_encode');
 	$mbstring = extension_loaded('mbstring');
 	// @phpstan-ignore-next-line
-	$data = DATA_PATH && is_writable(DATA_PATH);
+	$data = DATA_PATH && touch(DATA_PATH . '/index.html');	// is_writable() is not reliable for a folder on NFS
 	// @phpstan-ignore-next-line
-	$cache = CACHE_PATH && is_writable(CACHE_PATH);
+	$cache = CACHE_PATH && touch(CACHE_PATH . '/index.html');
 	// @phpstan-ignore-next-line
 	$tmp = TMP_PATH && is_writable(TMP_PATH);
 	// @phpstan-ignore-next-line
-	$users = USERS_PATH && is_writable(USERS_PATH);
-	$favicons = is_writable(join_path(DATA_PATH, 'favicons'));
+	$users = USERS_PATH && touch(USERS_PATH . '/index.html');
+	$favicons = touch(DATA_PATH . '/favicons/index.html');
 
 	return array(
 		'php' => $php ? 'ok' : 'ko',

+ 5 - 5
lib/lib_rss.php

@@ -696,13 +696,13 @@ function check_install_php() {
 function check_install_files() {
 	return array(
 		// @phpstan-ignore-next-line
-		'data' => DATA_PATH && is_writable(DATA_PATH),
+		'data' => DATA_PATH && touch(DATA_PATH . '/index.html'),	// is_writable() is not reliable for a folder on NFS
 		// @phpstan-ignore-next-line
-		'cache' => CACHE_PATH && is_writable(CACHE_PATH),
+		'cache' => CACHE_PATH && touch(CACHE_PATH . '/index.html'),
 		// @phpstan-ignore-next-line
-		'users' => USERS_PATH && is_writable(USERS_PATH),
-		'favicons' => is_writable(DATA_PATH . '/favicons'),
-		'tokens' => is_writable(DATA_PATH . '/tokens'),
+		'users' => USERS_PATH && touch(USERS_PATH . '/index.html'),
+		'favicons' => touch(DATA_PATH . '/favicons/index.html'),
+		'tokens' => touch(DATA_PATH . '/tokens/index.html'),
 	);
 }