PageRenderTime 65ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/dist/webpagetest/www/lib/pcltar.lib.php3

http://webpagetest.googlecode.com/
PHP | 3557 lines | 1991 code | 507 blank | 1059 comment | 617 complexity | 10c4a9dd663a648c26d3296fe8e39c62 MD5 | raw file
Possible License(s): AGPL-1.0, Apache-2.0, GPL-3.0, LGPL-3.0, MIT, BSD-3-Clause, ISC, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?
  2. // --------------------------------------------------------------------------------
  3. // PhpConcept Library - Tar Module 1.3.1
  4. // --------------------------------------------------------------------------------
  5. // License GNU/GPL - Vincent Blavet - January 2003
  6. // http://www.phpconcept.net
  7. // --------------------------------------------------------------------------------
  8. //
  9. // Presentation :
  10. // PclTar is a library that allow you to create a GNU TAR + GNU ZIP archive,
  11. // to add files or directories, to extract all the archive or a part of it.
  12. // So far tests show that the files generated by PclTar are readable by
  13. // gzip tools and WinZip application.
  14. //
  15. // Description :
  16. // See readme.txt (English & Français) and http://www.phpconcept.net
  17. //
  18. // Warning :
  19. // This library and the associated files are non commercial, non professional
  20. // work.
  21. // It should not have unexpected results. However if any damage is caused by
  22. // this software the author can not be responsible.
  23. // The use of this software is at the risk of the user.
  24. //
  25. // --------------------------------------------------------------------------------
  26. // ----- Look for double include
  27. if (!defined("PCL_TAR"))
  28. {
  29. define( "PCL_TAR", 1 );
  30. // ----- Configuration variable
  31. // Theses values may be changed by the user of PclTar library
  32. if (!isset($g_pcltar_lib_dir))
  33. $g_pcltar_lib_dir = "lib";
  34. // ----- Error codes
  35. // -1 : Unable to open file in binary write mode
  36. // -2 : Unable to open file in binary read mode
  37. // -3 : Invalid parameters
  38. // -4 : File does not exist
  39. // -5 : Filename is too long (max. 99)
  40. // -6 : Not a valid tar file
  41. // -7 : Invalid extracted file size
  42. // -8 : Unable to create directory
  43. // -9 : Invalid archive extension
  44. // -10 : Invalid archive format
  45. // -11 : Unable to delete file (unlink)
  46. // -12 : Unable to rename file (rename)
  47. // -13 : Invalid header checksum
  48. // --------------------------------------------------------------------------------
  49. // ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED *****
  50. // --------------------------------------------------------------------------------
  51. // ----- Global variables
  52. $g_pcltar_version = "1.3.1";
  53. // ----- Extract extension type (.php3/.php/...)
  54. $g_pcltar_extension = substr(strrchr(basename($PATH_TRANSLATED), '.'), 1);
  55. // ----- Include other libraries
  56. // This library should be called by each script before the include of PhpZip
  57. // Library in order to limit the potential 'lib' directory path problem.
  58. if (!defined("PCLERROR_LIB"))
  59. {
  60. include($g_pcltar_lib_dir."/pclerror.lib.".$g_pcltar_extension);
  61. }
  62. if (!defined("PCLTRACE_LIB"))
  63. {
  64. include($g_pcltar_lib_dir."/pcltrace.lib.".$g_pcltar_extension);
  65. }
  66. // --------------------------------------------------------------------------------
  67. // Function : PclTarCreate()
  68. // Description :
  69. // Creates a new archive with name $p_tarname containing the files and/or
  70. // directories indicated in $p_list. If the tar filename extension is
  71. // ".tar", the file will not be compressed. If it is ".tar.gz" or ".tgz"
  72. // it will be a gzip compressed tar archive.
  73. // If you want to use an other extension, you must indicate the mode in
  74. // $p_mode ("tar" or "tgz").
  75. // $p_add_dir and $p_remove_dir give you the ability to store a path
  76. // which is not the real path of the files.
  77. // Parameters :
  78. // $p_tarname : Name of an existing tar file
  79. // $p_filelist : An array containing file or directory names, or
  80. // a string containing one filename or directory name, or
  81. // a string containing a list of filenames and/or directory
  82. // names separated by spaces.
  83. // $p_mode : "tar" for normal tar archive, "tgz" for gzipped tar archive,
  84. // if $p_mode is not specified, it will be determined by the extension.
  85. // $p_add_dir : Path to add in the filename path archived
  86. // $p_remove_dir : Path to remove in the filename path archived
  87. // Return Values :
  88. // 1 on success, or an error code (see table at the beginning).
  89. // --------------------------------------------------------------------------------
  90. function PclTarCreate($p_tarname, $p_filelist="", $p_mode="", $p_add_dir="", $p_remove_dir="")
  91. {
  92. TrFctStart(__FILE__, __LINE__, "PclTarCreate", "tar=$p_tarname, file='$p_filelist', mode=$p_mode, add_dir='$p_add_dir', remove_dir='$p_remove_dir'");
  93. $v_result=1;
  94. // ----- Look for default mode
  95. if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
  96. {
  97. // ----- Extract the tar format from the extension
  98. if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
  99. {
  100. // ----- Return
  101. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  102. return PclErrorCode();
  103. }
  104. // ----- Trace
  105. TrFctMessage(__FILE__, __LINE__, 1, "Auto mode selected : found $p_mode");
  106. }
  107. // ----- Look if the $p_filelist is really an array
  108. if (is_array($p_filelist))
  109. {
  110. // ----- Call the create fct
  111. $v_result = PclTarHandleCreate($p_tarname, $p_filelist, $p_mode, $p_add_dir, $p_remove_dir);
  112. }
  113. // ----- Look if the $p_filelist is a string
  114. else if (is_string($p_filelist))
  115. {
  116. // ----- Create a list with the elements from the string
  117. $v_list = explode(" ", $p_filelist);
  118. // ----- Call the create fct
  119. $v_result = PclTarHandleCreate($p_tarname, $v_list, $p_mode, $p_add_dir, $p_remove_dir);
  120. }
  121. // ----- Invalid variable
  122. else
  123. {
  124. // ----- Error log
  125. PclErrorLog(-3, "Invalid variable type p_filelist");
  126. $v_result = -3;
  127. }
  128. // ----- Return
  129. TrFctEnd(__FILE__, __LINE__, $v_result);
  130. return $v_result;
  131. }
  132. // --------------------------------------------------------------------------------
  133. // --------------------------------------------------------------------------------
  134. // Function : PclTarAdd()
  135. // Description :
  136. // PLEASE DO NOT USE ANY MORE THIS FUNCTION. Use PclTarAddList().
  137. //
  138. // This function is maintained only for compatibility reason
  139. //
  140. // Parameters :
  141. // $p_tarname : Name of an existing tar file
  142. // $p_filelist : An array containing file or directory names, or
  143. // a string containing one filename or directory name, or
  144. // a string containing a list of filenames and/or directory
  145. // names separated by spaces.
  146. // Return Values :
  147. // 1 on success,
  148. // Or an error code (see list on top).
  149. // --------------------------------------------------------------------------------
  150. function PclTarAdd($p_tarname, $p_filelist)
  151. {
  152. TrFctStart(__FILE__, __LINE__, "PclTarAdd", "tar=$p_tarname, file=$p_filelist");
  153. $v_result=1;
  154. $v_list_detail = array();
  155. // ----- Extract the tar format from the extension
  156. if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
  157. {
  158. // ----- Return
  159. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  160. return PclErrorCode();
  161. }
  162. // ----- Look if the $p_filelist is really an array
  163. if (is_array($p_filelist))
  164. {
  165. // ----- Call the add fct
  166. $v_result = PclTarHandleAppend($p_tarname, $p_filelist, $p_mode, $v_list_detail, "", "");
  167. }
  168. // ----- Look if the $p_filelist is a string
  169. else if (is_string($p_filelist))
  170. {
  171. // ----- Create a list with the elements from the string
  172. $v_list = explode(" ", $p_filelist);
  173. // ----- Call the add fct
  174. $v_result = PclTarHandleAppend($p_tarname, $v_list, $p_mode, $v_list_detail, "", "");
  175. }
  176. // ----- Invalid variable
  177. else
  178. {
  179. // ----- Error log
  180. PclErrorLog(-3, "Invalid variable type p_filelist");
  181. $v_result = -3;
  182. }
  183. // ----- Cleaning
  184. unset($v_list_detail);
  185. // ----- Return
  186. TrFctEnd(__FILE__, __LINE__, $v_result);
  187. return $v_result;
  188. }
  189. // --------------------------------------------------------------------------------
  190. // --------------------------------------------------------------------------------
  191. // Function : PclTarAddList()
  192. // Description :
  193. // Add a list of files or directories ($p_filelist) in the tar archive $p_tarname.
  194. // The list can be an array of file/directory names or a string with names
  195. // separated by one space.
  196. // $p_add_dir and $p_remove_dir will give the ability to memorize a path which is
  197. // different from the real path of the file. This is usefull if you want to have PclTar
  198. // running in any directory, and memorize relative path from an other directory.
  199. // If $p_mode is not set it will be automatically computed from the $p_tarname
  200. // extension (.tar, .tar.gz or .tgz).
  201. // Parameters :
  202. // $p_tarname : Name of an existing tar file
  203. // $p_filelist : An array containing file or directory names, or
  204. // a string containing one filename or directory name, or
  205. // a string containing a list of filenames and/or directory
  206. // names separated by spaces.
  207. // $p_add_dir : Path to add in the filename path archived
  208. // $p_remove_dir : Path to remove in the filename path archived
  209. // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
  210. // Return Values :
  211. // 1 on success,
  212. // Or an error code (see list on top).
  213. // --------------------------------------------------------------------------------
  214. function PclTarAddList($p_tarname, $p_filelist, $p_add_dir="", $p_remove_dir="", $p_mode="")
  215. {
  216. TrFctStart(__FILE__, __LINE__, "PclTarAddList", "tar=$p_tarname, file=$p_filelist, p_add_dir='$p_add_dir', p_remove_dir='$p_remove_dir', mode=$p_mode");
  217. $v_result=1;
  218. $p_list_detail = array();
  219. // ----- Extract the tar format from the extension
  220. if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
  221. {
  222. if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
  223. {
  224. // ----- Return
  225. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  226. return PclErrorCode();
  227. }
  228. }
  229. // ----- Look if the $p_filelist is really an array
  230. if (is_array($p_filelist))
  231. {
  232. // ----- Call the add fct
  233. $v_result = PclTarHandleAppend($p_tarname, $p_filelist, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir);
  234. }
  235. // ----- Look if the $p_filelist is a string
  236. else if (is_string($p_filelist))
  237. {
  238. // ----- Create a list with the elements from the string
  239. $v_list = explode(" ", $p_filelist);
  240. // ----- Call the add fct
  241. $v_result = PclTarHandleAppend($p_tarname, $v_list, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir);
  242. }
  243. // ----- Invalid variable
  244. else
  245. {
  246. // ----- Error log
  247. PclErrorLog(-3, "Invalid variable type p_filelist");
  248. $v_result = -3;
  249. }
  250. // ----- Return
  251. if ($v_result != 1)
  252. {
  253. TrFctEnd(__FILE__, __LINE__, 0);
  254. return 0;
  255. }
  256. TrFctEnd(__FILE__, __LINE__, $p_list_detail);
  257. return $p_list_detail;
  258. }
  259. // --------------------------------------------------------------------------------
  260. // --------------------------------------------------------------------------------
  261. // Function : PclTarList()
  262. // Description :
  263. // Gives the list of all the files present in the tar archive $p_tarname.
  264. // The list is the function result, it will be 0 on error.
  265. // Depending on the $p_tarname extension (.tar, .tar.gz or .tgz) the
  266. // function will determine the type of the archive.
  267. // Parameters :
  268. // $p_tarname : Name of an existing tar file
  269. // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
  270. // Return Values :
  271. // 0 on error (Use PclErrorCode() and PclErrorString() for more info)
  272. // or
  273. // An array containing file properties. Each file properties is an array of
  274. // properties.
  275. // The properties (array field names) are :
  276. // filename, size, mode, uid, gid, mtime, typeflag, status
  277. // Exemple : $v_list = PclTarList("my.tar");
  278. // for ($i=0; $i<sizeof($v_list); $i++)
  279. // echo "Filename :'".$v_list[$i][filename]."'<br>";
  280. // --------------------------------------------------------------------------------
  281. function PclTarList($p_tarname, $p_mode="")
  282. {
  283. TrFctStart(__FILE__, __LINE__, "PclTarList", "tar=$p_tarname, mode='$p_mode'");
  284. $v_result=1;
  285. // ----- Extract the tar format from the extension
  286. if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
  287. {
  288. if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
  289. {
  290. // ----- Return
  291. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  292. return 0;
  293. }
  294. }
  295. // ----- Call the extracting fct
  296. $p_list = array();
  297. if (($v_result = PclTarHandleExtract($p_tarname, 0, $p_list, "list", "", $p_mode, "")) != 1)
  298. {
  299. unset($p_list);
  300. TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
  301. return(0);
  302. }
  303. // ----- Return
  304. TrFctEnd(__FILE__, __LINE__, $p_list);
  305. return $p_list;
  306. }
  307. // --------------------------------------------------------------------------------
  308. // --------------------------------------------------------------------------------
  309. // Function : PclTarExtract()
  310. // Description :
  311. // Extract all the files present in the archive $p_tarname, in the directory
  312. // $p_path. The relative path of the archived files are keep and become
  313. // relative to $p_path.
  314. // If a file with the same name already exists it will be replaced.
  315. // If the path to the file does not exist, it will be created.
  316. // Depending on the $p_tarname extension (.tar, .tar.gz or .tgz) the
  317. // function will determine the type of the archive.
  318. // Parameters :
  319. // $p_tarname : Name of an existing tar file.
  320. // $p_path : Path where the files will be extracted. The files will use
  321. // their memorized path from $p_path.
  322. // If $p_path is "", files will be extracted in "./".
  323. // $p_remove_path : Path to remove (from the file memorized path) while writing the
  324. // extracted files. If the path does not match the file path,
  325. // the file is extracted with its memorized path.
  326. // $p_path and $p_remove_path are commulative.
  327. // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
  328. // Return Values :
  329. // Same as PclTarList()
  330. // --------------------------------------------------------------------------------
  331. function PclTarExtract($p_tarname, $p_path="./", $p_remove_path="", $p_mode="")
  332. {
  333. TrFctStart(__FILE__, __LINE__, "PclTarExtract", "tar='$p_tarname', path='$p_path', remove_path='$p_remove_path', mode='$p_mode'");
  334. $v_result=1;
  335. // ----- Extract the tar format from the extension
  336. if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
  337. {
  338. if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
  339. {
  340. // ----- Return
  341. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  342. return 0;
  343. }
  344. }
  345. // ----- Call the extracting fct
  346. if (($v_result = PclTarHandleExtract($p_tarname, 0, $p_list, "complete", $p_path, $v_tar_mode, $p_remove_path)) != 1)
  347. {
  348. TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
  349. return(0);
  350. }
  351. // ----- Return
  352. TrFctEnd(__FILE__, __LINE__, $p_list);
  353. return $p_list;
  354. }
  355. // --------------------------------------------------------------------------------
  356. // --------------------------------------------------------------------------------
  357. // Function : PclTarExtractList()
  358. // Description :
  359. // Extract the files present in the archive $p_tarname and specified in
  360. // $p_filelist, in the directory
  361. // $p_path. The relative path of the archived files are keep and become
  362. // relative to $p_path.
  363. // If a directory is spécified in the list, all the files from this directory
  364. // will be extracted.
  365. // If a file with the same name already exists it will be replaced.
  366. // If the path to the file does not exist, it will be created.
  367. // Depending on the $p_tarname extension (.tar, .tar.gz or .tgz) the
  368. // function will determine the type of the archive.
  369. // Parameters :
  370. // $p_tarname : Name of an existing tar file
  371. // $p_filelist : An array containing file or directory names, or
  372. // a string containing one filename or directory name, or
  373. // a string containing a list of filenames and/or directory
  374. // names separated by spaces.
  375. // $p_path : Path where the files will be extracted. The files will use
  376. // their memorized path from $p_path.
  377. // If $p_path is "", files will be extracted in "./".
  378. // $p_remove_path : Path to remove (from the file memorized path) while writing the
  379. // extracted files. If the path does not match the file path,
  380. // the file is extracted with its memorized path.
  381. // $p_path and $p_remove_path are commulative.
  382. // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
  383. // Return Values :
  384. // Same as PclTarList()
  385. // --------------------------------------------------------------------------------
  386. function PclTarExtractList($p_tarname, $p_filelist, $p_path="./", $p_remove_path="", $p_mode="")
  387. {
  388. TrFctStart(__FILE__, __LINE__, "PclTarExtractList", "tar=$p_tarname, list, path=$p_path, remove_path='$p_remove_path', mode='$p_mode'");
  389. $v_result=1;
  390. // ----- Extract the tar format from the extension
  391. if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
  392. {
  393. if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
  394. {
  395. // ----- Return
  396. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  397. return 0;
  398. }
  399. }
  400. // ----- Look if the $p_filelist is really an array
  401. if (is_array($p_filelist))
  402. {
  403. // ----- Call the extracting fct
  404. if (($v_result = PclTarHandleExtract($p_tarname, $p_filelist, $p_list, "partial", $p_path, $v_tar_mode, $p_remove_path)) != 1)
  405. {
  406. TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
  407. return(0);
  408. }
  409. }
  410. // ----- Look if the $p_filelist is a string
  411. else if (is_string($p_filelist))
  412. {
  413. // ----- Create a list with the elements from the string
  414. $v_list = explode(" ", $p_filelist);
  415. // ----- Call the extracting fct
  416. if (($v_result = PclTarHandleExtract($p_tarname, $v_list, $p_list, "partial", $p_path, $v_tar_mode, $p_remove_path)) != 1)
  417. {
  418. TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
  419. return(0);
  420. }
  421. }
  422. // ----- Invalid variable
  423. else
  424. {
  425. // ----- Error log
  426. PclErrorLog(-3, "Invalid variable type p_filelist");
  427. // ----- Return
  428. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  429. return 0;
  430. }
  431. // ----- Return
  432. TrFctEnd(__FILE__, __LINE__, $p_list);
  433. return $p_list;
  434. }
  435. // --------------------------------------------------------------------------------
  436. // --------------------------------------------------------------------------------
  437. // Function : PclTarExtractIndex()
  438. // Description :
  439. // Extract the files present in the archive $p_tarname and specified at
  440. // the indexes in $p_index, in the directory
  441. // $p_path. The relative path of the archived files are keep and become
  442. // relative to $p_path.
  443. // If a directory is specified in the list, the directory only is created. All
  444. // the file stored in this archive for this directory
  445. // are not extracted.
  446. // If a file with the same name already exists it will be replaced.
  447. // If the path to the file does not exist, it will be created.
  448. // Depending on the $p_tarname extension (.tar, .tar.gz or .tgz) the
  449. // function will determine the type of the archive.
  450. // Parameters :
  451. // $p_tarname : Name of an existing tar file
  452. // $p_index : A single index (integer) or a string of indexes of files to
  453. // extract. The form of the string is "0,4-6,8-12" with only numbers
  454. // and '-' for range or ',' to separate ranges. No spaces or ';'
  455. // are allowed.
  456. // $p_path : Path where the files will be extracted. The files will use
  457. // their memorized path from $p_path.
  458. // If $p_path is "", files will be extracted in "./".
  459. // $p_remove_path : Path to remove (from the file memorized path) while writing the
  460. // extracted files. If the path does not match the file path,
  461. // the file is extracted with its memorized path.
  462. // $p_path and $p_remove_path are commulative.
  463. // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
  464. // Return Values :
  465. // Same as PclTarList()
  466. // --------------------------------------------------------------------------------
  467. function PclTarExtractIndex($p_tarname, $p_index, $p_path="./", $p_remove_path="", $p_mode="")
  468. {
  469. TrFctStart(__FILE__, __LINE__, "PclTarExtractIndex", "tar=$p_tarname, index='$p_index', path=$p_path, remove_path='$p_remove_path', mode='$p_mode'");
  470. $v_result=1;
  471. // ----- Extract the tar format from the extension
  472. if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
  473. {
  474. if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
  475. {
  476. // ----- Return
  477. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  478. return 0;
  479. }
  480. }
  481. // ----- Look if the $p_index is really an integer
  482. if (is_integer($p_index))
  483. {
  484. // ----- Call the extracting fct
  485. if (($v_result = PclTarHandleExtractByIndexList($p_tarname, "$p_index", $p_list, $p_path, $p_remove_path, $v_tar_mode)) != 1)
  486. {
  487. TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
  488. return(0);
  489. }
  490. }
  491. // ----- Look if the $p_filelist is a string
  492. else if (is_string($p_index))
  493. {
  494. // ----- Call the extracting fct
  495. if (($v_result = PclTarHandleExtractByIndexList($p_tarname, $p_index, $p_list, $p_path, $p_remove_path, $v_tar_mode)) != 1)
  496. {
  497. TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
  498. return(0);
  499. }
  500. }
  501. // ----- Invalid variable
  502. else
  503. {
  504. // ----- Error log
  505. PclErrorLog(-3, "Invalid variable type $p_index");
  506. // ----- Return
  507. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  508. return 0;
  509. }
  510. // ----- Return
  511. TrFctEnd(__FILE__, __LINE__, $p_list);
  512. return $p_list;
  513. }
  514. // --------------------------------------------------------------------------------
  515. // --------------------------------------------------------------------------------
  516. // Function : PclTarDelete()
  517. // Description :
  518. // This function deletes from the archive $p_tarname the files which are listed
  519. // in $p_filelist. $p_filelist can be a string with file names separated by
  520. // spaces, or an array containing the file names.
  521. // Parameters :
  522. // $p_tarname : Name of an existing tar file
  523. // $p_filelist : An array or a string containing file names to remove from the
  524. // archive.
  525. // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
  526. // Return Values :
  527. // List of the files which are kept in the archive (same format as PclTarList())
  528. // --------------------------------------------------------------------------------
  529. function PclTarDelete($p_tarname, $p_filelist, $p_mode="")
  530. {
  531. TrFctStart(__FILE__, __LINE__, "PclTarDelete", "tar='$p_tarname', list='$p_filelist', mode='$p_mode'");
  532. $v_result=1;
  533. // ----- Extract the tar format from the extension
  534. if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
  535. {
  536. if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
  537. {
  538. // ----- Return
  539. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  540. return 0;
  541. }
  542. }
  543. // ----- Look if the $p_filelist is really an array
  544. if (is_array($p_filelist))
  545. {
  546. // ----- Call the extracting fct
  547. if (($v_result = PclTarHandleDelete($p_tarname, $p_filelist, $p_list, $p_mode)) != 1)
  548. {
  549. TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
  550. return(0);
  551. }
  552. }
  553. // ----- Look if the $p_filelist is a string
  554. else if (is_string($p_filelist))
  555. {
  556. // ----- Create a list with the elements from the string
  557. $v_list = explode(" ", $p_filelist);
  558. // ----- Call the extracting fct
  559. if (($v_result = PclTarHandleDelete($p_tarname, $v_list, $p_list, $p_mode)) != 1)
  560. {
  561. TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
  562. return(0);
  563. }
  564. }
  565. // ----- Invalid variable
  566. else
  567. {
  568. // ----- Error log
  569. PclErrorLog(-3, "Invalid variable type p_filelist");
  570. // ----- Return
  571. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  572. return 0;
  573. }
  574. // ----- Return
  575. TrFctEnd(__FILE__, __LINE__, $p_list);
  576. return $p_list;
  577. }
  578. // --------------------------------------------------------------------------------
  579. // --------------------------------------------------------------------------------
  580. // Function : PclTarUpdate()
  581. // Description :
  582. // This function updates the files in $p_filelist which are already in the
  583. // $p_tarname archive with an older last modified date. If the file does not
  584. // exist, it is added at the end of the archive.
  585. // Parameters :
  586. // $p_tarname : Name of an existing tar file
  587. // $p_filelist : An array or a string containing file names to update from the
  588. // archive.
  589. // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
  590. // Return Values :
  591. // List of the files contained in the archive. The field status contains
  592. // "updated", "not_updated", "added" or "ok" for the files not concerned.
  593. // --------------------------------------------------------------------------------
  594. function PclTarUpdate($p_tarname, $p_filelist, $p_mode="", $p_add_dir="", $p_remove_dir="")
  595. {
  596. TrFctStart(__FILE__, __LINE__, "PclTarUpdate", "tar='$p_tarname', list='$p_filelist', mode='$p_mode'");
  597. $v_result=1;
  598. // ----- Extract the tar format from the extension
  599. if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
  600. {
  601. if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
  602. {
  603. // ----- Return
  604. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  605. return 0;
  606. }
  607. }
  608. // ----- Look if the $p_filelist is really an array
  609. if (is_array($p_filelist))
  610. {
  611. // ----- Call the extracting fct
  612. if (($v_result = PclTarHandleUpdate($p_tarname, $p_filelist, $p_list, $p_mode, $p_add_dir, $p_remove_dir)) != 1)
  613. {
  614. TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
  615. return(0);
  616. }
  617. }
  618. // ----- Look if the $p_filelist is a string
  619. else if (is_string($p_filelist))
  620. {
  621. // ----- Create a list with the elements from the string
  622. $v_list = explode(" ", $p_filelist);
  623. // ----- Call the extracting fct
  624. if (($v_result = PclTarHandleUpdate($p_tarname, $v_list, $p_list, $p_mode, $p_add_dir, $p_remove_dir)) != 1)
  625. {
  626. TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
  627. return(0);
  628. }
  629. }
  630. // ----- Invalid variable
  631. else
  632. {
  633. // ----- Error log
  634. PclErrorLog(-3, "Invalid variable type p_filelist");
  635. // ----- Return
  636. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  637. return 0;
  638. }
  639. // ----- Return
  640. TrFctEnd(__FILE__, __LINE__, $p_list);
  641. return $p_list;
  642. }
  643. // --------------------------------------------------------------------------------
  644. // --------------------------------------------------------------------------------
  645. // Function : PclTarMerge()
  646. // Description :
  647. // This function add the content of $p_tarname_add at the end of $p_tarname.
  648. // Parameters :
  649. // $p_tarname : Name of an existing tar file
  650. // $p_tarname_add : Name of an existing tar file taht will be added at the end
  651. // of $p_tarname.
  652. // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
  653. // $p_mode_add : 'tar' or 'tgz', if not set, will be determined by $p_tarname_add
  654. // extension
  655. // Return Values :
  656. // List of the files contained in the archive. The field status contains
  657. // "updated", "not_updated", "added" or "ok" for the files not concerned.
  658. // --------------------------------------------------------------------------------
  659. function PclTarMerge($p_tarname, $p_tarname_add, $p_mode="", $p_mode_add="")
  660. {
  661. TrFctStart(__FILE__, __LINE__, "PclTarMerge", "tar='$p_tarname', tar_add='$p_tarname_add', mode='$p_mode', mode_add='$p_mode_add'");
  662. $v_result=1;
  663. // ----- Check the parameters
  664. if (($p_tarname == "") || ($p_tarname_add == ""))
  665. {
  666. // ----- Error log
  667. PclErrorLog(-3, "Invalid empty archive name");
  668. // ----- Return
  669. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  670. return PclErrorCode();
  671. }
  672. // ----- Extract the tar format from the extension
  673. if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
  674. {
  675. if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
  676. {
  677. // ----- Return
  678. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  679. return 0;
  680. }
  681. }
  682. if (($p_mode_add == "") || (($p_mode_add!="tar") && ($p_mode_add!="tgz")))
  683. {
  684. if (($p_mode_add = PclTarHandleExtension($p_tarname_add)) == "")
  685. {
  686. // ----- Return
  687. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  688. return 0;
  689. }
  690. }
  691. // ----- Clear filecache
  692. clearstatcache();
  693. // ----- Check the file size
  694. if ((!is_file($p_tarname)) ||
  695. (((($v_size = filesize($p_tarname)) % 512) != 0) && ($p_mode=="tar")))
  696. {
  697. // ----- Error log
  698. if (!is_file($p_tarname))
  699. PclErrorLog(-4, "Archive '$p_tarname' does not exist");
  700. else
  701. PclErrorLog(-6, "Archive '$p_tarname' has invalid size ".filesize($p_tarname)."(not a 512 block multiple)");
  702. // ----- Return
  703. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  704. return PclErrorCode();
  705. }
  706. if ((!is_file($p_tarname_add)) ||
  707. (((($v_size_add = filesize($p_tarname_add)) % 512) != 0) && ($p_mode_add=="tar")))
  708. {
  709. // ----- Error log
  710. if (!is_file($p_tarname_add))
  711. PclErrorLog(-4, "Archive '$p_tarname_add' does not exist");
  712. else
  713. PclErrorLog(-6, "Archive '$p_tarname_add' has invalid size ".filesize($p_tarname_add)."(not a 512 block multiple)");
  714. // ----- Return
  715. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  716. return PclErrorCode();
  717. }
  718. // ----- Look for compressed archive
  719. if ($p_mode == "tgz")
  720. {
  721. // ----- Open the file in read mode
  722. if (($p_tar = @gzopen($p_tarname, "rb")) == 0)
  723. {
  724. // ----- Error log
  725. PclErrorLog(-2, "Unable to open file '$p_tarname' in binary read mode");
  726. // ----- Return
  727. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  728. return PclErrorCode();
  729. }
  730. // ----- Open a temporary file in write mode
  731. $v_temp_tarname = uniqid("pcltar-").".tmp";
  732. TrFctMessage(__FILE__, __LINE__, 2, "Creating temporary archive file $v_temp_tarname");
  733. if (($v_temp_tar = @gzopen($v_temp_tarname, "wb")) == 0)
  734. {
  735. // ----- Close tar file
  736. gzclose($p_tar);
  737. // ----- Error log
  738. PclErrorLog(-1, "Unable to open file '$v_temp_tarname' in binary write mode");
  739. // ----- Return
  740. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  741. return PclErrorCode();
  742. }
  743. // ----- Read the first 512 bytes block
  744. $v_buffer = gzread($p_tar, 512);
  745. // ----- Read the following blocks but not the last one
  746. if (!gzeof($p_tar))
  747. {
  748. TrFctMessage(__FILE__, __LINE__, 3, "More than one 512 block file");
  749. $i=1;
  750. // ----- Read new 512 block and write the already read
  751. do{
  752. // ----- Write the already read block
  753. $v_binary_data = pack("a512", "$v_buffer");
  754. gzputs($v_temp_tar, $v_binary_data);
  755. $i++;
  756. TrFctMessage(__FILE__, __LINE__, 3, "Reading block $i");
  757. // ----- Read next block
  758. $v_buffer = gzread($p_tar, 512);
  759. } while (!gzeof($p_tar));
  760. TrFctMessage(__FILE__, __LINE__, 3, "$i 512 bytes blocks");
  761. }
  762. }
  763. // ----- Look for uncompressed tar file
  764. else if ($p_mode=="tar")
  765. {
  766. // ----- Open the tar file
  767. if (($p_tar = fopen($p_tarname, "r+b")) == 0)
  768. {
  769. // ----- Error log
  770. PclErrorLog(-1, "Unable to open file '$p_tarname' in binary write mode");
  771. // ----- Return
  772. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  773. return PclErrorCode();
  774. }
  775. // ----- Go to the beginning of last block
  776. TrFctMessage(__FILE__, __LINE__, 4, "Position before :".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
  777. fseek($p_tar, $v_size-512);
  778. TrFctMessage(__FILE__, __LINE__, 4, "Position after :".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
  779. }
  780. // ----- Look for unknown type
  781. else
  782. {
  783. // ----- Error log
  784. PclErrorLog(-3, "Invalid tar mode $p_mode");
  785. // ----- Return
  786. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  787. return PclErrorCode();
  788. }
  789. // ----- Look for type of archive to add
  790. if ($p_mode_add == "tgz")
  791. {
  792. TrFctMessage(__FILE__, __LINE__, 4, "Opening file $p_tarname_add");
  793. // ----- Open the file in read mode
  794. if (($p_tar_add = @gzopen($p_tarname_add, "rb")) == 0)
  795. {
  796. // ----- Error log
  797. PclErrorLog(-2, "Unable to open file '$p_tarname_add' in binary read mode");
  798. // ----- Return
  799. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  800. return PclErrorCode();
  801. }
  802. // ----- Read the first 512 bytes block
  803. $v_buffer = gzread($p_tar_add, 512);
  804. // ----- Read the following blocks but not the last one
  805. if (!gzeof($p_tar_add))
  806. {
  807. TrFctMessage(__FILE__, __LINE__, 3, "More than one 512 block file");
  808. $i=1;
  809. // ----- Read new 512 block and write the already read
  810. do{
  811. // ----- Write the already read block
  812. $v_binary_data = pack("a512", "$v_buffer");
  813. if ($p_mode=="tar")
  814. fputs($p_tar, $v_binary_data);
  815. else
  816. gzputs($v_temp_tar, $v_binary_data);
  817. $i++;
  818. TrFctMessage(__FILE__, __LINE__, 3, "Reading block $i");
  819. // ----- Read next block
  820. $v_buffer = gzread($p_tar_add, 512);
  821. } while (!gzeof($p_tar_add));
  822. TrFctMessage(__FILE__, __LINE__, 3, "$i 512 bytes blocks");
  823. }
  824. // ----- Close the files
  825. gzclose($p_tar_add);
  826. }
  827. // ----- Look for uncompressed tar file
  828. else if ($p_mode=="tar")
  829. {
  830. // ----- Open the file in read mode
  831. if (($p_tar_add = @fopen($p_tarname_add, "rb")) == 0)
  832. {
  833. // ----- Error log
  834. PclErrorLog(-2, "Unable to open file '$p_tarname_add' in binary read mode");
  835. // ----- Return
  836. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  837. return PclErrorCode();
  838. }
  839. // ----- Read the first 512 bytes block
  840. $v_buffer = fread($p_tar_add, 512);
  841. // ----- Read the following blocks but not the last one
  842. if (!feof($p_tar_add))
  843. {
  844. TrFctMessage(__FILE__, __LINE__, 3, "More than one 512 block file");
  845. $i=1;
  846. // ----- Read new 512 block and write the already read
  847. do{
  848. // ----- Write the already read block
  849. $v_binary_data = pack("a512", "$v_buffer");
  850. if ($p_mode=="tar")
  851. fputs($p_tar, $v_binary_data);
  852. else
  853. gzputs($v_temp_tar, $v_binary_data);
  854. $i++;
  855. TrFctMessage(__FILE__, __LINE__, 3, "Reading block $i");
  856. // ----- Read next block
  857. $v_buffer = fread($p_tar_add, 512);
  858. } while (!feof($p_tar_add));
  859. TrFctMessage(__FILE__, __LINE__, 3, "$i 512 bytes blocks");
  860. }
  861. // ----- Close the files
  862. fclose($p_tar_add);
  863. }
  864. // ----- Call the footer of the tar archive
  865. $v_result = PclTarHandleFooter($p_tar, $p_mode);
  866. // ----- Look for closing compressed archive
  867. if ($p_mode == "tgz")
  868. {
  869. // ----- Close the files
  870. gzclose($p_tar);
  871. gzclose($v_temp_tar);
  872. // ----- Unlink tar file
  873. if (!@unlink($p_tarname))
  874. {
  875. // ----- Error log
  876. PclErrorLog(-11, "Error while deleting archive name $p_tarname");
  877. }
  878. // ----- Rename tar file
  879. if (!@rename($v_temp_tarname, $p_tarname))
  880. {
  881. // ----- Error log
  882. PclErrorLog(-12, "Error while renaming temporary file $v_temp_tarname to archive name $p_tarname");
  883. // ----- Return
  884. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  885. return PclErrorCode();
  886. }
  887. // ----- Return
  888. TrFctEnd(__FILE__, __LINE__, $v_result);
  889. return $v_result;
  890. }
  891. // ----- Look for closing uncompressed tar file
  892. else if ($p_mode=="tar")
  893. {
  894. // ----- Close the tarfile
  895. fclose($p_tar);
  896. }
  897. // ----- Return
  898. TrFctEnd(__FILE__, __LINE__, $v_result);
  899. return $v_result;
  900. }
  901. // --------------------------------------------------------------------------------
  902. // --------------------------------------------------------------------------------
  903. // ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****
  904. // ***** *****
  905. // ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY *****
  906. // --------------------------------------------------------------------------------
  907. // --------------------------------------------------------------------------------
  908. // Function : PclTarHandleCreate()
  909. // Description :
  910. // Parameters :
  911. // $p_tarname : Name of the tar file
  912. // $p_list : An array containing the file or directory names to add in the tar
  913. // $p_mode : "tar" for normal tar archive, "tgz" for gzipped tar archive
  914. // Return Values :
  915. // --------------------------------------------------------------------------------
  916. function PclTarHandleCreate($p_tarname, $p_list, $p_mode, $p_add_dir="", $p_remove_dir="")
  917. {
  918. TrFctStart(__FILE__, __LINE__, "PclTarHandleCreate", "tar=$p_tarname, list, mode=$p_mode, add_dir='$p_add_dir', remove_dir='$p_remove_dir'");
  919. $v_result=1;
  920. $v_list_detail = array();
  921. // ----- Check the parameters
  922. if (($p_tarname == "") || (($p_mode != "tar") && ($p_mode != "tgz")))
  923. {
  924. // ----- Error log
  925. if ($p_tarname == "")
  926. PclErrorLog(-3, "Invalid empty archive name");
  927. else
  928. PclErrorLog(-3, "Unknown mode '$p_mode'");
  929. // ----- Return
  930. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  931. return PclErrorCode();
  932. }
  933. // ----- Look for tar file
  934. if ($p_mode == "tar")
  935. {
  936. // ----- Open the tar file
  937. if (($p_tar = fopen($p_tarname, "wb")) == 0)
  938. {
  939. // ----- Error log
  940. PclErrorLog(-1, "Unable to open file [$p_tarname] in binary write mode");
  941. // ----- Return
  942. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  943. return PclErrorCode();
  944. }
  945. // ----- Call the adding fct inside the tar
  946. if (($v_result = PclTarHandleAddList($p_tar, $p_list, $p_mode, $v_list_detail, $p_add_dir, $p_remove_dir)) == 1)
  947. {
  948. // ----- Call the footer of the tar archive
  949. $v_result = PclTarHandleFooter($p_tar, $p_mode);
  950. }
  951. // ----- Close the tarfile
  952. fclose($p_tar);
  953. }
  954. // ----- Look for tgz file
  955. else
  956. {
  957. // ----- Open the tar file
  958. if (($p_tar = @gzopen($p_tarname, "wb")) == 0)
  959. {
  960. // ----- Error log
  961. PclErrorLog(-1, "Unable to open file [$p_tarname] in binary write mode");
  962. // ----- Return
  963. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  964. return PclErrorCode();
  965. }
  966. // ----- Call the adding fct inside the tar
  967. if (($v_result = PclTarHandleAddList($p_tar, $p_list, $p_mode, $v_list_detail, $p_add_dir, $p_remove_dir)) == 1)
  968. {
  969. // ----- Call the footer of the tar archive
  970. $v_result = PclTarHandleFooter($p_tar, $p_mode);
  971. }
  972. // ----- Close the tarfile
  973. gzclose($p_tar);
  974. }
  975. // ----- Return
  976. TrFctEnd(__FILE__, __LINE__, $v_result);
  977. return $v_result;
  978. }
  979. // --------------------------------------------------------------------------------
  980. // --------------------------------------------------------------------------------
  981. // Function : PclTarHandleAppend()
  982. // Description :
  983. // Parameters :
  984. // $p_tarname : Name of the tar file
  985. // $p_list : An array containing the file or directory names to add in the tar
  986. // $p_mode : "tar" for normal tar archive, "tgz" for gzipped tar archive
  987. // Return Values :
  988. // --------------------------------------------------------------------------------
  989. function PclTarHandleAppend($p_tarname, $p_list, $p_mode, &$p_list_detail, $p_add_dir, $p_remove_dir)
  990. {
  991. TrFctStart(__FILE__, __LINE__, "PclTarHandleAppend", "tar=$p_tarname, list, mode=$p_mode");
  992. $v_result=1;
  993. // ----- Check the parameters
  994. if ($p_tarname == "")
  995. {
  996. // ----- Error log
  997. PclErrorLog(-3, "Invalid empty archive name");
  998. // ----- Return
  999. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  1000. return PclErrorCode();
  1001. }
  1002. clearstatcache();
  1003. // ----- Check the file size
  1004. if ((!is_file($p_tarname)) ||
  1005. (((($v_size = filesize($p_tarname)) % 512) != 0) && ($p_mode=="tar")))
  1006. {
  1007. // ----- Error log
  1008. if (!is_file($p_tarname))
  1009. PclErrorLog(-4, "Archive '$p_tarname' does not exist");
  1010. else
  1011. PclErrorLog(-6, "Archive '$p_tarname' has invalid size ".filesize($p_tarname)."(not a 512 block multiple)");
  1012. // ----- Return
  1013. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  1014. return PclErrorCode();
  1015. }
  1016. // ----- Look for compressed archive
  1017. if ($p_mode == "tgz")
  1018. {
  1019. // ----- Open the file in read mode
  1020. if (($p_tar = @gzopen($p_tarname, "rb")) == 0)
  1021. {
  1022. // ----- Error log
  1023. PclErrorLog(-2, "Unable to open file '$p_tarname' in binary read mode");
  1024. // ----- Return
  1025. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  1026. return PclErrorCode();
  1027. }
  1028. // ----- Open a temporary file in write mode
  1029. $v_temp_tarname = uniqid("pcltar-").".tmp";
  1030. TrFctMessage(__FILE__, __LINE__, 2, "Creating temporary archive file $v_temp_tarname");
  1031. if (($v_temp_tar = @gzopen($v_temp_tarname, "wb")) == 0)
  1032. {
  1033. // ----- Close tar file
  1034. gzclose($p_tar);
  1035. // ----- Error log
  1036. PclErrorLog(-1, "Unable to open file '$v_temp_tarname' in binary write mode");
  1037. // ----- Return
  1038. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  1039. return PclErrorCode();
  1040. }
  1041. // ----- Read the first 512 bytes block
  1042. $v_buffer = gzread($p_tar, 512);
  1043. // ----- Read the following blocks but not the last one
  1044. if (!gzeof($p_tar))
  1045. {
  1046. TrFctMessage(__FILE__, __LINE__, 3, "More than one 512 block file");
  1047. $i=1;
  1048. // ----- Read new 512 block and write the already read
  1049. do{
  1050. // ----- Write the already read block
  1051. $v_binary_data = pack("a512", "$v_buffer");
  1052. gzputs($v_temp_tar, $v_binary_data);
  1053. $i++;
  1054. TrFctMessage(__FILE__, __LINE__, 3, "Reading block $i");
  1055. // ----- Read next block
  1056. $v_buffer = gzread($p_tar, 512);
  1057. } while (!gzeof($p_tar));
  1058. TrFctMessage(__FILE__, __LINE__, 3, "$i 512 bytes blocks");
  1059. }
  1060. // ----- Call the adding fct inside the tar
  1061. if (($v_result = PclTarHandleAddList($v_temp_tar, $p_list, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir)) == 1)
  1062. {
  1063. // ----- Call the footer of the tar archive
  1064. $v_result = PclTarHandleFooter($v_temp_tar, $p_mode);
  1065. }
  1066. // ----- Close the files
  1067. gzclose($p_tar);
  1068. gzclose($v_temp_tar);
  1069. // ----- Unlink tar file
  1070. if (!@unlink($p_tarname))
  1071. {
  1072. // ----- Error log
  1073. PclErrorLog(-11, "Error while deleting archive name $p_tarname");
  1074. }
  1075. // ----- Rename tar file
  1076. if (!@rename($v_temp_tarname, $p_tarname))
  1077. {
  1078. // ----- Error log
  1079. PclErrorLog(-12, "Error while renaming temporary file $v_temp_tarname to archive name $p_tarname");
  1080. // ----- Return
  1081. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  1082. return PclErrorCode();
  1083. }
  1084. // ----- Return
  1085. TrFctEnd(__FILE__, __LINE__, $v_result);
  1086. return $v_result;
  1087. }
  1088. // ----- Look for uncompressed tar file
  1089. else if ($p_mode=="tar")
  1090. {
  1091. // ----- Open the tar file
  1092. if (($p_tar = fopen($p_tarname, "r+b")) == 0)
  1093. {
  1094. // ----- Error log
  1095. PclErrorLog(-1, "Unable to open file '$p_tarname' in binary write mode");
  1096. // ----- Return
  1097. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  1098. return PclErrorCode();
  1099. }
  1100. // ----- Go to the beginning of last block
  1101. TrFctMessage(__FILE__, __LINE__, 4, "Position before :".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
  1102. fseek($p_tar, $v_size-512);
  1103. TrFctMessage(__FILE__, __LINE__, 4, "Position after :".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
  1104. // ----- Call the adding fct inside the tar
  1105. if (($v_result = PclTarHandleAddList($p_tar, $p_list, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir)) == 1)
  1106. {
  1107. // ----- Call the footer of the tar archive
  1108. $v_result = PclTarHandleFooter($p_tar, $p_mode);
  1109. }
  1110. // ----- Close the tarfile
  1111. fclose($p_tar);
  1112. }
  1113. // ----- Look for unknown type
  1114. else
  1115. {
  1116. // ----- Error log
  1117. PclErrorLog(-3, "Invalid tar mode $p_mode");
  1118. // ----- Return
  1119. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  1120. return PclErrorCode();
  1121. }
  1122. // ----- Return
  1123. TrFctEnd(__FILE__, __LINE__, $v_result);
  1124. return $v_result;
  1125. }
  1126. // --------------------------------------------------------------------------------
  1127. // --------------------------------------------------------------------------------
  1128. // Function : PclTarHandleAddList()
  1129. // Description :
  1130. // $p_add_dir and $p_remove_dir will give the ability to memorize a path which is
  1131. // different from the real path of the file. This is usefull if you want to have PclTar
  1132. // running in any directory, and memorize relative path from an other directory.
  1133. // Parameters :
  1134. // $p_tar : File descriptor of the tar archive
  1135. // $p_list : An array containing the file or directory names to add in the tar
  1136. // $p_mode : "tar" for normal tar archive, "tgz" for gzipped tar archive
  1137. // $p_list_detail : list of added files with their properties (specially the status field)
  1138. // $p_add_dir : Path to add in the filename path archived
  1139. // $p_remove_dir : Path to remove in the filename path archived
  1140. // Return Values :
  1141. // --------------------------------------------------------------------------------
  1142. function PclTarHandleAddList($p_tar, $p_list, $p_mode, &$p_list_detail, $p_add_dir, $p_remove_dir)
  1143. {
  1144. TrFctStart(__FILE__, __LINE__, "PclTarHandleAddList", "tar='$p_tar', list, mode='$p_mode', add_dir='$p_add_dir', remove_dir='$p_remove_dir'");
  1145. $v_result=1;
  1146. $v_header = array();
  1147. // ----- Recuperate the current number of elt in list
  1148. $v_nb = sizeof($p_list_detail);
  1149. // ----- Check the parameters
  1150. if ($p_tar == 0)
  1151. {
  1152. // ----- Error log
  1153. PclErrorLog(-3, "Invalid file descriptor in file ".__FILE__.", line ".__LINE__);
  1154. // ----- Return
  1155. TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
  1156. re

Large files files are truncated, but you can click here to view the full file