HOR-3470-HQ

This commit is contained in:
hjonathan
2017-08-11 12:33:30 -04:00
parent 07f0a36aef
commit 9777285e72
9 changed files with 1006 additions and 1120 deletions

View File

@@ -12,18 +12,14 @@
* only if this copyright statement is not removed
*--------------------------------------------------*/
/**
*
* @package workflow.engine.classes
*/
/**
* This class is derived from the class archive, is imployed to use files .
* tar
*
* @package workflow.engine.classes
*
*/class tar_file extends archive
*/
class tar_file extends Archive
{
/**
@@ -31,9 +27,9 @@
*
* @param string $name
*/
public function tar_file ($name)
public function tar_file($name)
{
$this->archive( $name );
$this->archive($name);
$this->options['type'] = "tar";
}
@@ -43,50 +39,50 @@
*
* @return boolean
*/
public function create_tar ()
public function create_tar()
{
$pwd = getcwd();
chdir( $this->options['basedir'] );
chdir($this->options['basedir']);
foreach ($this->files as $current) {
if ($current['name'] == $this->options['name']) {
continue;
}
if (strlen( $current['name2'] ) > 99) {
$path = substr( $current['name2'], 0, strpos( $current['name2'], "/", strlen( $current['name2'] ) - 100 ) + 1 );
$current['name2'] = substr( $current['name2'], strlen( $path ) );
if (strlen( $path ) > 154 || strlen( $current['name2'] ) > 99) {
if (strlen($current['name2']) > 99) {
$path = substr($current['name2'], 0, strpos($current['name2'], "/", strlen($current['name2']) - 100) + 1);
$current['name2'] = substr($current['name2'], strlen($path));
if (strlen($path) > 154 || strlen($current['name2']) > 99) {
$this->error[] = "Could not add {$path}{$current['name2']} to archive because the filename is too long.";
continue;
}
}
$block = pack( "a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155a12", $current['name2'], sprintf( "%07o", $current['stat'][2] ), sprintf( "%07o", $current['stat'][4] ), sprintf( "%07o", $current['stat'][5] ), sprintf( "%011o", $current['type'] == 2 ? 0 : $current['stat'][7] ), sprintf( "%011o", $current['stat'][9] ), " ", $current['type'], $current['type'] == 2 ? @readlink( $current['name'] ) : "", "ustar ", " ", "Unknown", "Unknown", "", "", ! empty( $path ) ? $path : "", "" );
$block = pack("a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155a12", $current['name2'], sprintf("%07o", $current['stat'][2]), sprintf("%07o", $current['stat'][4]), sprintf("%07o", $current['stat'][5]), sprintf("%011o", $current['type'] == 2 ? 0 : $current['stat'][7]), sprintf("%011o", $current['stat'][9]), " ", $current['type'], $current['type'] == 2 ? @readlink($current['name']) : "", "ustar ", " ", "Unknown", "Unknown", "", "", !empty($path) ? $path : "", "");
$checksum = 0;
for ($i = 0; $i < 512; $i ++) {
$checksum += ord( substr( $block, $i, 1 ) );
for ($i = 0; $i < 512; $i++) {
$checksum += ord(substr($block, $i, 1));
}
$checksum = pack( "a8", sprintf( "%07o", $checksum ) );
$block = substr_replace( $block, $checksum, 148, 8 );
$checksum = pack("a8", sprintf("%07o", $checksum));
$block = substr_replace($block, $checksum, 148, 8);
if ($current['type'] == 2 || $current['stat'][7] == 0) {
$this->add_data( $block );
} elseif ($fp = @fopen( $current['name'], "rb" )) {
$this->add_data( $block );
while ($temp = fread( $fp, 1048576 )) {
$this->add_data( $temp );
$this->add_data($block);
} elseif ($fp = @fopen($current['name'], "rb")) {
$this->add_data($block);
while ($temp = fread($fp, 1048576)) {
$this->add_data($temp);
}
if ($current['stat'][7] % 512 > 0) {
$temp = "";
for ($i = 0; $i < 512 - $current['stat'][7] % 512; $i ++) {
for ($i = 0; $i < 512 - $current['stat'][7] % 512; $i++) {
$temp .= "\0";
}
$this->add_data( $temp );
$this->add_data($temp);
}
fclose( $fp );
fclose($fp);
} else {
$this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
}
}
$this->add_data( pack( "a1024", "" ) );
chdir( $pwd );
$this->add_data(pack("a1024", ""));
chdir($pwd);
return 1;
}
@@ -95,58 +91,58 @@
*
* @return void
*/
public function extract_files ()
public function extract_files()
{
$pwd = getcwd();
chdir( $this->options['basedir'] );
chdir($this->options['basedir']);
if ($fp = $this->open_archive()) {
if ($this->options['inmemory'] == 1) {
$this->files = array ();
$this->files = array();
}
while ($block = fread( $fp, 512 )) {
$temp = unpack( "a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp", $block );
$file = array ('name' => $this->options['basedir'] . '/' . $temp['prefix'] . $temp['name'],'stat' => array (2 => $temp['mode'],4 => octdec( $temp['uid'] ),5 => octdec( $temp['gid'] ),7 => octdec( $temp['size'] ),9 => octdec( $temp['mtime'] )
),'checksum' => octdec( $temp['checksum'] ),'type' => $temp['type'],'magic' => $temp['magic']
while ($block = fread($fp, 512)) {
$temp = unpack("a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp", $block);
$file = array('name' => $this->options['basedir'] . '/' . $temp['prefix'] . $temp['name'], 'stat' => array(2 => $temp['mode'], 4 => octdec($temp['uid']), 5 => octdec($temp['gid']), 7 => octdec($temp['size']), 9 => octdec($temp['mtime'])
), 'checksum' => octdec($temp['checksum']), 'type' => $temp['type'], 'magic' => $temp['magic']
);
if ($file['checksum'] == 0x00000000) {
break;
} elseif (substr( $file['magic'], 0, 5 ) != "ustar") {
} elseif (substr($file['magic'], 0, 5) != "ustar") {
$this->error[] = "This script does not support extracting this type of tar file.";
break;
}
$block = substr_replace( $block, " ", 148, 8 );
$block = substr_replace($block, " ", 148, 8);
$checksum = 0;
for ($i = 0; $i < 512; $i ++) {
$checksum += ord( substr( $block, $i, 1 ) );
for ($i = 0; $i < 512; $i++) {
$checksum += ord(substr($block, $i, 1));
}
if ($file['checksum'] != $checksum) {
$this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
}
if ($this->options['inmemory'] == 1) {
$file['data'] = fread( $fp, $file['stat'][7] );
fread( $fp, (512 - $file['stat'][7] % 512) == 512 ? 0 : (512 - $file['stat'][7] % 512) );
unset( $file['checksum'], $file['magic'] );
$file['data'] = fread($fp, $file['stat'][7]);
fread($fp, (512 - $file['stat'][7] % 512) == 512 ? 0 : (512 - $file['stat'][7] % 512));
unset($file['checksum'], $file['magic']);
$this->files[] = $file;
} elseif ($file['type'] == 5) {
if (! is_dir( $file['name'] )) {
if (!is_dir($file['name'])) {
//mkdir($file['name'], $file['stat'][2]);
mkdir( $file['name'], 0775 );
mkdir($file['name'], 0775);
}
} elseif ($this->options['overwrite'] == 0 && file_exists( $file['name'] )) {
} elseif ($this->options['overwrite'] == 0 && file_exists($file['name'])) {
$this->error[] = "{$file['name']} already exist.";
continue;
} elseif ($file['type'] == 2) {
symlink( $temp['symlink'], $file['name'] );
symlink($temp['symlink'], $file['name']);
//chmod($file['name'], $file['stat'][2]);
} elseif ($new = @fopen( $file['name'], "wb" )) {
fwrite( $new, fread( $fp, $file['stat'][7] ) );
} elseif ($new = @fopen($file['name'], "wb")) {
fwrite($new, fread($fp, $file['stat'][7]));
if ((512 - $file['stat'][7] % 512) != 512) {
fread( $fp, (512 - $file['stat'][7] % 512) );
fread($fp, (512 - $file['stat'][7] % 512));
}
//fread($fp, (512 - $file['stat'][7] % 512) == 512 ? 0 : (512 - $file['stat'][7] % 512));
fclose( $new );
fclose($new);
//chmod($file['name'], $file['stat'][2]);
chmod( $file['name'], 0777 );
chmod($file['name'], 0777);
$this->files[] = $file['name'];
} else {
$this->error[] = "Could not open {$file['name']} for writing.";
@@ -154,13 +150,13 @@
}
//chown($file['name'], $file['stat'][4]);
//chgrp($file['name'], $file['stat'][5]);
@touch( $file['name'], $file['stat'][9] );
unset( $file );
@touch($file['name'], $file['stat'][9]);
unset($file);
}
} else {
$this->error[] = "Could not open file {$this->options['name']}";
}
chdir( $pwd );
chdir($pwd);
}
/**
@@ -168,8 +164,8 @@
*
* @return void
*/
public function open_archive ()
public function open_archive()
{
return @fopen( $this->options['name'], "rb" );
return @fopen($this->options['name'], "rb");
}
}