Example #1
0
 function PclTarHandleAddList($p_tar, $p_list, $p_mode, &$p_list_detail, $p_add_dir, $p_remove_dir)
 {
     TrFctStart(__FILE__, __LINE__, "PclTarHandleAddList", "tar='{$p_tar}', list, mode='{$p_mode}', add_dir='{$p_add_dir}', remove_dir='{$p_remove_dir}'");
     $v_result = 1;
     $v_header = array();
     // ----- Recuperate the current number of elt in list
     $v_nb = sizeof($p_list_detail);
     // ----- Check the parameters
     if ($p_tar == 0) {
         // ----- Error log
         PclErrorLog(-3, "Invalid file descriptor in file " . __FILE__ . ", line " . __LINE__);
         // ----- Return
         TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
         return PclErrorCode();
     }
     // ----- Check the arguments
     if (sizeof($p_list) == 0) {
         // ----- Error log
         PclErrorLog(-3, "Invalid file list parameter (invalid or empty list)");
         // ----- Return
         TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
         return PclErrorCode();
     }
     // ----- Loop on the files
     for ($j = 0; $j < count($p_list) && $v_result == 1; $j++) {
         // ----- Recuperate the filename
         $p_filename = $p_list[$j];
         TrFctMessage(__FILE__, __LINE__, 2, "Looking for file [{$p_filename}]");
         // ----- Skip empty file names
         if ($p_filename == "") {
             TrFctMessage(__FILE__, __LINE__, 2, "Skip empty filename");
             continue;
         }
         // ----- Check the filename
         if (!file_exists($p_filename)) {
             // ----- Error log
             TrFctMessage(__FILE__, __LINE__, 2, "File '{$p_filename}' does not exists");
             PclErrorLog(-4, "File '{$p_filename}' does not exists");
             // ----- Return
             TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
             return PclErrorCode();
         }
         // ----- Check the path length
         if (strlen($p_filename) > 99) {
             // ----- Error log
             PclErrorLog(-5, "File name is too long (max. 99) : '{$p_filename}'");
             // ----- Return
             TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
             return PclErrorCode();
         }
         TrFctMessage(__FILE__, __LINE__, 4, "File position before header =" . ($p_mode == "tar" ? ftell($p_tar) : gztell($p_tar)));
         // ----- Add the file
         if (($v_result = PclTarHandleAddFile($p_tar, $p_filename, $p_mode, $v_header, $p_add_dir, $p_remove_dir)) != 1) {
             // ----- Return status
             TrFctEnd(__FILE__, __LINE__, $v_result);
             return $v_result;
         }
         // ----- Store the file infos
         $p_list_detail[$v_nb++] = $v_header;
         // ----- Look for directory
         if (is_dir($p_filename)) {
             TrFctMessage(__FILE__, __LINE__, 2, "{$p_filename} is a directory");
             // ----- Look for path
             if ($p_filename != ".") {
                 $v_path = $p_filename . "/";
             } else {
                 $v_path = "";
             }
             // ----- Read the directory for files and sub-directories
             $p_hdir = opendir($p_filename);
             $p_hitem = readdir($p_hdir);
             // '.' directory
             $p_hitem = readdir($p_hdir);
             // '..' directory
             while ($p_hitem = readdir($p_hdir)) {
                 // ----- Look for a file
                 if (is_file($v_path . $p_hitem)) {
                     TrFctMessage(__FILE__, __LINE__, 4, "Add the file '" . $v_path . $p_hitem . "'");
                     // ----- Add the file
                     if (($v_result = PclTarHandleAddFile($p_tar, $v_path . $p_hitem, $p_mode, $v_header, $p_add_dir, $p_remove_dir)) != 1) {
                         // ----- Return status
                         TrFctEnd(__FILE__, __LINE__, $v_result);
                         return $v_result;
                     }
                     // ----- Store the file infos
                     $p_list_detail[$v_nb++] = $v_header;
                 } else {
                     TrFctMessage(__FILE__, __LINE__, 4, "'" . $v_path . $p_hitem . "' is a directory");
                     // ----- Need an array as parameter
                     $p_temp_list[0] = $v_path . $p_hitem;
                     $v_result = PclTarHandleAddList($p_tar, $p_temp_list, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir);
                 }
             }
             // ----- Free memory for the recursive loop
             unset($p_temp_list);
             unset($p_hdir);
             unset($p_hitem);
         } else {
             TrFctMessage(__FILE__, __LINE__, 4, "File position after blocks =" . ($p_mode == "tar" ? ftell($p_tar) : gztell($p_tar)));
         }
     }
     // ----- Return
     TrFctEnd(__FILE__, __LINE__, $v_result);
     return $v_result;
 }
