From a7596d9799fb1dd5ae8e56444c317aa4341fe434 Mon Sep 17 00:00:00 2001 From: Jackson Murtha Date: Tue, 7 Mar 2017 20:26:30 -0600 Subject: [PATCH 1/2] Delay checking if local phar file is writable until it needs to be written --- src/Updater.php | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Updater.php b/src/Updater.php index 838d6b0..6e16dc0 100644 --- a/src/Updater.php +++ b/src/Updater.php @@ -371,7 +371,14 @@ protected function downloadPhar() protected function replacePhar() { - rename($this->getTempPharFile(), $this->getLocalPharFile()); + $localPharFile = $this->getLocalPharFile(); + if (!is_writable($localPharFile)) { + throw new FilesystemException(sprintf( + 'The current phar file is not writeable and cannot be replaced: %s.', + $localPharFile + )); + } + rename($this->getTempPharFile(), $localPharFile); } protected function restorePhar() @@ -383,7 +390,15 @@ protected function restorePhar() )); } $this->validatePhar($backup); - return rename($backup, $this->getLocalPharFile()); + + $localPharFile = $this->getLocalPharFile(); + if (!is_writable($localPharFile)) { + throw new FilesystemException(sprintf( + 'The current phar file is not writeable and cannot be replaced: %s.', + $localPharFile + )); + } + return rename($backup, $localPharFile); } protected function getBackupPharFile() @@ -426,12 +441,6 @@ protected function setLocalPharFile($localPharFile) 'The set phar file does not exist: %s.', $localPharFile )); } - if (!is_writable($localPharFile)) { - throw new FilesystemException(sprintf( - 'The current phar file is not writeable and cannot be replaced: %s.', - $localPharFile - )); - } $this->localPharFile = $localPharFile; $this->localPharFileBasename = basename($localPharFile, '.phar'); } From 2be819fc53a78b361187797524c9178eda30ea2f Mon Sep 17 00:00:00 2001 From: Jackson Murtha Date: Tue, 7 Mar 2017 20:45:31 -0600 Subject: [PATCH 2/2] delay checking if temp directory is writable until it needs to be written to --- src/Updater.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Updater.php b/src/Updater.php index 6e16dc0..77996a9 100644 --- a/src/Updater.php +++ b/src/Updater.php @@ -327,6 +327,13 @@ protected function newVersionAvailable() protected function backupPhar() { + $tempDirectory = $this->getTempDirectory(); + if (!is_writable($tempDirectory)) { + throw new FilesystemException(sprintf( + 'The directory is not writeable: %s.', $tempDirectory + )); + } + $result = copy($this->getLocalPharFile(), $this->getBackupPharFile()); if ($result === false) { $this->cleanupAfterError(); @@ -340,6 +347,13 @@ protected function backupPhar() protected function downloadPhar() { + $tempDirectory = $this->getTempDirectory(); + if (!is_writable($tempDirectory)) { + throw new FilesystemException(sprintf( + 'The directory is not writeable: %s.', $tempDirectory + )); + } + $this->strategy->download($this); if (!file_exists($this->getTempPharFile())) { @@ -383,6 +397,13 @@ protected function replacePhar() protected function restorePhar() { + $tempDirectory = $this->getTempDirectory(); + if (!is_writable($tempDirectory)) { + throw new FilesystemException(sprintf( + 'The directory is not writeable: %s.', $tempDirectory + )); + } + $backup = $this->getRestorePharFile(); if (!file_exists($backup)) { throw new RuntimeException(sprintf( @@ -459,11 +480,6 @@ protected function setLocalPubKeyFile() protected function setTempDirectory() { $tempDirectory = dirname($this->getLocalPharFile()); - if (!is_writable($tempDirectory)) { - throw new FilesystemException(sprintf( - 'The directory is not writeable: %s.', $tempDirectory - )); - } $this->tempDirectory = $tempDirectory; }