cvs: pear /Archive_Tar Tar.php
| From: | Vincent Blavet | Date: | Thu, 24 Jan 2002 08:07:55 +0000 |
| Subject: | cvs: pear /Archive_Tar Tar.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-2071@lists.php.net to get a copy of this message | ||
vblavet Thu Jan 24 03:07:55 2002 EDT
Modified files:
/pear/Archive_Tar Tar.php
Log:
* Adding support of extraction of remote archive http://www/archive.tgz
* Correct bug while using Windows root path c:\xxx\yyy in extract fct
Index: pear/Archive_Tar/Tar.php
diff -u pear/Archive_Tar/Tar.php:1.14 pear/Archive_Tar/Tar.php:1.15
--- pear/Archive_Tar/Tar.php:1.14 Thu Jan 10 16:09:53 2002
+++ pear/Archive_Tar/Tar.php Thu Jan 24 03:07:54 2002
@@ -16,7 +16,7 @@
// | Authors: Vincent Blavet <vincent@blavet.net> |
// +----------------------------------------------------------------------+
//
-// $Id: Tar.php,v 1.14 2002/01/10 21:09:53 vblavet Exp $
+// $Id: Tar.php,v 1.15 2002/01/24 08:07:54 vblavet Exp $
require_once 'PEAR.php';
@@ -24,7 +24,7 @@
* Creates a (compressed) Tar archive
*
* @author Vincent Blavet <vincent@blavet.net>
-* @version $Revision: 1.14 $
+* @version $Revision: 1.15 $
* @package Archive
*/
class Archive_Tar extends PEAR
@@ -44,6 +44,11 @@
*/
var $_file=0;
+ /**
+ * @var string Local Tar name of a remote Tar (http:// or ftp://)
+ */
+ var $_temp_tarname='';
+
// {{{ constructor
/**
* Archive_Tar Class constructor. This flavour of the constructor only
@@ -81,6 +86,9 @@
function _Archive_Tar()
{
$this->_close();
+ // ----- Look for a local copy to delete
+ if ($this->_temp_tarname != '')
+ @unlink($this->_temp_tarname);
$this->_PEAR();
}
// }}}
@@ -394,13 +402,41 @@
// {{{ _openRead()
function _openRead()
{
+ if (strtolower(substr($this->_tarname, 0, 7)) == 'http://') {
+
+ // ----- Look if a local copy need to be done
+ if ($this->_temp_tarname == '') {
+ $this->_temp_tarname = uniqid('tar').'.tmp';
+ if (!$v_file_from = @fopen($this->_tarname, 'rb')) {
+ $this->_error('Unable to open in read mode
\''.$this->_tarname.'\'');
+ $this->_temp_tarname = '';
+ return false;
+ }
+ if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) {
+ $this->_error('Unable to open in write mode
\''.$this->_temp_tarname.'\'');
+ $this->_temp_tarname = '';
+ return false;
+ }
+ while ($v_data = @fread($v_file_from, 1024))
+ @fwrite($v_file_to, $v_data);
+ @fclose($v_file_from);
+ @fclose($v_file_to);
+ }
+
+ // ----- File to open if the local copy
+ $v_filename = $this->_temp_tarname;
+
+ } else
+ // ----- File to open if the normal Tar file
+ $v_filename = $this->_tarname;
+
if ($this->_compress)
- $this->_file = @gzopen($this->_tarname, "rb");
+ $this->_file = @gzopen($v_filename, "rb");
else
- $this->_file = @fopen($this->_tarname, "rb");
+ $this->_file = @fopen($v_filename, "rb");
if ($this->_file == 0) {
- $this->_error('Unable to open in read mode
\''.$this->_tarname.'\'');
+ $this->_error('Unable to open in read mode
\''.$v_filename.'\'');
return false;
}
@@ -437,6 +473,13 @@
$this->_file = 0;
}
+ // ----- Look if a local copy need to be erase
+ // Note that it might be interesting to keep the url for a time : ToDo
+ if ($this->_temp_tarname != '') {
+ @unlink($this->_temp_tarname);
+ $this->_temp_tarname = '';
+ }
+
return true;
}
// }}}
@@ -444,8 +487,18 @@
// {{{ _cleanFile()
function _cleanFile()
{
- _close();
- @unlink($this->tarname);
+ $this->_close();
+
+ // ----- Look for a local copy
+ if ($this->_temp_tarname != '') {
+ // ----- Remove the local copy but not the remote tarname
+ @unlink($this->_temp_tarname);
+ $this->_temp_tarname = '';
+ } else {
+ // ----- Remove the local tarname file
+ @unlink($this->_tarname);
+ }
+ $this->_tarname = '';
return true;
}
@@ -743,7 +796,12 @@
$v_extract_all = true;
$v_listing = false;
- if ($p_path == '' || (substr($p_path, 0, 1) != '/' &&
substr($p_path, 0, 3) != "../" && substr($p_path, 1, 3) != ":\\")) {
+ // ----- Look for removing the WINDOW '\'
+ if (OS_WINDOWS && strpos($p_path, '\\')) {
+ str_replace('\\', '/', $p_path);
+ }
+
+ if ($p_path == '' || (substr($p_path, 0, 1) != '/' &&
substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) {
$p_path = "./".$p_path;
}