Example #2
0
 function PclTarHandleAddList($p_tar, $p_list, $p_mode, &$p_list_detail, $p_add_dir, $p_remove_dir)
 {
     TrFctStart(__FILE__, __LINE__, "PclTarHandleAddList", "tar='{$p_tar}', list, mode='{$p_mode}', add_dir='{$p_add_dir}', remove_dir='{$p_remove_dir}'");
     $v_result = 1;
     $v_header = array();
     $v_nb = sizeof($p_list_detail);
     if ($p_tar == 0) {
         PclErrorLog(-3, "Invalid file descriptor in file " . __FILE__ . ", line " . __LINE__);
         TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
         return PclErrorCode();
     }
     if (sizeof($p_list) == 0) {
         PclErrorLog(-3, "Invalid file list parameter (invalid or empty list)");
         TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
         return PclErrorCode();
     }
     for ($j = 0; $j < count($p_list) && $v_result == 1; $j++) {
         $p_filename = $p_list[$j];
         TrFctMessage(__FILE__, __LINE__, 2, "Looking for file [{$p_filename}]");
         if ($p_filename == "") {
             TrFctMessage(__FILE__, __LINE__, 2, "Skip empty filename");
             continue;
         }
         if (!file_exists($p_filename)) {
             TrFctMessage(__FILE__, __LINE__, 2, "File '{$p_filename}' does not exists");
             PclErrorLog(-4, "File '{$p_filename}' does not exists");
             TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
             return PclErrorCode();
         }
         if (strlen($p_filename) > 99) {
             PclErrorLog(-5, "File name is too long (max. 99) : '{$p_filename}'");
             TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
             return PclErrorCode();
         }
         TrFctMessage(__FILE__, __LINE__, 4, "File position before header =" . ($p_mode == "tar" ? ftell($p_tar) : gztell($p_tar)));
         if (($v_result = PclTarHandleAddFile($p_tar, $p_filename, $p_mode, $v_header, $p_add_dir, $p_remove_dir)) != 1) {
             TrFctEnd(__FILE__, __LINE__, $v_result);
             return $v_result;
         }
         $p_list_detail[$v_nb++] = $v_header;
         if (is_dir($p_filename)) {
             TrFctMessage(__FILE__, __LINE__, 2, "{$p_filename} is a directory");
             if ($p_filename != ".") {
                 $v_path = $p_filename . "/";
             } else {
                 $v_path = "";
             }
             $p_hdir = opendir($p_filename);
             $p_hitem = readdir($p_hdir);
             $p_hitem = readdir($p_hdir);
             while ($p_hitem = readdir($p_hdir)) {
                 if (is_file($v_path . $p_hitem)) {
                     TrFctMessage(__FILE__, __LINE__, 4, "Add the file '" . $v_path . $p_hitem . "'");
                     if (($v_result = PclTarHandleAddFile($p_tar, $v_path . $p_hitem, $p_mode, $v_header, $p_add_dir, $p_remove_dir)) != 1) {
                         TrFctEnd(__FILE__, __LINE__, $v_result);
                         return $v_result;
                     }
                     $p_list_detail[$v_nb++] = $v_header;
                 } else {
                     TrFctMessage(__FILE__, __LINE__, 4, "'" . $v_path . $p_hitem . "' is a directory");
                     $p_temp_list[0] = $v_path . $p_hitem;
                     $v_result = PclTarHandleAddList($p_tar, $p_temp_list, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir);
                 }
             }
             unset($p_temp_list);
             unset($p_hdir);
             unset($p_hitem);
         } else {
             TrFctMessage(__FILE__, __LINE__, 4, "File position after blocks =" . ($p_mode == "tar" ? ftell($p_tar) : gztell($p_tar)));
         }
     }
     TrFctEnd(__FILE__, __LINE__, $v_result);
     return $v_result;
 }