Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Request #17491 - add option to preserve permissions

git-svn-id: https://svn.php.net/repository/pear/packages/Archive_Tar/trunk@313104 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit be72492bb424d544baa952251e56a1dfeda18db4 1 parent 03b1c3c
Michiel Rook mrook authored
Showing with 27 additions and 20 deletions.
  1. +27 −20 Archive/Tar.php
47 Archive/Tar.php
View
@@ -239,9 +239,9 @@ function add($p_filelist)
// }}}
// {{{ extract()
- function extract($p_path='')
+ function extract($p_path='', $p_preserve=false)
{
- return $this->extractModify($p_path, '');
+ return $this->extractModify($p_path, '', $p_preserve);
}
// }}}
@@ -461,24 +461,25 @@ function addString($p_filename, $p_string)
* is returned. However the result can be a partial extraction that may
* need to be manually cleaned.
*
- * @param string $p_path The path of the directory where the
- * files/dir need to by extracted.
- * @param string $p_remove_path Part of the memorized path that can be
- * removed if present at the beginning of
- * the file/dir path.
+ * @param string $p_path The path of the directory where the
+ * files/dir need to by extracted.
+ * @param string $p_remove_path Part of the memorized path that can be
+ * removed if present at the beginning of
+ * the file/dir path.
+ * @param boolean $p_preserve Preserve user/group ownership of files
*
* @return boolean true on success, false on error.
* @access public
* @see extractList()
*/
- function extractModify($p_path, $p_remove_path)
+ function extractModify($p_path, $p_remove_path, $p_preserve=false)
{
$v_result = true;
$v_list_detail = array();
if ($v_result = $this->_openRead()) {
$v_result = $this->_extractList($p_path, $v_list_detail,
- "complete", 0, $p_remove_path);
+ "complete", 0, $p_remove_path, $p_preserve);
$this->_close();
}
@@ -517,20 +518,21 @@ function extractInString($p_filename)
* If indicated the $p_remove_path can be used in the same way as it is
* used in extractModify() method.
*
- * @param array $p_filelist An array of filenames and directory names,
- * or a single string with names separated
- * by a single blank space.
- * @param string $p_path The path of the directory where the
- * files/dir need to by extracted.
- * @param string $p_remove_path Part of the memorized path that can be
- * removed if present at the beginning of
- * the file/dir path.
+ * @param array $p_filelist An array of filenames and directory names,
+ * or a single string with names separated
+ * by a single blank space.
+ * @param string $p_path The path of the directory where the
+ * files/dir need to by extracted.
+ * @param string $p_remove_path Part of the memorized path that can be
+ * removed if present at the beginning of
+ * the file/dir path.
+ * @param boolean $p_preserve Preserve user/group ownership of files
*
* @return true on success, false on error.
* @access public
* @see extractModify()
*/
- function extractList($p_filelist, $p_path='', $p_remove_path='')
+ function extractList($p_filelist, $p_path='', $p_remove_path='', $p_preserve=false)
{
$v_result = true;
$v_list_detail = array();
@@ -546,7 +548,7 @@ function extractList($p_filelist, $p_path='', $p_remove_path='')
if ($v_result = $this->_openRead()) {
$v_result = $this->_extractList($p_path, $v_list_detail, "partial",
- $v_list, $p_remove_path);
+ $v_list, $p_remove_path, $p_preserve);
$this->_close();
}
@@ -1500,7 +1502,7 @@ function _extractInString($p_filename)
// {{{ _extractList()
function _extractList($p_path, &$p_list_detail, $p_mode,
- $p_file_list, $p_remove_path)
+ $p_file_list, $p_remove_path, $p_preserve=false)
{
$v_result=true;
$v_nb = 0;
@@ -1667,6 +1669,11 @@ function _extractList($p_path, &$p_list_detail, $p_mode,
}
@fclose($v_dest_file);
+
+ if ($p_preserve) {
+ @chown($v_header['filename'], $v_header['uid']);
+ @chgrp($v_header['filename'], $v_header['gid']);
+ }
// ----- Change the file mode, mtime
@touch($v_header['filename'], $v_header['mtime']);
Please sign in to comment.
Something went wrong with that request. Please try again.