Skip to content
Browse files

More robust handling of missing/unknown compression types

  • Loading branch information...
1 parent 9ceffd9 commit dc70ad36c55c1fe391ff1e215b85c8d067dcbd8d @mrook mrook committed Jun 29, 2012
Showing with 11 additions and 5 deletions.
  1. +11 −5 Archive/Tar.php
View
16 Archive/Tar.php
@@ -680,9 +680,11 @@ function _openWrite()
$this->_file = @bzopen($this->_tarname, "w");
else if ($this->_compress_type == 'none')
$this->_file = @fopen($this->_tarname, "wb");
- else
+ else {
$this->_error('Unknown or missing compression type ('
.$this->_compress_type.')');
+ return false;
+ }
if ($this->_file == 0) {
$this->_error('Unable to open in write mode \''
@@ -727,15 +729,17 @@ function _openRead()
// ----- File to open if the normal Tar file
$v_filename = $this->_tarname;
- if ($this->_compress_type == 'gz')
+ if ($this->_compress_type == 'gz' && function_exists('gzopen'))
$this->_file = @gzopen($v_filename, "rb");
- else if ($this->_compress_type == 'bz2')
+ else if ($this->_compress_type == 'bz2' && function_exists('bzopen'))
$this->_file = @bzopen($v_filename, "r");
else if ($this->_compress_type == 'none')
$this->_file = @fopen($v_filename, "rb");
- else
+ else {
$this->_error('Unknown or missing compression type ('
.$this->_compress_type.')');
+ return false;
+ }
if ($this->_file == 0) {
$this->_error('Unable to open in read mode \''.$v_filename.'\'');
@@ -757,9 +761,11 @@ function _openReadWrite()
return false;
} else if ($this->_compress_type == 'none')
$this->_file = @fopen($this->_tarname, "r+b");
- else
+ else {
$this->_error('Unknown or missing compression type ('
.$this->_compress_type.')');
+ return false;
+ }
if ($this->_file == 0) {
$this->_error('Unable to open in read/write mode \''

0 comments on commit dc70ad3

Please sign in to comment.
Something went wrong with that request. Please try again.