Browse Source

added check for gitlock file on docker update

CauseFX 3 years ago
parent
commit
c66ecead74
1 changed files with 22 additions and 1 deletions
  1. 22 1
      api/functions/update-functions.php

+ 22 - 1
api/functions/update-functions.php

@@ -7,7 +7,7 @@ trait UpdateFunctions
 		if (file_exists($script)) {
 			if (is_executable($script)) {
 				return true;
-			} elseif ($retest == false) {
+			} elseif (!$retest) {
 				$this->setLoggerChannel('Update')->notice('Attempting to set correct permissions', ['file' => $script]);
 				$permissions = shell_exec('chmod 777 ' . $script);
 				return $this->testScriptFilePermissions($script, true);
@@ -53,6 +53,23 @@ trait UpdateFunctions
 		return file_exists($this->config['dbLocation'] . 'updateInProgress.txt');
 	}
 
+	public function checkForGitLockFile()
+	{
+		return file_exists($this->root . DIRECTORY_SEPARATOR . '.git' . DIRECTORY_SEPARATOR . 'index.lock');
+	}
+
+	public function removeGitLockFile()
+	{
+		if ($this->checkForGitLockFile()) {
+			$removed = false;
+			if (@unlink($this->root . DIRECTORY_SEPARATOR . '.git' . DIRECTORY_SEPARATOR . 'index.lock')) {
+				$removed = true;
+			}
+			return $removed;
+		}
+		return true;
+	}
+
 	public function dockerUpdate()
 	{
 		if (!$this->docker) {
@@ -65,6 +82,10 @@ trait UpdateFunctions
 		} else {
 			$this->createUpdateStatusFile();
 		}
+		if (!$this->removeGitLockFile()) {
+			$this->setResponse(500, 'Git Lock file was found and could not be removed.  Please remove manually');
+			return false;
+		}
 		$dockerUpdate = null;
 		ini_set('max_execution_time', 0);
 		set_time_limit(0);