From 6edf40ee96a754512bde275df7d684337efc0b0f Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Fri, 10 Jan 2014 17:48:38 +0000 Subject: [PATCH 1/2] When $TMPDIR is low on space PHP streams silently fail --- src/Composer/Util/RemoteFilesystem.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index d3ecec03d..9f0235b06 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -179,6 +179,10 @@ class RemoteFilesystem // work around issue with gzuncompress & co that do not work with all gzip checksums $result = file_get_contents('compress.zlib://data:application/octet-stream;base64,'.base64_encode($result)); } + + if (!$result) { + throw new TransportException('Failed to decode zlib stream'); + } } } From 439095e446ede68da8f4c6b8c225c5e188e0e252 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Fri, 10 Jan 2014 17:49:09 +0000 Subject: [PATCH 2/2] Handle incomplete file write to cache --- src/Composer/Cache.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Composer/Cache.php b/src/Composer/Cache.php index 6bdf43d5d..83f8f1763 100644 --- a/src/Composer/Cache.php +++ b/src/Composer/Cache.php @@ -83,7 +83,28 @@ class Cache $this->io->write('Writing '.$this->root . $file.' into cache'); } - return file_put_contents($this->root . $file, $contents); + try { + return file_put_contents($this->root . $file, $contents); + } catch(\ErrorException $e) { + if (preg_match('{^file_put_contents\(\): Only ([0-9]+) of ([0-9]+) bytes written}', $e->getMessage(), $m)) { + // Remove partial file. + unlink($this->root . $file); + + $message = sprintf( + 'Writing %1$s into cache failed after %2$u of %3$u bytes written, only %4$u bytes of free space available', + $this->root . $file, + $m[1], + $m[2], + @disk_free_space($this->root . dirname($file)) + ); + + $this->io->write($message); + + return false; + } + + throw $e; + } } return false;