PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » File Formats » Archive_Tar » Bug #4013

Ignoring files and directories on creating an archive.

Details

Request #4013Ignoring files and directories on creating an archive.
Submitted2005-03-31 08:13 UTC
Fromroth at egotec dot com
Assignedmrook
StatusClosed
PackageArchive_Tar
PHP Version5.0.3
OSLinux
Roadmaps1.3.6

Comments

[2005-03-31 08:13 UTC] roth at egotec dot com

Description:
------------
Version 1.3.1

I added the functionality to define a regular expression that describes files and directories that should be ignored when creating an archive with Archive_Tar. Full Downgrade compatibility.

Patch:
Index: Archive_Tar/Archive/Tar.php
===================================================================
--- Archive_Tar/Archive/Tar.php (revision 11325)
+++ Archive_Tar/Archive/Tar.php (working copy)
@@ -62,6 +62,11 @@
*/
var $_temp_tarname='';

+ /**
+ * @var string regular expression for ignoring files or directories
+ */
+ var $_ignore_regexp='';
+
// {{{ constructor
/**
* Archive_Tar Class constructor. This flavour of the constructor only
@@ -545,6 +550,36 @@
}
// }}}

+ // {{{ setIgnoreRegexp()
+ /**
+ * This method sets the regular expression for ignoring files and directories
+ * at import, for example:
+ * $arch->setIgnoreRegexp("#CVS|\.svn#");
+ * @param string $regexp regular expression defining which files or directories to ignore
+ * @access public
+ */
+ function setIgnoreRegexp($regexp)
+ {
+ $this->_ignore_regexp = $regexp;
+ }
+ // }}}
+
+ // {{{ setIgnoreList()
+ /**
+ * This method sets the regular expression for ignoring all files and directories
+ * matching the filenames in the array list at import, for example:
+ * $arch->setIgnoreList(array('CVS', '.svn', 'bin/tool'));
+ * @param array $list a list of file or directory names to ignore
+ * @access public
+ */
+ function setIgnoreList($list)
+ {
+ $regexp = str_replace(array('#', '.', '^', '$'), array('\#', '\.', '\^', '\$'), $list);
+ $regexp = '#/'.join('$|/', $list).'#';
+ $this->setIgnoreRegexp($regexp);
+ }
+ // }}}
+
// {{{ _error()
function _error($p_message)
{
@@ -814,6 +849,12 @@
if ($v_filename == '')
continue;

+ // ----- ignore files and directories matching the ignore regular expression
+ if ($this->_ignore_regexp && preg_match($this->_ignore_regexp, '/'.$v_filename)) {
+ $this->_warning("File '$v_filename' ignored");
+ continue;
+ }
+
if (!file_exists($v_filename)) {
$this->_warning("File '$v_filename' does not exist");
continue;