diff options
Diffstat (limited to 'vendor/splitbrain/php-archive/src')
8 files changed, 114 insertions, 34 deletions
diff --git a/vendor/splitbrain/php-archive/src/Archive.php b/vendor/splitbrain/php-archive/src/Archive.php index d672cc6ec..45c87fda6 100644 --- a/vendor/splitbrain/php-archive/src/Archive.php +++ b/vendor/splitbrain/php-archive/src/Archive.php @@ -10,12 +10,15 @@ abstract class Archive const COMPRESS_GZIP = 1; const COMPRESS_BZIP = 2; + /** @var callable */ + protected $callback; + /** * Set the compression level and type * * @param int $level Compression level (0 to 9) * @param int $type Type of compression to use (use COMPRESS_* constants) - * @return mixed + * @throws ArchiveIllegalCompressionException */ abstract public function setCompression($level = 9, $type = Archive::COMPRESS_AUTO); @@ -117,16 +120,16 @@ abstract class Archive */ abstract public function save($file); -} - -class ArchiveIOException extends \Exception -{ -} - -class ArchiveIllegalCompressionException extends \Exception -{ -} - -class ArchiveCorruptedException extends \Exception -{ + /** + * Set a callback function to be called whenever a file is added or extracted. + * + * The callback is called with a FileInfo object as parameter. You can use this to show progress + * info during an operation. + * + * @param callable $callback + */ + public function setCallback($callback) + { + $this->callback = $callback; + } } diff --git a/vendor/splitbrain/php-archive/src/ArchiveCorruptedException.php b/vendor/splitbrain/php-archive/src/ArchiveCorruptedException.php new file mode 100644 index 000000000..a87cff4ff --- /dev/null +++ b/vendor/splitbrain/php-archive/src/ArchiveCorruptedException.php @@ -0,0 +1,10 @@ +<?php + +namespace splitbrain\PHPArchive; + +/** + * The archive is unreadable + */ +class ArchiveCorruptedException extends \Exception +{ +}
\ No newline at end of file diff --git a/vendor/splitbrain/php-archive/src/ArchiveIOException.php b/vendor/splitbrain/php-archive/src/ArchiveIOException.php new file mode 100644 index 000000000..6128caf2f --- /dev/null +++ b/vendor/splitbrain/php-archive/src/ArchiveIOException.php @@ -0,0 +1,10 @@ +<?php + +namespace splitbrain\PHPArchive; + +/** + * Read/Write Errors + */ +class ArchiveIOException extends \Exception +{ +}
\ No newline at end of file diff --git a/vendor/splitbrain/php-archive/src/ArchiveIllegalCompressionException.php b/vendor/splitbrain/php-archive/src/ArchiveIllegalCompressionException.php new file mode 100644 index 000000000..40a680f37 --- /dev/null +++ b/vendor/splitbrain/php-archive/src/ArchiveIllegalCompressionException.php @@ -0,0 +1,10 @@ +<?php + +namespace splitbrain\PHPArchive; + +/** + * Bad or unsupported compression settings requested + */ +class ArchiveIllegalCompressionException extends \Exception +{ +}
\ No newline at end of file diff --git a/vendor/splitbrain/php-archive/src/FileInfo.php b/vendor/splitbrain/php-archive/src/FileInfo.php index 99f60c0fe..11fca7e4f 100644 --- a/vendor/splitbrain/php-archive/src/FileInfo.php +++ b/vendor/splitbrain/php-archive/src/FileInfo.php @@ -288,7 +288,6 @@ class FileInfo * the prefix will be stripped. It is recommended to give prefixes with a trailing slash. * * @param int|string $strip - * @return FileInfo */ public function strip($strip) { @@ -339,6 +338,3 @@ class FileInfo } } -class FileInfoException extends \Exception -{ -}
\ No newline at end of file diff --git a/vendor/splitbrain/php-archive/src/FileInfoException.php b/vendor/splitbrain/php-archive/src/FileInfoException.php new file mode 100644 index 000000000..9c6acaac2 --- /dev/null +++ b/vendor/splitbrain/php-archive/src/FileInfoException.php @@ -0,0 +1,10 @@ +<?php + +namespace splitbrain\PHPArchive; + +/** + * File meta data problems + */ +class FileInfoException extends \Exception +{ +}
\ No newline at end of file diff --git a/vendor/splitbrain/php-archive/src/Tar.php b/vendor/splitbrain/php-archive/src/Tar.php index 5f01f39bd..9550b6c91 100644 --- a/vendor/splitbrain/php-archive/src/Tar.php +++ b/vendor/splitbrain/php-archive/src/Tar.php @@ -28,12 +28,15 @@ class Tar extends Archive * Sets the compression to use * * @param int $level Compression level (0 to 9) - * @param int $type Type of compression to use (use COMPRESS_* constants) - * @return mixed + * @param int $type Type of compression to use (use COMPRESS_* constants) + * @throws ArchiveIllegalCompressionException */ public function setCompression($level = 9, $type = Archive::COMPRESS_AUTO) { $this->compressioncheck($type); + if ($level < -1 || $level > 9) { + throw new ArchiveIllegalCompressionException('Compression level should be between -1 and 9'); + } $this->comptype = $type; $this->complevel = $level; if($level == 0) $this->comptype = Archive::COMPRESS_NONE; @@ -45,6 +48,7 @@ class Tar extends Archive * * @param string $file * @throws ArchiveIOException + * @throws ArchiveIllegalCompressionException */ public function open($file) { @@ -79,6 +83,7 @@ class Tar extends Archive * Reopen the file with open() again if you want to do additional operations * * @throws ArchiveIOException + * @throws ArchiveCorruptedException * @returns FileInfo[] */ public function contents() @@ -120,11 +125,12 @@ class Tar extends Archive * The archive is closed afer reading the contents, because rewinding is not possible in bzip2 streams. * Reopen the file with open() again if you want to do additional operations * - * @param string $outdir the target directory for extracting - * @param int|string $strip either the number of path components or a fixed prefix to strip - * @param string $exclude a regular expression of files to exclude - * @param string $include a regular expression of files to include + * @param string $outdir the target directory for extracting + * @param int|string $strip either the number of path components or a fixed prefix to strip + * @param string $exclude a regular expression of files to exclude + * @param string $include a regular expression of files to include * @throws ArchiveIOException + * @throws ArchiveCorruptedException * @return FileInfo[] */ public function extract($outdir, $strip = '', $exclude = '', $include = '') @@ -178,12 +184,15 @@ class Tar extends Archive } fclose($fp); - touch($output, $fileinfo->getMtime()); - chmod($output, $fileinfo->getMode()); + @touch($output, $fileinfo->getMtime()); + @chmod($output, $fileinfo->getMode()); } else { $this->skipbytes(ceil($header['size'] / 512) * 512); // the size is usually 0 for directories } + if(is_callable($this->callback)) { + call_user_func($this->callback, $fileinfo); + } $extracted[] = $fileinfo; } @@ -198,6 +207,7 @@ class Tar extends Archive * * @param string $file * @throws ArchiveIOException + * @throws ArchiveIllegalCompressionException */ public function create($file = '') { @@ -234,6 +244,7 @@ class Tar extends Archive * @param string|FileInfo $fileinfo either the name to us in archive (string) or a FileInfo oject with all meta data, empty to take from original * @throws ArchiveCorruptedException when the file changes while reading it, the archive will be corrupt and should be deleted * @throws ArchiveIOException there was trouble reading the given file, it was not added + * @throws FileInfoException trouble reading file info, it was not added */ public function addFile($file, $fileinfo = '') { @@ -273,6 +284,10 @@ class Tar extends Archive $this->close(); throw new ArchiveCorruptedException("The size of $file changed while reading, archive corrupted. read $read expected ".$fileinfo->getSize()); } + + if(is_callable($this->callback)) { + call_user_func($this->callback, $fileinfo); + } } /** @@ -299,6 +314,10 @@ class Tar extends Archive for ($s = 0; $s < $len; $s += 512) { $this->writebytes(pack("a512", substr($data, $s, 512))); } + + if (is_callable($this->callback)) { + call_user_func($this->callback, $fileinfo); + } } /** @@ -311,6 +330,7 @@ class Tar extends Archive * consists of two 512 blocks of zero bytes" * * @link http://www.gnu.org/software/tar/manual/html_chapter/tar_8.html#SEC134 + * @throws ArchiveIOException */ public function close() { @@ -346,6 +366,7 @@ class Tar extends Archive * Returns the created in-memory archive data * * This implicitly calls close() on the Archive + * @throws ArchiveIOException */ public function getArchive() { @@ -372,6 +393,7 @@ class Tar extends Archive * * @param string $file * @throws ArchiveIOException + * @throws ArchiveIllegalCompressionException */ public function save($file) { @@ -451,9 +473,10 @@ class Tar extends Archive } /** - * Write the given file metat data as header + * Write the given file meta data as header * * @param FileInfo $fileinfo + * @throws ArchiveIOException */ protected function writeFileHeader(FileInfo $fileinfo) { @@ -472,12 +495,13 @@ class Tar extends Archive * Write a file header to the stream * * @param string $name - * @param int $uid - * @param int $gid - * @param int $perm - * @param int $size - * @param int $mtime + * @param int $uid + * @param int $gid + * @param int $perm + * @param int $size + * @param int $mtime * @param string $typeflag Set to '5' for directories + * @throws ArchiveIOException */ protected function writeRawFileHeader($name, $uid, $gid, $perm, $size, $mtime, $typeflag = '') { @@ -664,4 +688,5 @@ class Tar extends Archive return Archive::COMPRESS_NONE; } + } diff --git a/vendor/splitbrain/php-archive/src/Zip.php b/vendor/splitbrain/php-archive/src/Zip.php index e84516b63..3dade8063 100644 --- a/vendor/splitbrain/php-archive/src/Zip.php +++ b/vendor/splitbrain/php-archive/src/Zip.php @@ -34,10 +34,13 @@ class Zip extends Archive * * @param int $level Compression level (0 to 9) * @param int $type Type of compression to use ignored for ZIP - * @return mixed + * @throws ArchiveIllegalCompressionException */ public function setCompression($level = 9, $type = Archive::COMPRESS_AUTO) { + if ($level < -1 || $level > 9) { + throw new ArchiveIllegalCompressionException('Compression level should be between -1 and 9'); + } $this->complevel = $level; } @@ -152,6 +155,9 @@ class Zip extends Archive // nothing more to do for directories if ($fileinfo->getIsdir()) { + if(is_callable($this->callback)) { + call_user_func($this->callback, $fileinfo); + } continue; } @@ -226,8 +232,11 @@ class Zip extends Archive unlink($extractto); // remove temporary gz file } - touch($output, $fileinfo->getMtime()); + @touch($output, $fileinfo->getMtime()); //FIXME what about permissions? + if(is_callable($this->callback)) { + call_user_func($this->callback, $fileinfo); + } } $this->close(); @@ -271,9 +280,10 @@ class Zip extends Archive /** * Add a file to the current archive using an existing file in the filesystem * - * @param string $file path to the original file + * @param string $file path to the original file * @param string|FileInfo $fileinfo either the name to use in archive (string) or a FileInfo oject with all meta data, empty to take from original * @throws ArchiveIOException + * @throws FileInfoException */ public function addFile($file, $fileinfo = '') { @@ -350,6 +360,10 @@ class Zip extends Archive $name, (bool) $this->complevel ); + + if(is_callable($this->callback)) { + call_user_func($this->callback, $fileinfo); + } } /** @@ -357,6 +371,7 @@ class Zip extends Archive * * After a call to this function no more data can be added to the archive, for * read access no reading is allowed anymore + * @throws ArchiveIOException */ public function close() { @@ -400,6 +415,7 @@ class Zip extends Archive * Returns the created in-memory archive data * * This implicitly calls close() on the Archive + * @throws ArchiveIOException */ public function getArchive() { |