From: Alexander Ebert Date: Mon, 22 Jul 2013 20:03:09 +0000 (+0200) Subject: Reverted usage of pack() X-Git-Tag: 2.0.0_Beta_5~19 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=10174daa951922a026b53277296461ab8ea32ea5;p=GitHub%2FWoltLab%2FWCF.git Reverted usage of pack() The PHP documentation lies, 'a' and 'Z' do NOT behave the same for pack() (but they do for unpack()). --- diff --git a/wcfsetup/install/files/lib/system/io/TarWriter.class.php b/wcfsetup/install/files/lib/system/io/TarWriter.class.php index 783d90c448..5638432420 100644 --- a/wcfsetup/install/files/lib/system/io/TarWriter.class.php +++ b/wcfsetup/install/files/lib/system/io/TarWriter.class.php @@ -43,14 +43,7 @@ class TarWriter extends Tar { * Writes the last 0 filled block for end of archive. */ protected function writeFooter() { - if (version_compare(PHP_VERSION, '5.5.0-dev', '>=')) { - $format = 'Z512'; - } - else { - $format = 'a512'; - } - - $this->file->write(pack($format, '')); + $this->file->write(pack('a512', '')); } /** @@ -77,16 +70,9 @@ class TarWriter extends Tar { return false; } - if (version_compare(PHP_VERSION, '5.5.0-dev', '>=')) { - $format = 'Z512'; - } - else { - $format = 'a512'; - } - $i = 0; while (($buffer = substr($string, (($i++) * 512), 512)) != '') { - $this->file->write(pack($format, $buffer)); + $this->file->write(pack('a512', $buffer)); } return true; @@ -170,15 +156,8 @@ class TarWriter extends Tar { } // write file content - if (version_compare(PHP_VERSION, '5.5.0-dev', '>=')) { - $format = 'Z512'; - } - else { - $format = 'a512'; - } - while (($buffer = $file->read(512)) != '') { - $this->file->write(pack($format, $buffer)); + $this->file->write(pack('a512', $buffer)); } // close file @@ -249,23 +228,8 @@ class TarWriter extends Tar { $permissions = sprintf("%6s ", decOct($permissions)); $mtime = sprintf("%11s", decOct($mtime)); - if (version_compare(PHP_VERSION, '5.5.0-dev', '>=')) { - $format = 'Z100Z8Z8Z8Z12A12'; - } - else { - $format = 'a100a8a8a8a12A12'; - } - - $binaryDataFirst = pack($format, $filename, $permissions, $uid, $gid, $size, $mtime); - - if (version_compare(PHP_VERSION, '5.5.0-dev', '>=')) { - $format = 'Z1Z100Z6Z2Z32Z32Z8Z8Z155Z12'; - } - else { - $format = 'a1a100a6a2a32a32a8a8a155a12'; - } - - $binaryDataLast = pack($format, $typeFlag, '', '', '', '', '', '', '', '', ''); + $binaryDataFirst = pack('a100a8a8a8a12A12', $filename, $permissions, $uid, $gid, $size, $mtime); + $binaryDataLast = pack('a1a100a6a2a32a32a8a8a155a12', $typeFlag, '', '', '', '', '', '', '', '', ''); // calculate the checksum $checksum = 0; @@ -279,15 +243,8 @@ class TarWriter extends Tar { $checksum += ord(substr($binaryDataLast, $j, 1)); } - if (version_compare(PHP_VERSION, '5.5.0-dev', '>=')) { - $format = 'Z8'; - } - else { - $format = 'a8'; - } - $this->file->write($binaryDataFirst, 148); - $this->file->write(pack($format, sprintf("%6s ", decOct($checksum))), 8); // write the checksum + $this->file->write(pack('a8', sprintf("%6s ", decOct($checksum))), 8); // write the checksum $this->file->write($binaryDataLast, 356); return true; @@ -303,23 +260,8 @@ class TarWriter extends Tar { $size = sprintf("%11s ", decOct(strlen($filename))); $typeFlag = 'L'; - if (version_compare(PHP_VERSION, '5.5.0-dev', '>=')) { - $format = 'Z100Z8Z8Z8Z12A12'; - } - else { - $format = 'a100a8a8a8a12A12'; - } - - $binaryDataFirst = pack($format, '././@LongLink', 0, 0, 0, $size, 0); - - if (version_compare(PHP_VERSION, '5.5.0-dev', '>=')) { - $format = 'Z1Z100Z6Z2Z32Z32Z8Z8Z155Z12'; - } - else { - $format = 'a1a100a6a2a32a32a8a8a155a12'; - } - - $binaryDataLast = pack($format, $typeFlag, '', '', '', '', '', '', '', '', ''); + $binaryDataFirst = pack('a100a8a8a8a12A12', '././@LongLink', 0, 0, 0, $size, 0); + $binaryDataLast = pack('a1a100a6a2a32a32a8a8a155a12', $typeFlag, '', '', '', '', '', '', '', '', ''); // calculate the checksum $checksum = 0; @@ -334,27 +276,12 @@ class TarWriter extends Tar { } $this->file->write($binaryDataFirst, 148); - - if (version_compare(PHP_VERSION, '5.5.0-dev', '>=')) { - $format = 'Z8'; - } - else { - $format = 'a8'; - } - - $this->file->write(pack($format, sprintf("%6s ", decOct($checksum))), 8); // write the checksum + $this->file->write(pack('a8', sprintf("%6s ", decOct($checksum))), 8); // write the checksum $this->file->write($binaryDataLast, 356); - if (version_compare(PHP_VERSION, '5.5.0-dev', '>=')) { - $format = 'Z512'; - } - else { - $format = 'a512'; - } - $i = 0; while (($buffer = substr($filename, (($i++) * 512), 512)) != '') { - $this->file->write(pack($format, $buffer)); + $this->file->write(pack('a512', $buffer)); } return true;