Skip to content

Commit

Permalink
Merge pull request #65 from hydephp/fix-selfupdate-command-issues
Browse files Browse the repository at this point in the history
Try renaming updated file to catch and rethrow with permissions hint
  • Loading branch information
caendesilva authored Apr 17, 2024
2 parents cfb18bf + 643163a commit a5f3b4b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/Commands/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,18 @@ protected function replaceApplication(string $downloadedFile): void
$this->debug("Moving file $downloadedFile to $applicationPath");

// Replace the current application with the downloaded one
rename($downloadedFile, $applicationPath);
try {
// This might give Permission denied if we can't write to the bin path (might need sudo)
rename($downloadedFile, $applicationPath);
} catch (Throwable $exception) {
// Check if it is a permission issue
if (Str::containsAll($exception->getMessage(), ['rename', 'Permission denied'])) {
throw new RuntimeException('The application path is not writable. Please rerun the command with elevated privileges (e.g. using sudo).', 126, $exception);
}

// Unknown error, rethrow the exception
throw $exception;
}
}

protected function updateViaComposer(): void
Expand Down

0 comments on commit a5f3b4b

Please sign in to comment.