function PclTarHandleExtractByIndexList($p_tarname, $p_index_string, &$p_list_detail, $p_path, $p_remove_path, $p_tar_mode) { TrFctStart(__FILE__, __LINE__, "PclTarHandleExtractByIndexList", "archive='{$p_tarname}', index_string='{$p_index_string}', list, path={$p_path}, remove_path='{$p_remove_path}', tar_mode={$p_tar_mode}"); $v_result = 1; $v_nb = 0; // ----- TBC : I should check the string by a regexp // ----- Check the path if ($p_path == "" || substr($p_path, 0, 1) != "/" && substr($p_path, 0, 3) != "../" && substr($p_path, 0, 2) != "./") { $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); // ----- 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(); } // ----- Manipulate the index list $v_list = explode(",", $p_index_string); sort($v_list); // ----- Loop on the index list $v_index = 0; for ($i = 0; $i < sizeof($v_list) && $v_result; $i++) { TrFctMessage(__FILE__, __LINE__, 3, "Looking for index part '{$v_list[$i]}'"); // ----- Extract range $v_index_list = explode("-", $v_list[$i]); $v_size_index_list = sizeof($v_index_list); if ($v_size_index_list == 1) { TrFctMessage(__FILE__, __LINE__, 3, "Only one index '{$v_index_list['0']}'"); // ----- Do the extraction $v_result = PclTarHandleExtractByIndex($v_tar, $v_index, $v_index_list[0], $v_index_list[0], $p_list_detail, $p_path, $p_remove_path, $p_tar_mode); } else { if ($v_size_index_list == 2) { TrFctMessage(__FILE__, __LINE__, 3, "Two indexes '{$v_index_list['0']}' and '{$v_index_list['1']}'"); // ----- Do the extraction $v_result = PclTarHandleExtractByIndex($v_tar, $v_index, $v_index_list[0], $v_index_list[1], $p_list_detail, $p_path, $p_remove_path, $p_tar_mode); } } } // ----- Close the tarfile if ($p_tar_mode == "tar") { fclose($v_tar); } else { gzclose($v_tar); } // ----- Return TrFctEnd(__FILE__, __LINE__, $v_result); return $v_result; }
function PclTarHandleExtractByIndexList($p_tarname, $p_index_string, &$p_list_detail, $p_path, $p_remove_path, $p_tar_mode) { TrFctStart(__FILE__, __LINE__, "PclTarHandleExtractByIndexList", "archive='{$p_tarname}', index_string='{$p_index_string}', list, path={$p_path}, remove_path='{$p_remove_path}', tar_mode={$p_tar_mode}"); $v_result = 1; $v_nb = 0; if ($p_path == "" || substr($p_path, 0, 1) != "/" && substr($p_path, 0, 3) != "../" && substr($p_path, 0, 2) != "./") { $p_path = "./" . $p_path; } if ($p_remove_path != "" && substr($p_remove_path, -1) != '/') { $p_remove_path .= '/'; } $p_remove_path_size = strlen($p_remove_path); 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"); } if ($v_tar == 0) { PclErrorLog(-2, "Unable to open archive '{$p_tarname}' in binary read mode"); TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return PclErrorCode(); } $v_list = explode(",", $p_index_string); sort($v_list); $v_index = 0; for ($i = 0; $i < sizeof($v_list) && $v_result; $i++) { TrFctMessage(__FILE__, __LINE__, 3, "Looking for index part '{$v_list[$i]}'"); $v_index_list = explode("-", $v_list[$i]); $v_size_index_list = sizeof($v_index_list); if ($v_size_index_list == 1) { TrFctMessage(__FILE__, __LINE__, 3, "Only one index '{$v_index_list['0']}'"); $v_result = PclTarHandleExtractByIndex($v_tar, $v_index, $v_index_list[0], $v_index_list[0], $p_list_detail, $p_path, $p_remove_path, $p_tar_mode); } else { if ($v_size_index_list == 2) { TrFctMessage(__FILE__, __LINE__, 3, "Two indexes '{$v_index_list['0']}' and '{$v_index_list['1']}'"); $v_result = PclTarHandleExtractByIndex($v_tar, $v_index, $v_index_list[0], $v_index_list[1], $p_list_detail, $p_path, $p_remove_path, $p_tar_mode); } } } if ($p_tar_mode == "tar") { fclose($v_tar); } else { gzclose($v_tar); } TrFctEnd(__FILE__, __LINE__, $v_result); return $v_result; }