cvs: php4 /pear/Archive Tar.php
| From: | Vincent Blavet | Date: | Thu, 09 May 2002 13:00:12 +0000 |
| Subject: | cvs: php4 /pear/Archive Tar.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-3727@lists.php.net to get a copy of this message | ||
vblavet Thu May 9 09:00:12 2002 EDT
Modified files:
/php4/pear/Archive Tar.php
Log:
* Better handling of Windows paths (\php\any_thing or c:\php\any_thing)
* Remember that inside the archive path are all the time in unix format /php/any_thing
* When necessary, '\' are replaced by '/' and 'c:' are removed
* Synchro with cvs:pear/Archive_Tar/Tar.php version 1.20
Index: php4/pear/Archive/Tar.php
diff -u php4/pear/Archive/Tar.php:1.7 php4/pear/Archive/Tar.php:1.8
--- php4/pear/Archive/Tar.php:1.7 Sat Apr 13 01:33:35 2002
+++ php4/pear/Archive/Tar.php Thu May 9 09:00:12 2002
@@ -16,7 +16,7 @@
// | Author: Vincent Blavet <vincent@blavet.net> |
// +----------------------------------------------------------------------+
//
-// $Id: Tar.php,v 1.7 2002/04/13 05:33:35 mfischer Exp $
+// $Id: Tar.php,v 1.8 2002/05/09 13:00:12 vblavet Exp $
require_once 'PEAR.php';
@@ -24,7 +24,7 @@
* Creates a (compressed) Tar archive
*
* @author Vincent Blavet <vincent@blavet.net>
-* @version $Revision: 1.7 $
+* @version $Revision: 1.8 $
* @package Archive
*/
class Archive_Tar extends PEAR
@@ -540,6 +540,10 @@
$v_result=true;
$v_header = array();
+ // ----- Remove potential windows directory separator
+ $p_add_dir = $this->_translateWinPath($p_add_dir);
+ $p_remove_dir = $this->_translateWinPath($p_remove_dir, false);
+
if (!$this->_file) {
$this->_error('Invalid file descriptor');
return false;
@@ -576,7 +580,7 @@
$p_hitem = readdir($p_hdir); // '..' directory
while ($p_hitem = readdir($p_hdir)) {
if ($v_filename != ".")
- $p_temp_list[0] = $v_filename.DIRECTORY_SEPARATOR.$p_hitem;
+ $p_temp_list[0] = $v_filename.'/'.$p_hitem;
else
$p_temp_list[0] = $p_hitem;
@@ -607,24 +611,28 @@
}
// ----- Calculate the stored filename
+ $p_filename = $this->_translateWinPath($p_filename, false);;
$v_stored_filename = $p_filename;
if (strcmp($p_filename, $p_remove_dir) == 0) {
return true;
}
if ($p_remove_dir != '') {
- if (substr($p_remove_dir, -1) != DIRECTORY_SEPARATOR)
- $p_remove_dir .= DIRECTORY_SEPARATOR;
+ if (substr($p_remove_dir, -1) != '/')
+ $p_remove_dir .= '/';
if (substr($p_filename, 0, strlen($p_remove_dir)) == $p_remove_dir)
$v_stored_filename = substr($p_filename, strlen($p_remove_dir));
}
+ $v_stored_filename = $this->_translateWinPath($v_stored_filename);
if ($p_add_dir != '') {
- if (substr($p_add_dir, -1) == DIRECTORY_SEPARATOR)
+ if (substr($p_add_dir, -1) == '/')
$v_stored_filename = $p_add_dir.$v_stored_filename;
else
- $v_stored_filename = $p_add_dir.DIRECTORY_SEPARATOR.$v_stored_filename;
+ $v_stored_filename = $p_add_dir.'/'.$v_stored_filename;
}
+ $v_stored_filename = $this->_pathReduction($v_stored_filename);
+
if (strlen($v_stored_filename) > 99) {
$this->_warning("Stored file name is too long (max. 99) :
'$v_stored_filename'");
fclose($v_file);
@@ -811,18 +819,15 @@
$v_extract_all = true;
$v_listing = false;
- // ----- Look for removing the WINDOW '\'
- if (OS_WINDOWS && strpos($p_path, '\\')) {
- str_replace('\\', DIRECTORY_SEPARATOR, $p_path);
- }
-
- if ($p_path == '' || (substr($p_path, 0, 1) != DIRECTORY_SEPARATOR &&
substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) {
+ $p_path = $this->_translateWinPath($p_path, false);
+ if ($p_path == '' || (substr($p_path, 0, 1) != '/' &&
substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) {
$p_path = "./".$p_path;
}
+ $p_remove_path = $this->_translateWinPath($p_remove_path);
// ----- Look for path to remove format (should end by /)
- if (($p_remove_path != '') && (substr($p_remove_path, -1) !=
DIRECTORY_SEPARATOR))
- $p_remove_path .= DIRECTORY_SEPARATOR;
+ if (($p_remove_path != '') && (substr($p_remove_path, -1) != '/'))
+ $p_remove_path .= '/';
$p_remove_path_size = strlen($p_remove_path);
switch ($p_mode) {
@@ -867,7 +872,7 @@
for ($i=0; $i<sizeof($p_file_list); $i++) {
// ----- Look if it is a directory
- if (substr($p_file_list[$i], -1) == DIRECTORY_SEPARATOR) {
+ if (substr($p_file_list[$i], -1) == '/') {
// ----- Look if the directory is in the filename path
if ((strlen($v_header['filename']) > strlen($p_file_list[$i])) &&
(substr($v_header['filename'], 0, strlen($p_file_list[$i])) == $p_file_list[$i])) {
$v_extract_file = TRUE;
@@ -891,14 +896,14 @@
if (($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 (($p_path != "./") && ($p_path != DIRECTORY_SEPARATOR)) {
- while (substr($p_path, -1) == DIRECTORY_SEPARATOR)
+ if (($p_path != './') && ($p_path != '/')) {
+ while (substr($p_path, -1) == '/')
$p_path = substr($p_path, 0, strlen($p_path)-1);
- if (substr($v_header['filename'], 0, 1) == DIRECTORY_SEPARATOR)
+ if (substr($v_header['filename'], 0, 1) == '/')
$v_header['filename'] = $p_path.$v_header['filename'];
else
- $v_header['filename'] =
$p_path.DIRECTORY_SEPARATOR.$v_header['filename'];
+ $v_header['filename'] =
$p_path.'/'.$v_header['filename'];
}
if (file_exists($v_header['filename'])) {
if ((@is_dir($v_header['filename'])) &&
($v_header['typeflag'] == '')) {
@@ -992,8 +997,8 @@
// ----- Log extracted files
if (($v_file_dir = dirname($v_header['filename'])) ==
$v_header['filename'])
$v_file_dir = '';
- if ((substr($v_header['filename'], 0, 1) == DIRECTORY_SEPARATOR) &&
($v_file_dir == ''))
- $v_file_dir = DIRECTORY_SEPARATOR;
+ if ((substr($v_header['filename'], 0, 1) == '/') &&
($v_file_dir == ''))
+ $v_file_dir = '/';
$p_list_detail[$v_nb++] = $v_header;
}
@@ -1097,7 +1102,7 @@
// ----- Look for not empty path
if ($p_dir != '') {
// ----- Explode path by directory names
- $v_list = explode(DIRECTORY_SEPARATOR, $p_dir);
+ $v_list = explode('/', $p_dir);
// ----- Study directories from last to first
for ($i=sizeof($v_list)-1; $i>=0; $i--) {
@@ -1112,16 +1117,33 @@
}
else if (($v_list[$i] == '') && ($i!=(sizeof($v_list)-1))
&& ($i!=0)) {
// ----- Ignore only the double '//' in path,
- // but not the first and last DIRECTORY_SEPARATOR
+ // but not the first and last /
} else {
- $v_result =
$v_list[$i].($i!=(sizeof($v_list)-1)?DIRECTORY_SEPARATOR.$v_result:'');
+ $v_result =
$v_list[$i].($i!=(sizeof($v_list)-1)?'/'.$v_result:'');
}
}
}
- $v_result = strtr($v_result, '\\', DIRECTORY_SEPARATOR);
+ $v_result = strtr($v_result, '\\', '/');
return $v_result;
}
// }}}
+ // {{{ _translateWinPath()
+ function _translateWinPath($p_path, $p_remove_disk_letter=true)
+ {
+ if (OS_WINDOWS) {
+ // ----- Look for potential disk letter
+ if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) !=
false)) {
+ $p_path = substr($p_path, $v_position+1);
+ }
+ // ----- Change potential windows directory separator
+ if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\'))
{
+ $p_path = strtr($p_path, '\\', '/');
+ }
+ }
+ return $p_path;
+ }
+ // }}}
+
}
-?>
+?>
\ No newline at end of file