$v_mtime; $p_header[typeflag] = $v_typeflag; $p_header[status] = "added"; // ----- Return TrFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : PclTarHandleFooter() // Description : // Parameters : // Return Values : // -------------------------------------------------------------------------------- function PclTarHandleFooter($p_tar, $p_mode) { TrFctStart(__FILE__, __LINE__, "PclTarHandleFooter", "tar='$p_tar', p_mode=$p_mode"); $v_result=1; // ----- Write the last 0 filled block for end of archive $v_binary_data = pack("a512", ""); if ($p_mode == "tar") fputs($p_tar, $v_binary_data); else gzputs($p_tar, $v_binary_data); // ----- Return TrFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : PclTarHandleExtract() // Description : // Parameters : // $p_tarname : Filename of the tar (or tgz) archive // $p_file_list : An array which contains the list of files to extract, this // array may be empty when $p_mode is 'complete' // $p_list_detail : An array where will be placed the properties of each extracted/listed file // $p_mode : 'complete' will extract all files from the archive, // 'partial' will look for files in $p_file_list // 'list' will only list the files from the archive without any extract // $p_path : Path to add while writing the extracted files // $p_tar_mode : 'tar' for GNU TAR archive, 'tgz' for compressed archive // $p_remove_path : Path to remove (from the file memorized path) while writing the // extracted files. If the path does not match the file path, // the file is extracted with its memorized path. // $p_remove_path does not apply to 'list' mode. // $p_path and $p_remove_path are commulative. // Return Values : // -------------------------------------------------------------------------------- function PclTarHandleExtract($p_tarname, $p_file_list, &$p_list_detail, $p_mode, $p_path, $p_tar_mode, $p_remove_path) { TrFctStart(__FILE__, __LINE__, "PclTarHandleExtract", "archive='$p_tarname', list, mode=$p_mode, path=$p_path, tar_mode=$p_tar_mode, remove_path='$p_remove_path'"); $v_result=1; $v_nb = 0; $v_extract_all = TRUE; $v_listing = FALSE; // ----- Check the path /* if (($p_path == "") || ((substr($p_path, 0, 1) != "/") && (substr($p_path, 0, 3) != "../"))) $p_path = "./".$p_path; */ $isWin = (substr(PHP_OS, 0, 3) == 'WIN'); if(!$isWin) { if (($p_path == "") || ((substr($p_path, 0, 1) != "/") && (substr($p_path, 0, 3) != "../"))) $p_path = "./".$p_path; } // ----- Look for path to remove format (should end by /) if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/')) { $p_remove_path .= '/'; } $p_remove_path_size = strlen($p_remove_path); // ----- Study the mode switch ($p_mode) { case "complete" : // ----- Flag extract of all files $v_extract_all = TRUE; $v_listing = FALSE; break; case "partial" : // ----- Flag extract of specific files $v_extract_all = FALSE; $v_listing = FALSE; break; case "list" : // ----- Flag list of all files $v_extract_all = FALSE; $v_listing = TRUE; break; default : // ----- Error log PclErrorLog(-3, "Invalid extract mode ($p_mode)"); // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return PclErrorCode(); } // ----- Open the tar file if ($p_tar_mode == "tar") { TrFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); $v_tar = fopen($p_tarname, "rb"); } else { TrFctMessage(__FILE__, __LINE__, 3, "Open file in gzip binary read mode"); $v_tar = @gzopen($p_tarname, "rb"); } // ----- Check that the archive is open if ($v_tar == 0) { // ----- Error log PclErrorLog(-2, "Unable to open archive '$p_tarname' in binary read mode"); // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return PclErrorCode(); } // ----- Read the blocks While (!($v_end_of_file = ($p_tar_mode == "tar"?feof($v_tar):gzeof($v_tar)))) { TrFctMessage(__FILE__, __LINE__, 3, "Looking for next header ..."); // ----- Clear cache of file infos clearstatcache(); // ----- Reset extract tag $v_extract_file = FALSE; $v_extraction_stopped = 0; // ----- Read the 512 bytes header if ($p_tar_mode == "tar") $v_binary_data = fread($v_tar, 512); else $v_binary_data = gzread($v_tar, 512); // ----- Read the header properties if (($v_result = PclTarHandleReadHeader($v_binary_data, $v_header)) != 1) { // ----- Close the archive file if ($p_tar_mode == "tar") fclose($v_tar); else gzclose($v_tar); // ----- Return TrFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Look for empty blocks to skip if ($v_header["filename"] == "") { TrFctMessage(__FILE__, __LINE__, 2, "Empty block found. End of archive ?"); continue; } TrFctMessage(__FILE__, __LINE__, 2, "Found file '" . $v_header["filename"] . "', size '$v_header[size]'"); // ----- Look for partial extract if ((!$v_extract_all) && (is_array($p_file_list))) { TrFctMessage(__FILE__, __LINE__, 2, "Look if the file '$v_header[filename]' need to be extracted"); // ----- By default no unzip if the file is not found $v_extract_file = FALSE; // ----- Look into the file list for ($i=0; $i strlen($p_file_list[$i])) && (substr($v_header["filename"], 0, strlen($p_file_list[$i])) == $p_file_list[$i])) { // ----- The file is in the directory, so extract it TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' is in directory '$p_file_list[$i]' : extract it"); $v_extract_file = TRUE; // ----- End of loop break; } } // ----- It is a file, so compare the file names else if ($p_file_list[$i] == $v_header["filename"]) { // ----- File found TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' should be extracted"); $v_extract_file = TRUE; // ----- End of loop break; } } // ----- Trace if (!$v_extract_file) { TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' should not be extracted"); } } else { // ----- All files need to be extracted $v_extract_file = TRUE; } // ----- Look if this file need to be ext