function PclTarHandleExtractByIndex($p_tar, &$p_index_current, $p_index_start, $p_index_stop, &$p_list_detail, $p_path, $p_remove_path, $p_tar_mode) { TrFctStart(__FILE__, __LINE__, "PclTarHandleExtractByIndex", "archive_descr='{$p_tar}', index_current={$p_index_current}, index_start='{$p_index_start}', index_stop='{$p_index_stop}', list, path={$p_path}, remove_path='{$p_remove_path}', tar_mode={$p_tar_mode}"); $v_result = 1; $v_nb = 0; // TBC : I should replace all $v_tar by $p_tar in this function .... $v_tar = $p_tar; // ----- Look the number of elements already in $p_list_detail $v_nb = sizeof($p_list_detail); // ----- 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 file ..."); TrFctMessage(__FILE__, __LINE__, 3, "Index current={$p_index_current}, range=[{$p_index_start}, {$p_index_stop}])"); if ($p_index_current > $p_index_stop) { TrFctMessage(__FILE__, __LINE__, 2, "Stop extraction, past stop index"); break; } // ----- 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) { // ----- 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 if file is in the range to be extracted if ($p_index_current >= $p_index_start && $p_index_current <= $p_index_stop) { TrFctMessage(__FILE__, __LINE__, 2, "File '{$v_header['filename']}' is in the range to be extracted"); $v_extract_file = TRUE; } else { TrFctMessage(__FILE__, __LINE__, 2, "File '{$v_header['filename']}' is out of the range"); $v_extract_file = FALSE; } // ----- Look if this file need to be extracted if ($v_extract_file) { if (($v_result = PclTarHandleExtractFile($v_tar, $v_header, $p_path, $p_remove_path, $p_tar_mode)) != 1) { // ----- Return TrFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } } else { // ----- Trace TrFctMessage(__FILE__, __LINE__, 2, "Jump file '{$v_header['filename']}'"); TrFctMessage(__FILE__, __LINE__, 4, "Position avant jump [" . ($p_tar_mode == "tar" ? ftell($v_tar) : gztell($v_tar)) . "]"); // ----- Jump to next file if ($p_tar_mode == "tar") { fseek($v_tar, ($p_tar_mode == "tar" ? ftell($v_tar) : gztell($v_tar)) + ceil($v_header[size] / 512) * 512); } else { gzseek($v_tar, gztell($v_tar) + ceil($v_header[size] / 512) * 512); } TrFctMessage(__FILE__, __LINE__, 4, "Position après jump [" . ($p_tar_mode == "tar" ? ftell($v_tar) : gztell($v_tar)) . "]"); } if ($p_tar_mode == "tar") { $v_end_of_file = feof($v_tar); } else { $v_end_of_file = gzeof($v_tar); } // ----- File name and properties are logged if listing mode or file is extracted if ($v_extract_file) { TrFctMessage(__FILE__, __LINE__, 2, "Memorize info about file '{$v_header['filename']}'"); // ----- Log extracted files if (($v_file_dir = dirname($v_header[filename])) == $v_header[filename]) { $v_file_dir = ""; } if (substr($v_header[filename], 0, 1) == "/" && $v_file_dir == "") { $v_file_dir = "/"; } // ----- Add the array describing the file into the list $p_list_detail[$v_nb] = $v_header; // ----- Increment $v_nb++; } // ----- Increment the current file index $p_index_current++; } // ----- Return TrFctEnd(__FILE__, __LINE__, $v_result); return $v_result; }
function PclTarHandleExtractByIndex($p_tar, &$p_index_current, $p_index_start, $p_index_stop, &$p_list_detail, $p_path, $p_remove_path, $p_tar_mode) { TrFctStart(__FILE__, __LINE__, "PclTarHandleExtractByIndex", "archive_descr='{$p_tar}', index_current={$p_index_current}, index_start='{$p_index_start}', index_stop='{$p_index_stop}', list, path={$p_path}, remove_path='{$p_remove_path}', tar_mode={$p_tar_mode}"); $v_result = 1; $v_nb = 0; $v_tar = $p_tar; $v_nb = sizeof($p_list_detail); while (!($v_end_of_file = $p_tar_mode == "tar" ? feof($v_tar) : gzeof($v_tar))) { TrFctMessage(__FILE__, __LINE__, 3, "Looking for next file ..."); TrFctMessage(__FILE__, __LINE__, 3, "Index current={$p_index_current}, range=[{$p_index_start}, {$p_index_stop}])"); if ($p_index_current > $p_index_stop) { TrFctMessage(__FILE__, __LINE__, 2, "Stop extraction, past stop index"); break; } clearstatcache(); $v_extract_file = FALSE; $v_extraction_stopped = 0; if ($p_tar_mode == "tar") { $v_binary_data = fread($v_tar, 512); } else { $v_binary_data = gzread($v_tar, 512); } if (($v_result = PclTarHandleReadHeader($v_binary_data, $v_header)) != 1) { TrFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } 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']}'"); if ($p_index_current >= $p_index_start && $p_index_current <= $p_index_stop) { TrFctMessage(__FILE__, __LINE__, 2, "File '{$v_header['filename']}' is in the range to be extracted"); $v_extract_file = TRUE; } else { TrFctMessage(__FILE__, __LINE__, 2, "File '{$v_header['filename']}' is out of the range"); $v_extract_file = FALSE; } if ($v_extract_file) { if (($v_result = PclTarHandleExtractFile($v_tar, $v_header, $p_path, $p_remove_path, $p_tar_mode)) != 1) { TrFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } } else { TrFctMessage(__FILE__, __LINE__, 2, "Jump file '{$v_header['filename']}'"); TrFctMessage(__FILE__, __LINE__, 4, "Position avant jump [" . ($p_tar_mode == "tar" ? ftell($v_tar) : gztell($v_tar)) . "]"); if ($p_tar_mode == "tar") { fseek($v_tar, ($p_tar_mode == "tar" ? ftell($v_tar) : gztell($v_tar)) + ceil($v_header[size] / 512) * 512); } else { gzseek($v_tar, gztell($v_tar) + ceil($v_header[size] / 512) * 512); } TrFctMessage(__FILE__, __LINE__, 4, "Position après jump [" . ($p_tar_mode == "tar" ? ftell($v_tar) : gztell($v_tar)) . "]"); } if ($p_tar_mode == "tar") { $v_end_of_file = feof($v_tar); } else { $v_end_of_file = gzeof($v_tar); } if ($v_extract_file) { TrFctMessage(__FILE__, __LINE__, 2, "Memorize info about file '{$v_header['filename']}'"); if (($v_file_dir = dirname($v_header[filename])) == $v_header[filename]) { $v_file_dir = ""; } if (substr($v_header[filename], 0, 1) == "/" && $v_file_dir == "") { $v_file_dir = "/"; } $p_list_detail[$v_nb] = $v_header; $v_nb++; } $p_index_current++; } TrFctEnd(__FILE__, __LINE__, $v_result); return $v_result; }