summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--web/lib/Archive/Tar.php59
1 files changed, 41 insertions, 18 deletions
diff --git a/web/lib/Archive/Tar.php b/web/lib/Archive/Tar.php
index 33c7d395..9249a068 100644
--- a/web/lib/Archive/Tar.php
+++ b/web/lib/Archive/Tar.php
@@ -35,7 +35,7 @@
* @author Vincent Blavet <vincent@phpconcept.net>
* @copyright 1997-2010 The Authors
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Tar.php 324840 2012-04-05 08:44:41Z mrook $
+ * @version CVS: $Id$
* @link http://pear.php.net/package/Archive_Tar
*/
@@ -50,7 +50,7 @@ define('ARCHIVE_TAR_END_BLOCK', pack("a512", ''));
* @package Archive_Tar
* @author Vincent Blavet <vincent@phpconcept.net>
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
-* @version $Revision: 324840 $
+* @version $Revision$
*/
class Archive_Tar extends PEAR
{
@@ -407,11 +407,13 @@ class Archive_Tar extends PEAR
* with the string.
* @param string $p_string The content of the file added in
* the archive.
+ * @param int $p_datetime A custom date/time (unix timestamp)
+ * for the file (optional).
*
* @return true on success, false on error.
* @access public
*/
- function addString($p_filename, $p_string)
+ function addString($p_filename, $p_string, $p_datetime = false)
{
$v_result = true;
@@ -426,7 +428,7 @@ class Archive_Tar extends PEAR
return false;
// Need to check the get back to the temporary file ? ....
- $v_result = $this->_addString($p_filename, $p_string);
+ $v_result = $this->_addString($p_filename, $p_string, $p_datetime);
$this->_writeFooter();
@@ -680,9 +682,11 @@ class Archive_Tar extends PEAR
$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 +731,17 @@ class Archive_Tar extends PEAR
// ----- 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 +763,11 @@ class Archive_Tar extends PEAR
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 \''
@@ -1044,7 +1052,7 @@ class Archive_Tar extends PEAR
// }}}
// {{{ _addString()
- function _addString($p_filename, $p_string)
+ function _addString($p_filename, $p_string, $p_datetime = false)
{
if (!$this->_file) {
$this->_error('Invalid file descriptor');
@@ -1058,9 +1066,14 @@ class Archive_Tar extends PEAR
// ----- Calculate the stored filename
$p_filename = $this->_translateWinPath($p_filename, false);;
+
+ // ----- If datetime is not specified, set current time
+ if ($p_datetime === false) {
+ $p_datetime = time();
+ }
if (!$this->_writeHeaderBlock($p_filename, strlen($p_string),
- time(), 384, "", 0, 0))
+ $p_datetime, 384, "", 0, 0))
return false;
$i=0;
@@ -1343,11 +1356,17 @@ class Archive_Tar extends PEAR
for ($i=156; $i<512; $i++)
$v_checksum+=ord(substr($v_binary_data,$i,1));
- $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" .
- "a8checksum/a1typeflag/a100link/a6magic/a2version/" .
- "a32uname/a32gname/a8devmajor/a8devminor/a131prefix",
- $v_binary_data);
-
+ if (version_compare(PHP_VERSION,"5.5.0-dev")<0) {
+ $fmt = "a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" .
+ "a8checksum/a1typeflag/a100link/a6magic/a2version/" .
+ "a32uname/a32gname/a8devmajor/a8devminor/a131prefix";
+ } else {
+ $fmt = "Z100filename/Z8mode/Z8uid/Z8gid/Z12size/Z12mtime/" .
+ "Z8checksum/Z1typeflag/Z100link/Z6magic/Z2version/" .
+ "Z32uname/Z32gname/Z8devmajor/Z8devminor/Z131prefix";
+ }
+ $v_data = unpack($fmt, $v_binary_data);
+
if (strlen($v_data["prefix"]) > 0) {
$v_data["filename"] = "$v_data[prefix]/$v_data[filename]";
}
@@ -1593,10 +1612,14 @@ class Archive_Tar extends PEAR
if (($v_extract_file) && (!$v_listing))
{
if (($p_remove_path != '')
- && (substr($v_header['filename'], 0, $p_remove_path_size)
- == $p_remove_path))
+ && (substr($v_header['filename'].'/', 0, $p_remove_path_size)
+ == $p_remove_path)) {
$v_header['filename'] = substr($v_header['filename'],
$p_remove_path_size);
+ if( $v_header['filename'] == '' ){
+ continue;
+ }
+ }
if (($p_path != './') && ($p_path != '/')) {
while (substr($p_path, -1) == '/')
$p_path = substr($p_path, 0, strlen($p_path)-1);