_tarname_add, "rb")) == 0) { // ----- Error log PclErrorLog(-2, "Unable to open file '$p_tarname_add' in binary read mode"); // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return PclErrorCode(); } // ----- Read the first 512 bytes block $v_buffer = fread($p_tar_add, 512); // ----- Read the following blocks but not the last one if (!feof($p_tar_add)) { TrFctMessage(__FILE__, __LINE__, 3, "More than one 512 block file"); $i=1; // ----- Read new 512 block and write the already read do{ // ----- Write the already read block $v_binary_data = pack("a512", "$v_buffer"); if ($p_mode=="tar") fputs($p_tar, $v_binary_data); else gzputs($v_temp_tar, $v_binary_data); $i++; TrFctMessage(__FILE__, __LINE__, 3, "Reading block $i"); // ----- Read next block $v_buffer = fread($p_tar_add, 512); } while (!feof($p_tar_add)); TrFctMessage(__FILE__, __LINE__, 3, "$i 512 bytes blocks"); } // ----- Close the files fclose($p_tar_add); } // ----- Call the footer of the tar archive $v_result = PclTarHandleFooter($p_tar, $p_mode); // ----- Look for closing compressed archive if ($p_mode == "tgz") { // ----- Close the files gzclose($p_tar); gzclose($v_temp_tar); // ----- Unlink tar file if (!@unlink($p_tarname)) { // ----- Error log PclErrorLog(-11, "Error while deleting archive name $p_tarname"); } // ----- Rename tar file if (!@rename($v_temp_tarname, $p_tarname)) { // ----- Error log PclErrorLog(-12, "Error while renaming temporary file $v_temp_tarname to archive name $p_tarname"); // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return PclErrorCode(); } // ----- Return TrFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Look for closing uncompressed tar file else if ($p_mode=="tar") { // ----- Close the tarfile fclose($p_tar); } // ----- Return TrFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS ***** // ***** ***** // ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY ***** // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : PclTarHandleCreate() // Description : // Parameters : // $p_tarname : Name of the tar file // $p_list : An array containing the file or directory names to add in the tar // $p_mode : "tar" for normal tar archive, "tgz" for gzipped tar archive // Return Values : // -------------------------------------------------------------------------------- function PclTarHandleCreate($p_tarname, $p_list, $p_mode, $p_add_dir="", $p_remove_dir="") { TrFctStart(__FILE__, __LINE__, "PclTarHandleCreate", "tar=$p_tarname, list, mode=$p_mode, add_dir='$p_add_dir', remove_dir='$p_remove_dir'"); $v_result=1; $v_list_detail = array(); // ----- Check the parameters if (($p_tarname == "") || (($p_mode != "tar") && ($p_mode != "tgz"))) { // ----- Error log if ($p_tarname == "") PclErrorLog(-3, "Invalid empty archive name"); else PclErrorLog(-3, "Unknown mode '$p_mode'"); // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return PclErrorCode(); } // ----- Look for tar file if ($p_mode == "tar") { // ----- Open the tar file if (($p_tar = fopen($p_tarname, "wb")) == 0) { // ----- Error log PclErrorLog(-1, "Unable to open file [$p_tarname] in binary write mode"); // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return PclErrorCode(); } // ----- Call the adding fct inside the tar if (($v_result = PclTarHandleAddList($p_tar, $p_list, $p_mode, $v_list_detail, $p_add_dir, $p_remove_dir)) == 1) { // ----- Call the footer of the tar archive $v_result = PclTarHandleFooter($p_tar, $p_mode); } // ----- Close the tarfile fclose($p_tar); } // ----- Look for tgz file else { // ----- Open the tar file if (($p_tar = @gzopen($p_tarname, "wb")) == 0) { // ----- Error log PclErrorLog(-1, "Unable to open file [$p_tarname] in binary write mode"); // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return PclErrorCode(); } // ----- Call the adding fct inside the tar if (($v_result = PclTarHandleAddList($p_tar, $p_list, $p_mode, $v_list_detail, $p_add_dir, $p_remove_dir)) == 1) { // ----- Call the footer of the tar archive $v_result = PclTarHandleFooter($p_tar, $p_mode); } // ----- Close the tarfile gzclose($p_tar); } // ----- Return TrFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : PclTarHandleAppend() // Description : // Parameters : // $p_tarname : Name of the tar file // $p_list : An array containing the file or directory names to add in the tar // $p_mode : "tar" for normal tar archive, "tgz" for gzipped tar archive // Return Values : // -------------------------------------------------------------------------------- function PclTarHandleAppend($p_tarname, $p_list, $p_mode, &$p_list_detail, $p_add_dir, $p_remove_dir) { TrFctStart(__FI