You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

547 lines
22 KiB

  1. /* Copyright (c) 2011, SmartFile <btimby@smartfile.com>
  2. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions are met:
  5. * Redistributions of source code must retain the above copyright
  6. notice, this list of conditions and the following disclaimer.
  7. * Redistributions in binary form must reproduce the above copyright
  8. notice, this list of conditions and the following disclaimer in the
  9. documentation and/or other materials provided with the distribution.
  10. * Neither the name of the organization nor the
  11. names of its contributors may be used to endorse or promote products
  12. derived from this software without specific prior written permission.
  13. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  14. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
  17. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  18. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  20. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
  23. %module _libarchive
  24. %{
  25. #include <archive.h>
  26. #include <archive_entry.h>
  27. %}
  28. %include "typemaps.i"
  29. %typemap(in) time_t
  30. {
  31. if (PyLong_Check($input))
  32. $1 = (time_t) PyLong_AsLong($input);
  33. else if (PyInt_Check($input))
  34. $1 = (time_t) PyInt_AsLong($input);
  35. else if (PyFloat_Check($input))
  36. $1 = (time_t) PyFloat_AsDouble($input);
  37. else {
  38. PyErr_SetString(PyExc_TypeError,"Expected a large number");
  39. return NULL;
  40. }
  41. }
  42. %typemap(out) time_t
  43. {
  44. $result = PyLong_FromLong((long)$1);
  45. }
  46. %typemap(in) int64_t
  47. {
  48. if (PyLong_Check($input))
  49. $1 = (int64_t) PyLong_AsLong($input);
  50. else if (PyInt_Check($input))
  51. $1 = (int64_t) PyInt_AsLong($input);
  52. else if (PyFloat_Check($input))
  53. $1 = (int64_t) PyFloat_AsDouble($input);
  54. else {
  55. PyErr_SetString(PyExc_TypeError,"Expected a large number");
  56. return NULL;
  57. }
  58. }
  59. %typemap(out) int64_t
  60. {
  61. $result = PyLong_FromLong((long)$1);
  62. }
  63. typedef unsigned short mode_t;
  64. /* CONFIGURATION */
  65. #include <sys/types.h>
  66. #include <stddef.h> /* for wchar_t */
  67. #include <time.h>
  68. #if defined(_WIN32) && !defined(__CYGWIN__)
  69. #include <windows.h>
  70. #endif
  71. /* Get appropriate definitions of standard POSIX-style types. */
  72. /* These should match the types used in 'struct stat' */
  73. #if defined(_WIN32) && !defined(__CYGWIN__)
  74. #define __LA_INT64_T __int64
  75. # if defined(__BORLANDC__)
  76. # define __LA_UID_T uid_t /* Remove in libarchive 3.2 */
  77. # define __LA_GID_T gid_t /* Remove in libarchive 3.2 */
  78. # define __LA_DEV_T dev_t
  79. # define __LA_MODE_T mode_t
  80. # else
  81. # define __LA_UID_T short /* Remove in libarchive 3.2 */
  82. # define __LA_GID_T short /* Remove in libarchive 3.2 */
  83. # define __LA_DEV_T unsigned int
  84. # define __LA_MODE_T unsigned short
  85. # endif
  86. #else
  87. #include <unistd.h>
  88. # if defined(_SCO_DS)
  89. # define __LA_INT64_T long long
  90. # else
  91. # define __LA_INT64_T int64_t
  92. # endif
  93. # define __LA_UID_T uid_t /* Remove in libarchive 3.2 */
  94. # define __LA_GID_T gid_t /* Remove in libarchive 3.2 */
  95. # define __LA_DEV_T dev_t
  96. # define __LA_MODE_T mode_t
  97. #endif
  98. /*
  99. * Remove this for libarchive 3.2, since ino_t is no longer used.
  100. */
  101. #define __LA_INO_T ino_t
  102. /*
  103. * On Windows, define LIBARCHIVE_STATIC if you're building or using a
  104. * .lib. The default here assumes you're building a DLL. Only
  105. * libarchive source should ever define __LIBARCHIVE_BUILD.
  106. */
  107. #if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC)
  108. # ifdef __LIBARCHIVE_BUILD
  109. # ifdef __GNUC__
  110. # define extern __attribute__((dllexport)) extern
  111. # else
  112. # define extern __declspec(dllexport)
  113. # endif
  114. # else
  115. # ifdef __GNUC__
  116. # define extern
  117. # else
  118. # define extern __declspec(dllimport)
  119. # endif
  120. # endif
  121. #else
  122. /* Static libraries on all platforms and shared libraries on non-Windows. */
  123. # define extern
  124. #endif
  125. /* STRUCTURES */
  126. struct archive;
  127. struct archive_entry;
  128. /* ARCHIVE READING */
  129. extern struct archive *archive_read_new(void);
  130. extern int archive_read_free(struct archive *);
  131. /* opening */
  132. extern int archive_read_open_filename(struct archive *,
  133. const char *_filename, size_t _block_size);
  134. extern int archive_read_open_memory(struct archive *,
  135. const void * buff, size_t size);
  136. extern int archive_read_open_memory2(struct archive *a, void const *buff,
  137. size_t size, size_t read_size);
  138. extern int archive_read_open_fd(struct archive *, int _fd,
  139. size_t _block_size);
  140. /* closing */
  141. extern int archive_read_close(struct archive *);
  142. extern int archive_format(struct archive *);
  143. /* headers */
  144. extern int archive_read_next_header2(struct archive *,
  145. struct archive_entry *);
  146. extern const struct stat *archive_entry_stat(struct archive_entry *);
  147. extern __LA_INT64_T archive_read_header_position(struct archive *);
  148. /*
  149. * Set read options.
  150. */
  151. /* Apply option to the format only. */
  152. extern int archive_read_set_format_option(struct archive *_a,
  153. const char *m, const char *o,
  154. const char *v);
  155. /* Apply option to the filter only. */
  156. extern int archive_read_set_filter_option(struct archive *_a,
  157. const char *m, const char *o,
  158. const char *v);
  159. /* Apply option to both the format and the filter. */
  160. extern int archive_read_set_option(struct archive *_a,
  161. const char *m, const char *o,
  162. const char *v);
  163. /* Apply option string to both the format and the filter. */
  164. extern int archive_read_set_options(struct archive *_a,
  165. const char *opts);
  166. /*
  167. * Add a decryption passphrase.
  168. */
  169. extern int archive_read_add_passphrase(struct archive *, const char *);
  170. /* data */
  171. extern int archive_read_data_skip(struct archive *);
  172. extern int archive_read_data_into_fd(struct archive *, int fd);
  173. #if ARCHIVE_VERSION_NUMBER < 4000000
  174. extern int archive_read_support_compression_all(struct archive *);
  175. extern int archive_read_support_compression_bzip2(struct archive *);
  176. extern int archive_read_support_compression_compress(struct archive *);
  177. extern int archive_read_support_compression_gzip(struct archive *);
  178. extern int archive_read_support_compression_lzip(struct archive *);
  179. extern int archive_read_support_compression_lzma(struct archive *);
  180. extern int archive_read_support_compression_none(struct archive *);
  181. extern int archive_read_support_compression_program(struct archive *, const char *command);
  182. extern int archive_read_support_compression_program_signature
  183. (struct archive *, const char *,
  184. const void * /* match */, size_t);
  185. extern int archive_read_support_compression_rpm(struct archive *);
  186. extern int archive_read_support_compression_uu(struct archive *);
  187. extern int archive_read_support_compression_xz(struct archive *);
  188. #endif
  189. extern int archive_read_support_filter_all(struct archive *);
  190. extern int archive_read_support_filter_bzip2(struct archive *);
  191. extern int archive_read_support_filter_compress(struct archive *);
  192. extern int archive_read_support_filter_gzip(struct archive *);
  193. extern int archive_read_support_filter_grzip(struct archive *);
  194. extern int archive_read_support_filter_lrzip(struct archive *);
  195. extern int archive_read_support_filter_lz4(struct archive *);
  196. extern int archive_read_support_filter_lzip(struct archive *);
  197. extern int archive_read_support_filter_lzma(struct archive *);
  198. extern int archive_read_support_filter_lzop(struct archive *);
  199. extern int archive_read_support_filter_none(struct archive *);
  200. extern int archive_read_support_filter_program(struct archive *,
  201. const char *command);
  202. extern int archive_read_support_filter_program_signature
  203. (struct archive *, const char * /* cmd */,
  204. const void * /* match */, size_t);
  205. extern int archive_read_support_filter_rpm(struct archive *);
  206. extern int archive_read_support_filter_uu(struct archive *);
  207. extern int archive_read_support_filter_xz(struct archive *);
  208. extern int archive_read_support_format_7zip(struct archive *);
  209. extern int archive_read_support_format_all(struct archive *);
  210. extern int archive_read_support_format_ar(struct archive *);
  211. extern int archive_read_support_format_by_code(struct archive *, int);
  212. extern int archive_read_support_format_cab(struct archive *);
  213. extern int archive_read_support_format_cpio(struct archive *);
  214. extern int archive_read_support_format_empty(struct archive *);
  215. extern int archive_read_support_format_gnutar(struct archive *);
  216. extern int archive_read_support_format_iso9660(struct archive *);
  217. extern int archive_read_support_format_lha(struct archive *);
  218. /* extern int archive_read_support_format_mtree(struct archive *); */
  219. extern int archive_read_support_format_rar(struct archive *);
  220. extern int archive_read_support_format_raw(struct archive *);
  221. extern int archive_read_support_format_tar(struct archive *);
  222. extern int archive_read_support_format_warc(struct archive *);
  223. extern int archive_read_support_format_xar(struct archive *);
  224. /* archive_read_support_format_zip() enables both streamable and seekable
  225. * zip readers. */
  226. extern int archive_read_support_format_zip(struct archive *);
  227. /* Reads Zip archives as stream from beginning to end. Doesn't
  228. * correctly handle SFX ZIP files or ZIP archives that have been modified
  229. * in-place. */
  230. extern int archive_read_support_format_zip_streamable(struct archive *);
  231. /* Reads starting from central directory; requires seekable input. */
  232. extern int archive_read_support_format_zip_seekable(struct archive *);
  233. /* Functions to manually set the format and filters to be used. This is
  234. * useful to bypass the bidding process when the format and filters to use
  235. * is known in advance.
  236. */
  237. extern int archive_read_set_format(struct archive *, int);
  238. extern int archive_read_append_filter(struct archive *, int);
  239. extern int archive_read_append_filter_program(struct archive *,
  240. const char *);
  241. extern int archive_read_append_filter_program_signature
  242. (struct archive *, const char *, const void * /* match */, size_t);
  243. /* ARCHIVE WRITING */
  244. extern struct archive *archive_write_new(void);
  245. extern int archive_write_free(struct archive *);
  246. /* opening */
  247. extern int archive_write_open(struct archive *, void *,
  248. archive_open_callback *, archive_write_callback *,
  249. archive_close_callback *);
  250. extern int archive_write_open_fd(struct archive *, int _fd);
  251. extern int archive_write_open_filename(struct archive *, const char *_file);
  252. extern int archive_write_open_filename_w(struct archive *,
  253. const wchar_t *_file);
  254. extern int archive_write_open_memory(struct archive *,
  255. void *_buffer, size_t _buffSize, size_t *_used);
  256. /* closing */
  257. extern int archive_write_close(struct archive *);
  258. /* headers */
  259. extern int archive_write_header(struct archive *,
  260. struct archive_entry *);
  261. extern int archive_write_set_format_option(struct archive *_a,
  262. const char *m, const char *o,
  263. const char *v);
  264. /* Apply option to the filter only. */
  265. extern int archive_write_set_filter_option(struct archive *_a,
  266. const char *m, const char *o,
  267. const char *v);
  268. /* Apply option to both the format and the filter. */
  269. extern int archive_write_set_option(struct archive *_a,
  270. const char *m, const char *o,
  271. const char *v);
  272. /* Apply option string to both the format and the filter. */
  273. extern int archive_write_set_options(struct archive *_a,
  274. const char *opts);
  275. /* password */
  276. extern int archive_write_set_passphrase(struct archive *_a, const char *p);
  277. /* data */
  278. /* commit */
  279. extern int archive_write_finish_entry(struct archive *);
  280. /* FILTERS */
  281. extern int archive_write_add_filter(struct archive *, int filter_code);
  282. extern int archive_write_add_filter_by_name(struct archive *,
  283. const char *name);
  284. extern int archive_write_add_filter_b64encode(struct archive *);
  285. extern int archive_write_add_filter_bzip2(struct archive *);
  286. extern int archive_write_add_filter_compress(struct archive *);
  287. extern int archive_write_add_filter_grzip(struct archive *);
  288. extern int archive_write_add_filter_gzip(struct archive *);
  289. extern int archive_write_add_filter_lrzip(struct archive *);
  290. extern int archive_write_add_filter_lz4(struct archive *);
  291. extern int archive_write_add_filter_lzip(struct archive *);
  292. extern int archive_write_add_filter_lzma(struct archive *);
  293. extern int archive_write_add_filter_lzop(struct archive *);
  294. extern int archive_write_add_filter_none(struct archive *);
  295. extern int archive_write_add_filter_program(struct archive *,
  296. const char *cmd);
  297. extern int archive_write_add_filter_uuencode(struct archive *);
  298. extern int archive_write_add_filter_xz(struct archive *);
  299. /* A convenience function to set the format based on the code or name. */
  300. extern int archive_write_set_format(struct archive *, int format_code);
  301. extern int archive_write_set_format_by_name(struct archive *,
  302. const char *name);
  303. /* To minimize link pollution, use one or more of the following. */
  304. extern int archive_write_set_format_7zip(struct archive *);
  305. extern int archive_write_set_format_ar_bsd(struct archive *);
  306. extern int archive_write_set_format_ar_svr4(struct archive *);
  307. extern int archive_write_set_format_cpio(struct archive *);
  308. extern int archive_write_set_format_cpio_newc(struct archive *);
  309. extern int archive_write_set_format_gnutar(struct archive *);
  310. extern int archive_write_set_format_iso9660(struct archive *);
  311. extern int archive_write_set_format_mtree(struct archive *);
  312. extern int archive_write_set_format_mtree_classic(struct archive *);
  313. /* TODO: int archive_write_set_format_old_tar(struct archive *); */
  314. extern int archive_write_set_format_pax(struct archive *);
  315. extern int archive_write_set_format_pax_restricted(struct archive *);
  316. extern int archive_write_set_format_raw(struct archive *);
  317. extern int archive_write_set_format_shar(struct archive *);
  318. extern int archive_write_set_format_shar_dump(struct archive *);
  319. extern int archive_write_set_format_ustar(struct archive *);
  320. extern int archive_write_set_format_v7tar(struct archive *);
  321. extern int archive_write_set_format_warc(struct archive *);
  322. extern int archive_write_set_format_xar(struct archive *);
  323. extern int archive_write_set_format_zip(struct archive *);
  324. extern int archive_write_set_format_filter_by_ext(struct archive *a, const char *filename);
  325. extern int archive_write_set_format_filter_by_ext_def(struct archive *a, const char *filename, const char * def_ext);
  326. extern int archive_write_zip_set_compression_deflate(struct archive *);
  327. extern int archive_write_zip_set_compression_store(struct archive *);
  328. /* ARCHIVE ENTRY */
  329. extern struct archive_entry *archive_entry_new(void);
  330. extern void archive_entry_free(struct archive_entry *);
  331. /* ARCHIVE ENTRY PROPERTY ACCESS */
  332. /* reading */
  333. extern const char *archive_entry_pathname(struct archive_entry *);
  334. extern const wchar_t *archive_entry_pathname_w(struct archive_entry *);
  335. extern __LA_INT64_T archive_entry_size(struct archive_entry *);
  336. extern time_t archive_entry_mtime(struct archive_entry *);
  337. extern __LA_MODE_T archive_entry_filetype(struct archive_entry *);
  338. extern __LA_MODE_T archive_entry_perm(struct archive_entry *);
  339. extern const char *archive_entry_symlink(struct archive_entry *);
  340. //extern const char *archive_entry_symlink_utf8(struct archive_entry *);
  341. extern void archive_entry_set_link(struct archive_entry *, const char *);
  342. //extern void archive_entry_set_link_utf8(struct archive_entry *, const char *);
  343. //extern int archive_entry_symlink_type(struct archive_entry *);
  344. extern const wchar_t *archive_entry_symlink_w(struct archive_entry *);
  345. //extern void archive_entry_copy_link(struct archive_entry *, const char *);
  346. //extern void archive_entry_copy_link_w(struct archive_entry *, const wchar_t *);
  347. /* The names for symlink modes here correspond to an old BSD
  348. * command-line argument convention: -L, -P, -H */
  349. /* Follow all symlinks. */
  350. extern int archive_read_disk_set_symlink_logical(struct archive *);
  351. /* Follow no symlinks. */
  352. extern int archive_read_disk_set_symlink_physical(struct archive *);
  353. /* Follow symlink initially, then not. */
  354. extern int archive_read_disk_set_symlink_hybrid(struct archive *);
  355. extern void archive_entry_set_symlink(struct archive_entry *, const char *);
  356. //extern void archive_entry_set_symlink_type(struct archive_entry *, int);
  357. //extern void archive_entry_set_symlink_utf8(struct archive_entry *, const char *);
  358. extern void archive_entry_copy_symlink(struct archive_entry *, const char *);
  359. extern void archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *);
  360. //extern int archive_entry_update_symlink_utf8(struct archive_entry *, const char *);
  361. /* writing */
  362. extern void archive_entry_set_pathname(struct archive_entry *, const char *);
  363. extern void archive_entry_set_size(struct archive_entry *, __LA_INT64_T);
  364. extern void archive_entry_set_mtime(struct archive_entry *, time_t, long);
  365. extern void archive_entry_set_filetype(struct archive_entry *, unsigned int);
  366. extern void archive_entry_set_perm(struct archive_entry *, __LA_MODE_T);
  367. //extern void archive_entry_set_link(struct archive_entry *, __LA_MODE_T);
  368. //extern void archive_entry_set_symlink(struct archive_entry *, __LA_MODE_T);
  369. /* ERROR HANDLING */
  370. extern int archive_errno(struct archive *);
  371. extern const char *archive_error_string(struct archive *);
  372. /* CONSTANTS */
  373. #define ARCHIVE_VERSION_NUMBER 3002002
  374. #define ARCHIVE_VERSION_STRING "libarchive 3.2.2"
  375. #define ARCHIVE_EOF 1 /* Found end of archive. */
  376. #define ARCHIVE_OK 0 /* Operation was successful. */
  377. #define ARCHIVE_RETRY (-10) /* Retry might succeed. */
  378. #define ARCHIVE_WARN (-20) /* Partial success. */
  379. #define ARCHIVE_FAILED (-25) /* Current operation cannot complete. */
  380. #define ARCHIVE_FATAL (-30) /* No more operations are possible. */
  381. #define ARCHIVE_FILTER_NONE 0
  382. #define ARCHIVE_FILTER_GZIP 1
  383. #define ARCHIVE_FILTER_BZIP2 2
  384. #define ARCHIVE_FILTER_COMPRESS 3
  385. #define ARCHIVE_FILTER_PROGRAM 4
  386. #define ARCHIVE_FILTER_LZMA 5
  387. #define ARCHIVE_FILTER_XZ 6
  388. #define ARCHIVE_FILTER_UU 7
  389. #define ARCHIVE_FILTER_RPM 8
  390. #define ARCHIVE_FILTER_LZIP 9
  391. #define ARCHIVE_FILTER_LRZIP 10
  392. #define ARCHIVE_FILTER_LZOP 11
  393. #define ARCHIVE_FILTER_GRZIP 12
  394. #define ARCHIVE_FILTER_LZ4 13
  395. #define ARCHIVE_FORMAT_BASE_MASK 0xff0000
  396. #define ARCHIVE_FORMAT_CPIO 0x10000
  397. #define ARCHIVE_FORMAT_CPIO_POSIX (ARCHIVE_FORMAT_CPIO | 1)
  398. #define ARCHIVE_FORMAT_CPIO_BIN_LE (ARCHIVE_FORMAT_CPIO | 2)
  399. #define ARCHIVE_FORMAT_CPIO_BIN_BE (ARCHIVE_FORMAT_CPIO | 3)
  400. #define ARCHIVE_FORMAT_CPIO_SVR4_NOCRC (ARCHIVE_FORMAT_CPIO | 4)
  401. #define ARCHIVE_FORMAT_CPIO_SVR4_CRC (ARCHIVE_FORMAT_CPIO | 5)
  402. #define ARCHIVE_FORMAT_CPIO_AFIO_LARGE (ARCHIVE_FORMAT_CPIO | 6)
  403. #define ARCHIVE_FORMAT_SHAR 0x20000
  404. #define ARCHIVE_FORMAT_SHAR_BASE (ARCHIVE_FORMAT_SHAR | 1)
  405. #define ARCHIVE_FORMAT_SHAR_DUMP (ARCHIVE_FORMAT_SHAR | 2)
  406. #define ARCHIVE_FORMAT_TAR 0x30000
  407. #define ARCHIVE_FORMAT_TAR_USTAR (ARCHIVE_FORMAT_TAR | 1)
  408. #define ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE (ARCHIVE_FORMAT_TAR | 2)
  409. #define ARCHIVE_FORMAT_TAR_PAX_RESTRICTED (ARCHIVE_FORMAT_TAR | 3)
  410. #define ARCHIVE_FORMAT_TAR_GNUTAR (ARCHIVE_FORMAT_TAR | 4)
  411. #define ARCHIVE_FORMAT_ISO9660 0x40000
  412. #define ARCHIVE_FORMAT_ISO9660_ROCKRIDGE (ARCHIVE_FORMAT_ISO9660 | 1)
  413. #define ARCHIVE_FORMAT_ZIP 0x50000
  414. #define ARCHIVE_FORMAT_EMPTY 0x60000
  415. #define ARCHIVE_FORMAT_AR 0x70000
  416. #define ARCHIVE_FORMAT_AR_GNU (ARCHIVE_FORMAT_AR | 1)
  417. #define ARCHIVE_FORMAT_AR_BSD (ARCHIVE_FORMAT_AR | 2)
  418. #define ARCHIVE_FORMAT_MTREE 0x80000
  419. #define ARCHIVE_FORMAT_RAW 0x90000
  420. #define ARCHIVE_FORMAT_XAR 0xA0000
  421. #define ARCHIVE_FORMAT_LHA 0xB0000
  422. #define ARCHIVE_FORMAT_CAB 0xC0000
  423. #define ARCHIVE_FORMAT_RAR 0xD0000
  424. #define ARCHIVE_FORMAT_7ZIP 0xE0000
  425. #define ARCHIVE_FORMAT_WARC 0xF0000
  426. /* Default: Do not try to set owner/group. */
  427. #define ARCHIVE_EXTRACT_OWNER (0x0001)
  428. /* Default: Do obey umask, do not restore SUID/SGID/SVTX bits. */
  429. #define ARCHIVE_EXTRACT_PERM (0x0002)
  430. /* Default: Do not restore mtime/atime. */
  431. #define ARCHIVE_EXTRACT_TIME (0x0004)
  432. /* Default: Replace existing files. */
  433. #define ARCHIVE_EXTRACT_NO_OVERWRITE (0x0008)
  434. /* Default: Try create first, unlink only if create fails with EEXIST. */
  435. #define ARCHIVE_EXTRACT_UNLINK (0x0010)
  436. /* Default: Do not restore ACLs. */
  437. #define ARCHIVE_EXTRACT_ACL (0x0020)
  438. /* Default: Do not restore fflags. */
  439. #define ARCHIVE_EXTRACT_FFLAGS (0x0040)
  440. /* Default: Do not restore xattrs. */
  441. #define ARCHIVE_EXTRACT_XATTR (0x0080)
  442. /* Default: Do not try to guard against extracts redirected by symlinks. */
  443. /* Note: With ARCHIVE_EXTRACT_UNLINK, will remove any intermediate symlink. */
  444. #define ARCHIVE_EXTRACT_SECURE_SYMLINKS (0x0100)
  445. /* Default: Do not reject entries with '..' as path elements. */
  446. #define ARCHIVE_EXTRACT_SECURE_NODOTDOT (0x0200)
  447. /* Default: Create parent directories as needed. */
  448. #define ARCHIVE_EXTRACT_NO_AUTODIR (0x0400)
  449. /* Default: Overwrite files, even if one on disk is newer. */
  450. #define ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER (0x0800)
  451. /* Detect blocks of 0 and write holes instead. */
  452. #define ARCHIVE_EXTRACT_SPARSE (0x1000)
  453. /* Default: Do not restore Mac extended metadata. */
  454. /* This has no effect except on Mac OS. */
  455. #define ARCHIVE_EXTRACT_MAC_METADATA (0x2000)
  456. /* Default: Use HFS+ compression if it was compressed. */
  457. /* This has no effect except on Mac OS v10.6 or later. */
  458. #define ARCHIVE_EXTRACT_NO_HFS_COMPRESSION (0x4000)
  459. /* Default: Do not use HFS+ compression if it was not compressed. */
  460. /* This has no effect except on Mac OS v10.6 or later. */
  461. #define ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED (0x8000)
  462. /* Default: Do not reject entries with absolute paths */
  463. #define ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS (0x10000)
  464. /* Default: Do not clear no-change flags when unlinking object */
  465. #define ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS (0x20000)
  466. %inline %{
  467. PyObject *archive_read_data_into_str(struct archive *archive, int len) {
  468. PyObject *str = NULL;
  469. if (!(str = PyBytes_FromStringAndSize(NULL, len))) {
  470. PyErr_SetString(PyExc_MemoryError, "could not allocate string.");
  471. return NULL;
  472. }
  473. if (len != archive_read_data(archive, PyBytes_AS_STRING(str), len)) {
  474. PyErr_SetString(PyExc_RuntimeError, "could not read requested data.");
  475. return NULL;
  476. }
  477. return str;
  478. }
  479. PyObject *archive_write_data_from_str(struct archive *archive, PyObject *str) {
  480. Py_ssize_t len = PyBytes_Size(str);
  481. if (!archive_write_data(archive, PyBytes_AS_STRING(str), len)) {
  482. PyErr_SetString(PyExc_RuntimeError, "could not write requested data.");
  483. return NULL;
  484. }
  485. return PyInt_FromLong(len);
  486. }
  487. %}