diff options
author | Paul S. Owen <psotfx@users.sourceforge.net> | 2003-08-13 16:11:04 +0000 |
---|---|---|
committer | Paul S. Owen <psotfx@users.sourceforge.net> | 2003-08-13 16:11:04 +0000 |
commit | 321eb7eedc4d12ed11ad257aa21d04dae30f86b0 (patch) | |
tree | 8d2e274aa5cd1039d091cb98aa31648813e3702f /phpBB | |
parent | 808d0f1455041b8ce051e23992ca43354eea9475 (diff) | |
download | forums-321eb7eedc4d12ed11ad257aa21d04dae30f86b0.tar forums-321eb7eedc4d12ed11ad257aa21d04dae30f86b0.tar.gz forums-321eb7eedc4d12ed11ad257aa21d04dae30f86b0.tar.bz2 forums-321eb7eedc4d12ed11ad257aa21d04dae30f86b0.tar.xz forums-321eb7eedc4d12ed11ad257aa21d04dae30f86b0.zip |
Fix up issues with .tar, .tar.gz and .tar.bz2 archives and directory structure creation
git-svn-id: file:///svn/phpbb/trunk@4398 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/includes/functions_compress.php | 74 |
1 files changed, 58 insertions, 16 deletions
diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php index f06121c2cf..9a70bd9fc0 100644 --- a/phpBB/includes/functions_compress.php +++ b/phpBB/includes/functions_compress.php @@ -122,7 +122,7 @@ class compress_zip extends compress function compress_zip($mode, $file) { - return $this->fp = @fopen($phpbb_root_path . $file, $mode . 'b'); + return $this->fp = @fopen($file, $mode . 'b'); } function unix_to_dos_time($time) @@ -380,12 +380,10 @@ class compress_zip extends compress // Header/checksum creation derived from tarfile.pl, © Tom Horsley, 1994 class compress_tar extends compress { - var $fzopen = ''; - var $fzclose = ''; - var $fzread = ''; - var $fzwrite = ''; var $isgz = false; var $isbz = false; + var $filename = ''; + var $mode = ''; function compress_tar($mode, $file, $type = '') { @@ -393,16 +391,16 @@ class compress_tar extends compress $this->isgz = (strpos($type, '.tar.gz') !== false || strpos($type, '.tgz') !== false) ? true : false; $this->isbz = (strpos($type, '.tar.bz2') !== false) ? true : false; - $fzopen = ($this->isbz && function_exists('bzopen')) ? 'bzopen' : (($this->isgz && extension_loaded('zlib')) ? 'gzopen' : 'fopen'); - return $this->fp = @$fzopen($phpbb_root_path . $file, $mode . 'b'); + $this->mode = &$mode; + $this->file = &$file; + $this->open(); } function extract($dst) { $fzread = ($this->isbz && function_exists('bzread')) ? 'bzread' : (($this->isgz && extension_loaded('zlib')) ? 'gzread' : 'fread'); - $size = 0; - $header = $data = ''; + // Run through the file and grab directory entries while ($buffer = $fzread($this->fp, 512)) { $tmp = unpack("A6magic", substr($buffer, 257, 6)); @@ -417,14 +415,52 @@ class compress_tar extends compress if ($filetype == 5) { - if (!@mkdir("$dst$filename", 0777)) - { - trigger_error("Could not create directory $filename"); - } - @chmod("$dst$filename", 0777); - continue; + $mkdir_ary[] = "$dst$filename"; } - else + } + } + + // Create the directory structure + if (is_array($mkdir_ary)) + { + sort($mkdir_ary); + foreach ($mkdir_ary as $dir) + { + if (!@mkdir($dir, 0777)) + { + trigger_error("Could not create directory $dir"); + } + @chmod("$dir", 0777); + } + } + + // If this is a .bz2 we need to close and re-open the file in order + // to reset the file pointer since we cannot apparently rewind it + if ($this->isbz) + { + $this->close(); + $this->open(); + } + else + { + fseek($this->fp, 0); + } + + // Write out the files + $size = 0; + while ($buffer = $fzread($this->fp, 512)) + { + $tmp = unpack("A6magic", substr($buffer, 257, 6)); + + if (trim($tmp['magic']) == 'ustar') + { + $tmp = unpack("A100name", $buffer); + $filename = trim($tmp['name']); + + $tmp = unpack("Atype", substr($buffer, 156, 1)); + $filetype = (int) trim($tmp['type']); + + if ($filetype != 5) { $tmp = unpack("A12size", substr($buffer, 124, 12)); $filesize = octdec((int) trim($tmp['size'])); @@ -499,6 +535,12 @@ class compress_tar extends compress } unset($data); } + + function open($mode, $file) + { + $fzopen = ($this->isbz && function_exists('bzopen')) ? 'bzopen' : (($this->isgz && extension_loaded('zlib')) ? 'gzopen' : 'fopen'); + return $this->fp = @$fzopen($this->file, $this->mode . 'b'); + } } ?>
\ No newline at end of file |