From 4d7ecdcb6916e5225a4bc73316b8868db123f0be Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 17 Feb 2012 12:35:42 +0100 Subject: [PATCH] Fix authentication behavior when re-entering get() --- src/Composer/Util/RemoteFilesystem.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index c782ea83e..89325720f 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -25,7 +25,7 @@ class RemoteFilesystem private $originUrl; private $fileUrl; private $fileName; - private $content; + private $result; private $progess; private $lastProgress; @@ -46,10 +46,14 @@ class RemoteFilesystem * @param string $fileUrl The file URL * @param string $fileName the local filename * @param boolean $progess Display the progression + * + * @return Boolean true */ public function copy($originUrl, $fileUrl, $fileName, $progess = true) { $this->get($originUrl, $fileUrl, $fileName, $progess); + + return $this->result; } /** @@ -65,7 +69,7 @@ class RemoteFilesystem { $this->get($originUrl, $fileUrl, null, $progess); - return $this->content; + return $this->result; } /** @@ -83,7 +87,7 @@ class RemoteFilesystem { $this->firstCall = $firstCall; $this->bytesMax = 0; - $this->content = null; + $this->result = null; $this->originUrl = $originUrl; $this->fileUrl = $fileUrl; $this->fileName = $fileName; @@ -112,14 +116,18 @@ class RemoteFilesystem $result = @copy($fileUrl, $fileName, $ctx); } else { $result = @file_get_contents($fileUrl, false, $ctx); - $this->content = $result; + } + + // avoid overriding if content was loaded by a sub-call to get() + if (null === $this->result) { + $this->result = $result; } if ($this->progress) { $this->io->overwrite(" Downloading", false); } - if (false === $result) { + if (false === $this->result) { throw new \RuntimeException("The '$fileUrl' file could not be downloaded"); } } @@ -166,7 +174,7 @@ class RemoteFilesystem $password = $this->io->askAndHideAnswer(' Password: '); $this->io->setAuthorization($this->originUrl, $username, $password); - $this->content = $this->get($this->originUrl, $this->fileUrl, $this->fileName, $this->progress, false); + $this->get($this->originUrl, $this->fileUrl, $this->fileName, $this->progress, false); } break;