@papyrus-sdk/engine-native 0.2.22-beta.1 → 0.2.22-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +1 -0
- package/android/src/main/cpp/CMakeLists.txt +137 -0
- package/android/src/main/cpp/PapyrusComicArchiveJni.cpp +68 -0
- package/android/src/main/cpp/PapyrusComicArchiveTest.cpp +55 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusComicArchiveNative.java +14 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentView.java +353 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentViewManager.java +32 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusComicPageLayout.java +17 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +298 -34
- package/android/src/main/java/com/papyrus/engine/PapyrusNativeTextModel.java +195 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusPackage.java +3 -1
- package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerView.java +24 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusRenderMath.java +9 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentView.java +439 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentViewManager.java +43 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusTextStore.java +43 -0
- package/dist/index.d.mts +439 -3
- package/dist/index.d.ts +439 -3
- package/dist/index.js +412 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +404 -3
- package/dist/index.mjs.map +1 -1
- package/ios/PapyrusComicDocumentView.h +21 -0
- package/ios/PapyrusComicDocumentView.m +374 -0
- package/ios/PapyrusComicDocumentViewManager.m +23 -0
- package/ios/PapyrusEngineStore.m +4 -0
- package/ios/PapyrusNativeEngine.m +664 -0
- package/ios/PapyrusNativeEngine.podspec +26 -1
- package/ios/PapyrusPageRotationRegistry.h +29 -0
- package/ios/PapyrusPageRotationRegistry.m +179 -0
- package/ios/PapyrusPageView.m +38 -11
- package/ios/PapyrusPdfDocumentView.h +2 -0
- package/ios/PapyrusPdfDocumentView.m +121 -15
- package/ios/PapyrusPdfDocumentViewManager.m +2 -0
- package/ios/PapyrusPdfPageTheme.h +15 -0
- package/ios/PapyrusPdfPageTheme.m +218 -0
- package/ios/PapyrusTextDocumentView.h +27 -0
- package/ios/PapyrusTextDocumentView.m +300 -0
- package/ios/PapyrusTextDocumentViewManager.m +29 -0
- package/ios/PapyrusTextStore.h +13 -0
- package/ios/PapyrusTextStore.m +73 -0
- package/package.json +5 -3
- package/third_party_licenses/BLAKE2-NOTICE.txt +11 -0
- package/third_party_licenses/libarchive-COPYING +65 -0
- package/vendor/libarchive/PapyrusComicArchive.cpp +376 -0
- package/vendor/libarchive/PapyrusComicArchive.h +30 -0
- package/vendor/libarchive/README.papyrus.md +15 -0
- package/vendor/libarchive/android.h +192 -0
- package/vendor/libarchive/config/PapyrusArchiveConfig.h +65 -0
- package/vendor/libarchive/libarchive/CMakeLists.txt +293 -0
- package/vendor/libarchive/libarchive/android_lf.h +36 -0
- package/vendor/libarchive/libarchive/archive.h +1266 -0
- package/vendor/libarchive/libarchive/archive_acl.c +2025 -0
- package/vendor/libarchive/libarchive/archive_acl_private.h +85 -0
- package/vendor/libarchive/libarchive/archive_blake2.h +197 -0
- package/vendor/libarchive/libarchive/archive_blake2_impl.h +161 -0
- package/vendor/libarchive/libarchive/archive_blake2s_ref.c +369 -0
- package/vendor/libarchive/libarchive/archive_blake2sp_ref.c +361 -0
- package/vendor/libarchive/libarchive/archive_check_magic.c +183 -0
- package/vendor/libarchive/libarchive/archive_cmdline.c +211 -0
- package/vendor/libarchive/libarchive/archive_cmdline_private.h +45 -0
- package/vendor/libarchive/libarchive/archive_crc32.h +123 -0
- package/vendor/libarchive/libarchive/archive_cryptor.c +534 -0
- package/vendor/libarchive/libarchive/archive_cryptor_private.h +199 -0
- package/vendor/libarchive/libarchive/archive_digest.c +1584 -0
- package/vendor/libarchive/libarchive/archive_digest_private.h +431 -0
- package/vendor/libarchive/libarchive/archive_disk_acl_darwin.c +558 -0
- package/vendor/libarchive/libarchive/archive_disk_acl_freebsd.c +712 -0
- package/vendor/libarchive/libarchive/archive_disk_acl_linux.c +760 -0
- package/vendor/libarchive/libarchive/archive_disk_acl_sunos.c +824 -0
- package/vendor/libarchive/libarchive/archive_endian.h +234 -0
- package/vendor/libarchive/libarchive/archive_entry.3 +147 -0
- package/vendor/libarchive/libarchive/archive_entry.c +2297 -0
- package/vendor/libarchive/libarchive/archive_entry.h +763 -0
- package/vendor/libarchive/libarchive/archive_entry_acl.3 +458 -0
- package/vendor/libarchive/libarchive/archive_entry_copy_bhfi.c +55 -0
- package/vendor/libarchive/libarchive/archive_entry_copy_stat.c +82 -0
- package/vendor/libarchive/libarchive/archive_entry_link_resolver.c +472 -0
- package/vendor/libarchive/libarchive/archive_entry_linkify.3 +224 -0
- package/vendor/libarchive/libarchive/archive_entry_locale.h +90 -0
- package/vendor/libarchive/libarchive/archive_entry_misc.3 +63 -0
- package/vendor/libarchive/libarchive/archive_entry_paths.3 +153 -0
- package/vendor/libarchive/libarchive/archive_entry_perms.3 +210 -0
- package/vendor/libarchive/libarchive/archive_entry_private.h +205 -0
- package/vendor/libarchive/libarchive/archive_entry_sparse.c +156 -0
- package/vendor/libarchive/libarchive/archive_entry_stat.3 +274 -0
- package/vendor/libarchive/libarchive/archive_entry_stat.c +121 -0
- package/vendor/libarchive/libarchive/archive_entry_strmode.c +69 -0
- package/vendor/libarchive/libarchive/archive_entry_time.3 +127 -0
- package/vendor/libarchive/libarchive/archive_entry_xattr.c +155 -0
- package/vendor/libarchive/libarchive/archive_hmac.c +345 -0
- package/vendor/libarchive/libarchive/archive_hmac_private.h +119 -0
- package/vendor/libarchive/libarchive/archive_integer.h +267 -0
- package/vendor/libarchive/libarchive/archive_match.c +1869 -0
- package/vendor/libarchive/libarchive/archive_openssl_evp_private.h +54 -0
- package/vendor/libarchive/libarchive/archive_openssl_hmac_private.h +54 -0
- package/vendor/libarchive/libarchive/archive_options.c +219 -0
- package/vendor/libarchive/libarchive/archive_options_private.h +49 -0
- package/vendor/libarchive/libarchive/archive_pack_dev.c +330 -0
- package/vendor/libarchive/libarchive/archive_pack_dev.h +49 -0
- package/vendor/libarchive/libarchive/archive_parse_date.c +1173 -0
- package/vendor/libarchive/libarchive/archive_pathmatch.c +480 -0
- package/vendor/libarchive/libarchive/archive_pathmatch.h +50 -0
- package/vendor/libarchive/libarchive/archive_platform.h +213 -0
- package/vendor/libarchive/libarchive/archive_platform_acl.h +53 -0
- package/vendor/libarchive/libarchive/archive_platform_stat.h +45 -0
- package/vendor/libarchive/libarchive/archive_platform_xattr.h +45 -0
- package/vendor/libarchive/libarchive/archive_ppmd7.c +1173 -0
- package/vendor/libarchive/libarchive/archive_ppmd7_private.h +119 -0
- package/vendor/libarchive/libarchive/archive_ppmd8.c +1293 -0
- package/vendor/libarchive/libarchive/archive_ppmd8_private.h +123 -0
- package/vendor/libarchive/libarchive/archive_ppmd_private.h +159 -0
- package/vendor/libarchive/libarchive/archive_private.h +209 -0
- package/vendor/libarchive/libarchive/archive_random.c +274 -0
- package/vendor/libarchive/libarchive/archive_random_private.h +36 -0
- package/vendor/libarchive/libarchive/archive_rb.c +709 -0
- package/vendor/libarchive/libarchive/archive_rb.h +113 -0
- package/vendor/libarchive/libarchive/archive_read.3 +250 -0
- package/vendor/libarchive/libarchive/archive_read.c +1814 -0
- package/vendor/libarchive/libarchive/archive_read_add_passphrase.3 +72 -0
- package/vendor/libarchive/libarchive/archive_read_add_passphrase.c +189 -0
- package/vendor/libarchive/libarchive/archive_read_append_filter.c +209 -0
- package/vendor/libarchive/libarchive/archive_read_data.3 +128 -0
- package/vendor/libarchive/libarchive/archive_read_data_into_fd.c +207 -0
- package/vendor/libarchive/libarchive/archive_read_disk.3 +422 -0
- package/vendor/libarchive/libarchive/archive_read_disk_entry_from_file.c +1086 -0
- package/vendor/libarchive/libarchive/archive_read_disk_posix.c +2639 -0
- package/vendor/libarchive/libarchive/archive_read_disk_private.h +97 -0
- package/vendor/libarchive/libarchive/archive_read_disk_set_standard_lookup.c +315 -0
- package/vendor/libarchive/libarchive/archive_read_disk_windows.c +2603 -0
- package/vendor/libarchive/libarchive/archive_read_extract.3 +135 -0
- package/vendor/libarchive/libarchive/archive_read_extract.c +59 -0
- package/vendor/libarchive/libarchive/archive_read_extract2.c +154 -0
- package/vendor/libarchive/libarchive/archive_read_filter.3 +163 -0
- package/vendor/libarchive/libarchive/archive_read_format.3 +190 -0
- package/vendor/libarchive/libarchive/archive_read_free.3 +91 -0
- package/vendor/libarchive/libarchive/archive_read_header.3 +89 -0
- package/vendor/libarchive/libarchive/archive_read_new.3 +57 -0
- package/vendor/libarchive/libarchive/archive_read_open.3 +247 -0
- package/vendor/libarchive/libarchive/archive_read_open_fd.c +236 -0
- package/vendor/libarchive/libarchive/archive_read_open_file.c +257 -0
- package/vendor/libarchive/libarchive/archive_read_open_filename.c +652 -0
- package/vendor/libarchive/libarchive/archive_read_open_memory.c +188 -0
- package/vendor/libarchive/libarchive/archive_read_private.h +274 -0
- package/vendor/libarchive/libarchive/archive_read_set_format.c +116 -0
- package/vendor/libarchive/libarchive/archive_read_set_options.3 +290 -0
- package/vendor/libarchive/libarchive/archive_read_set_options.c +132 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_all.c +84 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_by_code.c +68 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_bzip2.c +360 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_compress.c +457 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_grzip.c +108 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_gzip.c +538 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_lrzip.c +119 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_lz4.c +829 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_lzop.c +493 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_none.c +51 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_program.c +497 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_rpm.c +249 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_uu.c +739 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_xz.c +792 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_zstd.c +356 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_7zip.c +4650 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_all.c +88 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_ar.c +597 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_by_code.c +76 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_cab.c +3410 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_cpio.c +1152 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_empty.c +95 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_iso9660.c +3516 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_lha.c +2931 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_mtree.c +2113 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_rar.c +3932 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_rar5.c +4501 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_raw.c +194 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_tar.c +3785 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_warc.c +875 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_xar.c +3770 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_zip.c +4710 -0
- package/vendor/libarchive/libarchive/archive_string.c +4391 -0
- package/vendor/libarchive/libarchive/archive_string.h +244 -0
- package/vendor/libarchive/libarchive/archive_string_composition.h +2289 -0
- package/vendor/libarchive/libarchive/archive_string_sprintf.c +200 -0
- package/vendor/libarchive/libarchive/archive_time.c +168 -0
- package/vendor/libarchive/libarchive/archive_time_private.h +47 -0
- package/vendor/libarchive/libarchive/archive_util.3 +239 -0
- package/vendor/libarchive/libarchive/archive_util.c +668 -0
- package/vendor/libarchive/libarchive/archive_version_details.c +516 -0
- package/vendor/libarchive/libarchive/archive_virtual.c +162 -0
- package/vendor/libarchive/libarchive/archive_windows.c +1035 -0
- package/vendor/libarchive/libarchive/archive_windows.h +332 -0
- package/vendor/libarchive/libarchive/archive_write.3 +266 -0
- package/vendor/libarchive/libarchive/archive_write.c +896 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter.c +71 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_b64encode.c +329 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_by_name.c +76 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_bzip2.c +411 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_compress.c +459 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_grzip.c +143 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_gzip.c +493 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_lrzip.c +214 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_lz4.c +710 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_lzop.c +500 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_none.c +42 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_program.c +398 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_uuencode.c +320 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_xz.c +547 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_zstd.c +608 -0
- package/vendor/libarchive/libarchive/archive_write_blocksize.3 +112 -0
- package/vendor/libarchive/libarchive/archive_write_data.3 +88 -0
- package/vendor/libarchive/libarchive/archive_write_disk.3 +360 -0
- package/vendor/libarchive/libarchive/archive_write_disk_posix.c +4789 -0
- package/vendor/libarchive/libarchive/archive_write_disk_private.h +43 -0
- package/vendor/libarchive/libarchive/archive_write_disk_set_standard_lookup.c +265 -0
- package/vendor/libarchive/libarchive/archive_write_disk_windows.c +2952 -0
- package/vendor/libarchive/libarchive/archive_write_filter.3 +140 -0
- package/vendor/libarchive/libarchive/archive_write_finish_entry.3 +77 -0
- package/vendor/libarchive/libarchive/archive_write_format.3 +187 -0
- package/vendor/libarchive/libarchive/archive_write_free.3 +94 -0
- package/vendor/libarchive/libarchive/archive_write_header.3 +71 -0
- package/vendor/libarchive/libarchive/archive_write_new.3 +56 -0
- package/vendor/libarchive/libarchive/archive_write_open.3 +270 -0
- package/vendor/libarchive/libarchive/archive_write_open_fd.c +141 -0
- package/vendor/libarchive/libarchive/archive_write_open_file.c +102 -0
- package/vendor/libarchive/libarchive/archive_write_open_filename.c +272 -0
- package/vendor/libarchive/libarchive/archive_write_open_memory.c +110 -0
- package/vendor/libarchive/libarchive/archive_write_private.h +166 -0
- package/vendor/libarchive/libarchive/archive_write_set_format.c +124 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_7zip.c +2571 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_ar.c +540 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_by_name.c +93 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_cpio.c +11 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_cpio_binary.c +618 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_cpio_newc.c +457 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_cpio_odc.c +508 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_filter_by_ext.c +141 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_gnutar.c +790 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_iso9660.c +8216 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_mtree.c +2307 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_pax.c +2249 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_private.h +40 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_raw.c +123 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_shar.c +650 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_ustar.c +768 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_v7tar.c +648 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_warc.c +491 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_xar.c +3799 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_zip.c +2548 -0
- package/vendor/libarchive/libarchive/archive_write_set_options.3 +779 -0
- package/vendor/libarchive/libarchive/archive_write_set_options.c +129 -0
- package/vendor/libarchive/libarchive/archive_write_set_passphrase.3 +72 -0
- package/vendor/libarchive/libarchive/archive_write_set_passphrase.c +95 -0
- package/vendor/libarchive/libarchive/archive_xxhash.h +48 -0
- package/vendor/libarchive/libarchive/config_freebsd.h +275 -0
- package/vendor/libarchive/libarchive/cpio.5 +389 -0
- package/vendor/libarchive/libarchive/filter_fork.h +44 -0
- package/vendor/libarchive/libarchive/filter_fork_posix.c +269 -0
- package/vendor/libarchive/libarchive/filter_fork_windows.c +270 -0
- package/vendor/libarchive/libarchive/libarchive-formats.5 +478 -0
- package/vendor/libarchive/libarchive/libarchive.3 +297 -0
- package/vendor/libarchive/libarchive/libarchive_changes.3 +339 -0
- package/vendor/libarchive/libarchive/libarchive_internals.3 +363 -0
- package/vendor/libarchive/libarchive/module.modulemap +34 -0
- package/vendor/libarchive/libarchive/mtree.5 +323 -0
- package/vendor/libarchive/libarchive/tar.5 +947 -0
- package/vendor/libarchive/libarchive/xxhash.c +531 -0
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
/*-
|
|
2
|
+
* Copyright (c) 2003-2007 Tim Kientzle
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
|
6
|
+
* modification, are permitted provided that the following conditions
|
|
7
|
+
* are met:
|
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
|
10
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
|
11
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
12
|
+
* documentation and/or other materials provided with the distribution.
|
|
13
|
+
*
|
|
14
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
|
15
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
16
|
+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
17
|
+
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
18
|
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
19
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
20
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
21
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
22
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
23
|
+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include "archive_platform.h"
|
|
27
|
+
|
|
28
|
+
#ifdef HAVE_SYS_STAT_H
|
|
29
|
+
#include <sys/stat.h>
|
|
30
|
+
#endif
|
|
31
|
+
#ifdef HAVE_ERRNO_H
|
|
32
|
+
#include <errno.h>
|
|
33
|
+
#endif
|
|
34
|
+
#include <stdio.h>
|
|
35
|
+
#ifdef HAVE_STDLIB_H
|
|
36
|
+
#include <stdlib.h>
|
|
37
|
+
#endif
|
|
38
|
+
#ifdef HAVE_STRING_H
|
|
39
|
+
#include <string.h>
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
#include "archive.h"
|
|
43
|
+
#include "archive_entry.h"
|
|
44
|
+
#include "archive_integer.h"
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
* This is mostly a pretty straightforward hash table implementation.
|
|
48
|
+
* The only interesting bit is the different strategies used to
|
|
49
|
+
* match up links. These strategies match those used by various
|
|
50
|
+
* archiving formats:
|
|
51
|
+
* tar - content stored with first link, remainder refer back to it.
|
|
52
|
+
* This requires us to match each subsequent link up with the
|
|
53
|
+
* first appearance.
|
|
54
|
+
* cpio - Old cpio just stored body with each link, match-ups were
|
|
55
|
+
* implicit. This is trivial.
|
|
56
|
+
* new cpio - New cpio only stores body with last link, match-ups
|
|
57
|
+
* are implicit. This is actually quite tricky; see the notes
|
|
58
|
+
* below.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/* Users pass us a format code, we translate that into a strategy here. */
|
|
62
|
+
#define ARCHIVE_ENTRY_LINKIFY_LIKE_TAR 0
|
|
63
|
+
#define ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE 1
|
|
64
|
+
#define ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO 2
|
|
65
|
+
#define ARCHIVE_ENTRY_LINKIFY_LIKE_NEW_CPIO 3
|
|
66
|
+
|
|
67
|
+
/* Initial size of link cache. */
|
|
68
|
+
#define links_cache_initial_size 1024
|
|
69
|
+
|
|
70
|
+
struct links_entry {
|
|
71
|
+
struct links_entry *next;
|
|
72
|
+
struct links_entry *previous;
|
|
73
|
+
struct archive_entry *canonical;
|
|
74
|
+
struct archive_entry *entry;
|
|
75
|
+
size_t hash;
|
|
76
|
+
unsigned int links; /* # links not yet seen */
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
struct archive_entry_linkresolver {
|
|
80
|
+
struct links_entry **buckets;
|
|
81
|
+
struct links_entry *spare;
|
|
82
|
+
size_t number_entries;
|
|
83
|
+
size_t number_buckets;
|
|
84
|
+
int strategy;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
#define NEXT_ENTRY_DEFERRED 1
|
|
88
|
+
#define NEXT_ENTRY_PARTIAL 2
|
|
89
|
+
#define NEXT_ENTRY_ALL (NEXT_ENTRY_DEFERRED | NEXT_ENTRY_PARTIAL)
|
|
90
|
+
|
|
91
|
+
static struct links_entry *find_entry(struct archive_entry_linkresolver *,
|
|
92
|
+
struct archive_entry *);
|
|
93
|
+
static void grow_hash(struct archive_entry_linkresolver *);
|
|
94
|
+
static struct links_entry *insert_entry(struct archive_entry_linkresolver *,
|
|
95
|
+
struct archive_entry *);
|
|
96
|
+
static struct links_entry *next_entry(struct archive_entry_linkresolver *,
|
|
97
|
+
int);
|
|
98
|
+
|
|
99
|
+
struct archive_entry_linkresolver *
|
|
100
|
+
archive_entry_linkresolver_new(void)
|
|
101
|
+
{
|
|
102
|
+
struct archive_entry_linkresolver *res;
|
|
103
|
+
|
|
104
|
+
/* Check for positive power-of-two */
|
|
105
|
+
if (links_cache_initial_size == 0 ||
|
|
106
|
+
(links_cache_initial_size & (links_cache_initial_size - 1)) != 0)
|
|
107
|
+
return (NULL);
|
|
108
|
+
|
|
109
|
+
res = calloc(1, sizeof(struct archive_entry_linkresolver));
|
|
110
|
+
if (res == NULL)
|
|
111
|
+
return (NULL);
|
|
112
|
+
res->number_buckets = links_cache_initial_size;
|
|
113
|
+
res->buckets = calloc(res->number_buckets, sizeof(res->buckets[0]));
|
|
114
|
+
if (res->buckets == NULL) {
|
|
115
|
+
free(res);
|
|
116
|
+
return (NULL);
|
|
117
|
+
}
|
|
118
|
+
return (res);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
void
|
|
122
|
+
archive_entry_linkresolver_set_strategy(struct archive_entry_linkresolver *res,
|
|
123
|
+
int fmt)
|
|
124
|
+
{
|
|
125
|
+
int fmtbase = fmt & ARCHIVE_FORMAT_BASE_MASK;
|
|
126
|
+
|
|
127
|
+
switch (fmtbase) {
|
|
128
|
+
case ARCHIVE_FORMAT_7ZIP:
|
|
129
|
+
case ARCHIVE_FORMAT_AR:
|
|
130
|
+
case ARCHIVE_FORMAT_ZIP:
|
|
131
|
+
res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO;
|
|
132
|
+
break;
|
|
133
|
+
case ARCHIVE_FORMAT_CPIO:
|
|
134
|
+
switch (fmt) {
|
|
135
|
+
case ARCHIVE_FORMAT_CPIO_SVR4_NOCRC:
|
|
136
|
+
case ARCHIVE_FORMAT_CPIO_SVR4_CRC:
|
|
137
|
+
res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_NEW_CPIO;
|
|
138
|
+
break;
|
|
139
|
+
default:
|
|
140
|
+
res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
break;
|
|
144
|
+
case ARCHIVE_FORMAT_MTREE:
|
|
145
|
+
res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE;
|
|
146
|
+
break;
|
|
147
|
+
case ARCHIVE_FORMAT_ISO9660:
|
|
148
|
+
case ARCHIVE_FORMAT_SHAR:
|
|
149
|
+
case ARCHIVE_FORMAT_TAR:
|
|
150
|
+
case ARCHIVE_FORMAT_XAR:
|
|
151
|
+
res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_TAR;
|
|
152
|
+
break;
|
|
153
|
+
default:
|
|
154
|
+
res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
void
|
|
160
|
+
archive_entry_linkresolver_free(struct archive_entry_linkresolver *res)
|
|
161
|
+
{
|
|
162
|
+
if (res == NULL)
|
|
163
|
+
return;
|
|
164
|
+
|
|
165
|
+
while (next_entry(res, NEXT_ENTRY_ALL) != NULL) {
|
|
166
|
+
/* Actual freeing done by next_entry() */
|
|
167
|
+
}
|
|
168
|
+
free(res->buckets);
|
|
169
|
+
free(res);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
void
|
|
173
|
+
archive_entry_linkify(struct archive_entry_linkresolver *res,
|
|
174
|
+
struct archive_entry **e, struct archive_entry **f)
|
|
175
|
+
{
|
|
176
|
+
struct links_entry *le;
|
|
177
|
+
struct archive_entry *t;
|
|
178
|
+
|
|
179
|
+
*f = NULL; /* Default: Don't return a second entry. */
|
|
180
|
+
|
|
181
|
+
if (*e == NULL) {
|
|
182
|
+
le = next_entry(res, NEXT_ENTRY_DEFERRED);
|
|
183
|
+
if (le != NULL) {
|
|
184
|
+
*e = le->entry;
|
|
185
|
+
le->entry = NULL;
|
|
186
|
+
}
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/* If it has only one link, then we're done. */
|
|
191
|
+
if (archive_entry_nlink(*e) == 1)
|
|
192
|
+
return;
|
|
193
|
+
/* Directories, devices never have hardlinks. */
|
|
194
|
+
if (archive_entry_filetype(*e) == AE_IFDIR
|
|
195
|
+
|| archive_entry_filetype(*e) == AE_IFBLK
|
|
196
|
+
|| archive_entry_filetype(*e) == AE_IFCHR)
|
|
197
|
+
return;
|
|
198
|
+
|
|
199
|
+
switch (res->strategy) {
|
|
200
|
+
case ARCHIVE_ENTRY_LINKIFY_LIKE_TAR:
|
|
201
|
+
le = find_entry(res, *e);
|
|
202
|
+
if (le != NULL) {
|
|
203
|
+
archive_entry_unset_size(*e);
|
|
204
|
+
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
205
|
+
archive_entry_copy_hardlink_w(*e,
|
|
206
|
+
archive_entry_pathname_w(le->canonical));
|
|
207
|
+
#else
|
|
208
|
+
archive_entry_copy_hardlink(*e,
|
|
209
|
+
archive_entry_pathname(le->canonical));
|
|
210
|
+
#endif
|
|
211
|
+
} else
|
|
212
|
+
insert_entry(res, *e);
|
|
213
|
+
return;
|
|
214
|
+
case ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE:
|
|
215
|
+
le = find_entry(res, *e);
|
|
216
|
+
if (le != NULL) {
|
|
217
|
+
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
218
|
+
archive_entry_copy_hardlink_w(*e,
|
|
219
|
+
archive_entry_pathname_w(le->canonical));
|
|
220
|
+
#else
|
|
221
|
+
archive_entry_copy_hardlink(*e,
|
|
222
|
+
archive_entry_pathname(le->canonical));
|
|
223
|
+
#endif
|
|
224
|
+
} else
|
|
225
|
+
insert_entry(res, *e);
|
|
226
|
+
return;
|
|
227
|
+
case ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO:
|
|
228
|
+
/* This one is trivial. */
|
|
229
|
+
return;
|
|
230
|
+
case ARCHIVE_ENTRY_LINKIFY_LIKE_NEW_CPIO:
|
|
231
|
+
le = find_entry(res, *e);
|
|
232
|
+
if (le != NULL) {
|
|
233
|
+
/*
|
|
234
|
+
* Put the new entry in le, return the
|
|
235
|
+
* old entry from le.
|
|
236
|
+
*/
|
|
237
|
+
t = *e;
|
|
238
|
+
*e = le->entry;
|
|
239
|
+
le->entry = t;
|
|
240
|
+
/* Make the old entry into a hardlink. */
|
|
241
|
+
archive_entry_unset_size(*e);
|
|
242
|
+
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
243
|
+
archive_entry_copy_hardlink_w(*e,
|
|
244
|
+
archive_entry_pathname_w(le->canonical));
|
|
245
|
+
#else
|
|
246
|
+
archive_entry_copy_hardlink(*e,
|
|
247
|
+
archive_entry_pathname(le->canonical));
|
|
248
|
+
#endif
|
|
249
|
+
/* If we ran out of links, return the
|
|
250
|
+
* final entry as well. */
|
|
251
|
+
if (le->links == 0) {
|
|
252
|
+
*f = le->entry;
|
|
253
|
+
le->entry = NULL;
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
/*
|
|
257
|
+
* If we haven't seen it, tuck it away
|
|
258
|
+
* for future use.
|
|
259
|
+
*/
|
|
260
|
+
le = insert_entry(res, *e);
|
|
261
|
+
if (le == NULL)
|
|
262
|
+
/* XXX We should return an error code XXX */
|
|
263
|
+
return;
|
|
264
|
+
le->entry = *e;
|
|
265
|
+
*e = NULL;
|
|
266
|
+
}
|
|
267
|
+
return;
|
|
268
|
+
default:
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
static struct links_entry *
|
|
275
|
+
find_entry(struct archive_entry_linkresolver *res,
|
|
276
|
+
struct archive_entry *entry)
|
|
277
|
+
{
|
|
278
|
+
struct links_entry *le;
|
|
279
|
+
size_t hash, bucket;
|
|
280
|
+
dev_t dev;
|
|
281
|
+
int64_t ino;
|
|
282
|
+
|
|
283
|
+
if (!archive_entry_ino_is_set(entry) || !archive_entry_dev_is_set(entry)) {
|
|
284
|
+
return (NULL);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/* Free a held entry. */
|
|
288
|
+
if (res->spare != NULL) {
|
|
289
|
+
archive_entry_free(res->spare->canonical);
|
|
290
|
+
archive_entry_free(res->spare->entry);
|
|
291
|
+
free(res->spare);
|
|
292
|
+
res->spare = NULL;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
dev = archive_entry_dev(entry);
|
|
296
|
+
ino = archive_entry_ino64(entry);
|
|
297
|
+
hash = (size_t)(dev ^ ino);
|
|
298
|
+
|
|
299
|
+
/* Try to locate this entry in the links cache. */
|
|
300
|
+
bucket = hash & (res->number_buckets - 1);
|
|
301
|
+
for (le = res->buckets[bucket]; le != NULL; le = le->next) {
|
|
302
|
+
if (le->hash == hash
|
|
303
|
+
&& dev == archive_entry_dev(le->canonical)
|
|
304
|
+
&& ino == archive_entry_ino64(le->canonical)) {
|
|
305
|
+
/*
|
|
306
|
+
* Decrement link count each time and release
|
|
307
|
+
* the entry if it hits zero. This saves
|
|
308
|
+
* memory and is necessary for detecting
|
|
309
|
+
* missed links.
|
|
310
|
+
*/
|
|
311
|
+
--le->links;
|
|
312
|
+
if (le->links > 0)
|
|
313
|
+
return (le);
|
|
314
|
+
/* Remove it from this hash bucket. */
|
|
315
|
+
if (le->previous != NULL)
|
|
316
|
+
le->previous->next = le->next;
|
|
317
|
+
if (le->next != NULL)
|
|
318
|
+
le->next->previous = le->previous;
|
|
319
|
+
if (res->buckets[bucket] == le)
|
|
320
|
+
res->buckets[bucket] = le->next;
|
|
321
|
+
res->number_entries--;
|
|
322
|
+
/* Defer freeing this entry. */
|
|
323
|
+
res->spare = le;
|
|
324
|
+
return (le);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return (NULL);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
static struct links_entry *
|
|
331
|
+
next_entry(struct archive_entry_linkresolver *res, int mode)
|
|
332
|
+
{
|
|
333
|
+
struct links_entry *le;
|
|
334
|
+
size_t bucket;
|
|
335
|
+
|
|
336
|
+
/* Free a held entry. */
|
|
337
|
+
if (res->spare != NULL) {
|
|
338
|
+
archive_entry_free(res->spare->canonical);
|
|
339
|
+
archive_entry_free(res->spare->entry);
|
|
340
|
+
free(res->spare);
|
|
341
|
+
res->spare = NULL;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/* Look for next non-empty bucket in the links cache. */
|
|
345
|
+
for (bucket = 0; bucket < res->number_buckets; bucket++) {
|
|
346
|
+
for (le = res->buckets[bucket]; le != NULL; le = le->next) {
|
|
347
|
+
if (le->entry != NULL &&
|
|
348
|
+
(mode & NEXT_ENTRY_DEFERRED) == 0)
|
|
349
|
+
continue;
|
|
350
|
+
if (le->entry == NULL &&
|
|
351
|
+
(mode & NEXT_ENTRY_PARTIAL) == 0)
|
|
352
|
+
continue;
|
|
353
|
+
/* Remove it from this hash bucket. */
|
|
354
|
+
if (le->next != NULL)
|
|
355
|
+
le->next->previous = le->previous;
|
|
356
|
+
if (le->previous != NULL)
|
|
357
|
+
le->previous->next = le->next;
|
|
358
|
+
else
|
|
359
|
+
res->buckets[bucket] = le->next;
|
|
360
|
+
res->number_entries--;
|
|
361
|
+
/* Defer freeing this entry. */
|
|
362
|
+
res->spare = le;
|
|
363
|
+
return (le);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return (NULL);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
static struct links_entry *
|
|
370
|
+
insert_entry(struct archive_entry_linkresolver *res,
|
|
371
|
+
struct archive_entry *entry)
|
|
372
|
+
{
|
|
373
|
+
struct links_entry *le;
|
|
374
|
+
size_t hash, bucket;
|
|
375
|
+
|
|
376
|
+
if (!archive_entry_ino_is_set(entry) || !archive_entry_dev_is_set(entry)) {
|
|
377
|
+
return (NULL);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/* Add this entry to the links cache. */
|
|
381
|
+
le = calloc(1, sizeof(struct links_entry));
|
|
382
|
+
if (le == NULL)
|
|
383
|
+
return (NULL);
|
|
384
|
+
le->canonical = archive_entry_clone(entry);
|
|
385
|
+
if (le->canonical == NULL) {
|
|
386
|
+
free(le);
|
|
387
|
+
return (NULL);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/* If the links cache is getting too full, enlarge the hash table. */
|
|
391
|
+
if (res->number_entries / 2 > res->number_buckets)
|
|
392
|
+
grow_hash(res);
|
|
393
|
+
|
|
394
|
+
hash = (size_t)(archive_entry_dev(entry) ^ archive_entry_ino64(entry));
|
|
395
|
+
bucket = hash & (res->number_buckets - 1);
|
|
396
|
+
|
|
397
|
+
/* If we could allocate the entry, record it. */
|
|
398
|
+
if (res->buckets[bucket] != NULL)
|
|
399
|
+
res->buckets[bucket]->previous = le;
|
|
400
|
+
res->number_entries++;
|
|
401
|
+
le->next = res->buckets[bucket];
|
|
402
|
+
le->previous = NULL;
|
|
403
|
+
res->buckets[bucket] = le;
|
|
404
|
+
le->hash = hash;
|
|
405
|
+
le->links = archive_entry_nlink(entry) - 1;
|
|
406
|
+
return (le);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
static void
|
|
410
|
+
grow_hash(struct archive_entry_linkresolver *res)
|
|
411
|
+
{
|
|
412
|
+
struct links_entry *le, **new_buckets;
|
|
413
|
+
size_t new_size;
|
|
414
|
+
size_t i, bucket;
|
|
415
|
+
|
|
416
|
+
/* Try to enlarge the bucket list. */
|
|
417
|
+
if (archive_ckd_mul_size(&new_size, res->number_buckets, 2))
|
|
418
|
+
return;
|
|
419
|
+
new_buckets = calloc(new_size, sizeof(struct links_entry *));
|
|
420
|
+
|
|
421
|
+
if (new_buckets == NULL)
|
|
422
|
+
return;
|
|
423
|
+
|
|
424
|
+
for (i = 0; i < res->number_buckets; i++) {
|
|
425
|
+
while (res->buckets[i] != NULL) {
|
|
426
|
+
/* Remove entry from old bucket. */
|
|
427
|
+
le = res->buckets[i];
|
|
428
|
+
res->buckets[i] = le->next;
|
|
429
|
+
|
|
430
|
+
/* Add entry to new bucket. */
|
|
431
|
+
bucket = le->hash & (new_size - 1);
|
|
432
|
+
|
|
433
|
+
if (new_buckets[bucket] != NULL)
|
|
434
|
+
new_buckets[bucket]->previous = le;
|
|
435
|
+
le->next = new_buckets[bucket];
|
|
436
|
+
le->previous = NULL;
|
|
437
|
+
new_buckets[bucket] = le;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
free(res->buckets);
|
|
441
|
+
res->buckets = new_buckets;
|
|
442
|
+
res->number_buckets = new_size;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
struct archive_entry *
|
|
446
|
+
archive_entry_partial_links(struct archive_entry_linkresolver *res,
|
|
447
|
+
unsigned int *links)
|
|
448
|
+
{
|
|
449
|
+
struct archive_entry *e;
|
|
450
|
+
struct links_entry *le;
|
|
451
|
+
|
|
452
|
+
/* Free a held entry. */
|
|
453
|
+
if (res->spare != NULL) {
|
|
454
|
+
archive_entry_free(res->spare->canonical);
|
|
455
|
+
archive_entry_free(res->spare->entry);
|
|
456
|
+
free(res->spare);
|
|
457
|
+
res->spare = NULL;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
le = next_entry(res, NEXT_ENTRY_PARTIAL);
|
|
461
|
+
if (le != NULL) {
|
|
462
|
+
e = le->canonical;
|
|
463
|
+
if (links != NULL)
|
|
464
|
+
*links = le->links;
|
|
465
|
+
le->canonical = NULL;
|
|
466
|
+
} else {
|
|
467
|
+
e = NULL;
|
|
468
|
+
if (links != NULL)
|
|
469
|
+
*links = 0;
|
|
470
|
+
}
|
|
471
|
+
return (e);
|
|
472
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
.\" Copyright (c) 2010 Joerg Sonnenberger
|
|
2
|
+
.\" All rights reserved.
|
|
3
|
+
.\"
|
|
4
|
+
.\" Redistribution and use in source and binary forms, with or without
|
|
5
|
+
.\" modification, are permitted provided that the following conditions
|
|
6
|
+
.\" are met:
|
|
7
|
+
.\" 1. Redistributions of source code must retain the above copyright
|
|
8
|
+
.\" notice, this list of conditions and the following disclaimer.
|
|
9
|
+
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
10
|
+
.\" notice, this list of conditions and the following disclaimer in the
|
|
11
|
+
.\" documentation and/or other materials provided with the distribution.
|
|
12
|
+
.\"
|
|
13
|
+
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
14
|
+
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
15
|
+
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
16
|
+
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
17
|
+
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
18
|
+
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
19
|
+
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
20
|
+
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
21
|
+
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
22
|
+
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
23
|
+
.\" SUCH DAMAGE.
|
|
24
|
+
.\"
|
|
25
|
+
.Dd February 2, 2012
|
|
26
|
+
.Dt ARCHIVE_ENTRY_LINKIFY 3
|
|
27
|
+
.Os
|
|
28
|
+
.Sh NAME
|
|
29
|
+
.Nm archive_entry_linkresolver ,
|
|
30
|
+
.Nm archive_entry_linkresolver_new ,
|
|
31
|
+
.Nm archive_entry_linkresolver_set_strategy ,
|
|
32
|
+
.Nm archive_entry_linkresolver_free ,
|
|
33
|
+
.Nm archive_entry_linkify
|
|
34
|
+
.Nd hardlink resolver functions
|
|
35
|
+
.Sh LIBRARY
|
|
36
|
+
Streaming Archive Library (libarchive, -larchive)
|
|
37
|
+
.Sh SYNOPSIS
|
|
38
|
+
.In archive_entry.h
|
|
39
|
+
.Ft struct archive_entry_linkresolver *
|
|
40
|
+
.Fn archive_entry_linkresolver_new void
|
|
41
|
+
.Ft void
|
|
42
|
+
.Fo archive_entry_linkresolver_set_strategy
|
|
43
|
+
.Fa "struct archive_entry_linkresolver *resolver"
|
|
44
|
+
.Fa "int format"
|
|
45
|
+
.Fc
|
|
46
|
+
.Ft void
|
|
47
|
+
.Fo archive_entry_linkresolver_free
|
|
48
|
+
.Fa "struct archive_entry_linkresolver *resolver"
|
|
49
|
+
.Fc
|
|
50
|
+
.Ft void
|
|
51
|
+
.Fo archive_entry_linkify
|
|
52
|
+
.Fa "struct archive_entry_linkresolver *resolver"
|
|
53
|
+
.Fa "struct archive_entry **entry"
|
|
54
|
+
.Fa "struct archive_entry **sparse"
|
|
55
|
+
.Fc
|
|
56
|
+
.Sh DESCRIPTION
|
|
57
|
+
Programs that want to create archives have to deal with hardlinks.
|
|
58
|
+
Hardlinks are handled in different ways by the archive formats.
|
|
59
|
+
The basic strategies are:
|
|
60
|
+
.Bl -enum
|
|
61
|
+
.It
|
|
62
|
+
Ignore hardlinks and store the body for each reference (old cpio, zip).
|
|
63
|
+
.It
|
|
64
|
+
Store the body the first time an inode is seen (ustar, pax).
|
|
65
|
+
.It
|
|
66
|
+
Store the body the last time an inode is seen (new cpio).
|
|
67
|
+
.El
|
|
68
|
+
.Pp
|
|
69
|
+
The
|
|
70
|
+
.Nm
|
|
71
|
+
functions help by providing a unified interface and handling the complexity
|
|
72
|
+
behind the scene.
|
|
73
|
+
.Pp
|
|
74
|
+
The
|
|
75
|
+
.Nm
|
|
76
|
+
functions assume that
|
|
77
|
+
.Vt archive_entry
|
|
78
|
+
instances have valid nlinks, inode and device values.
|
|
79
|
+
The inode and device value is used to match entries.
|
|
80
|
+
The nlinks value is used to determined if all references have been found and
|
|
81
|
+
if the internal references can be recycled.
|
|
82
|
+
.Pp
|
|
83
|
+
The
|
|
84
|
+
.Fn archive_entry_linkresolver_new
|
|
85
|
+
function allocates a new link resolver.
|
|
86
|
+
The instance can be freed using
|
|
87
|
+
.Fn archive_entry_linkresolver_free .
|
|
88
|
+
All deferred entries are flushed and the internal storage is freed.
|
|
89
|
+
.Pp
|
|
90
|
+
The
|
|
91
|
+
.Fn archive_entry_linkresolver_set_strategy
|
|
92
|
+
function selects the optimal hardlink strategy for the given format.
|
|
93
|
+
The format code can be obtained from
|
|
94
|
+
.Xr archive_format 3 .
|
|
95
|
+
The function can be called more than once, but it is recommended to
|
|
96
|
+
flush all deferred entries first.
|
|
97
|
+
.Pp
|
|
98
|
+
The
|
|
99
|
+
.Fn archive_entry_linkify
|
|
100
|
+
function is the core of
|
|
101
|
+
.Nm .
|
|
102
|
+
The
|
|
103
|
+
.Fn entry
|
|
104
|
+
argument points to the
|
|
105
|
+
.Vt archive_entry
|
|
106
|
+
that should be written.
|
|
107
|
+
Depending on the strategy one of the following actions is taken:
|
|
108
|
+
.Bl -enum
|
|
109
|
+
.It
|
|
110
|
+
For the simple archive formats
|
|
111
|
+
.Va *entry
|
|
112
|
+
is left unmodified and
|
|
113
|
+
.Va *sparse
|
|
114
|
+
is set to
|
|
115
|
+
.Dv NULL .
|
|
116
|
+
.It
|
|
117
|
+
For tar like archive formats,
|
|
118
|
+
.Va *sparse
|
|
119
|
+
is set to
|
|
120
|
+
.Dv NULL .
|
|
121
|
+
If
|
|
122
|
+
.Va *entry
|
|
123
|
+
is
|
|
124
|
+
.Dv NULL ,
|
|
125
|
+
no action is taken.
|
|
126
|
+
If the hardlink count of
|
|
127
|
+
.Va *entry
|
|
128
|
+
is larger than 1 and the file type is a regular file or symbolic link,
|
|
129
|
+
the internal list is searched for a matching inode.
|
|
130
|
+
If such an inode is found, the link count is decremented and the file size
|
|
131
|
+
of
|
|
132
|
+
.Va *entry
|
|
133
|
+
is set to 0 to notify that no body should be written.
|
|
134
|
+
If no such inode is found, a copy of the entry is added to the internal cache
|
|
135
|
+
with a link count reduced by one.
|
|
136
|
+
.It
|
|
137
|
+
For new cpio like archive formats a value for
|
|
138
|
+
.Va *entry
|
|
139
|
+
of
|
|
140
|
+
.Dv NULL
|
|
141
|
+
is used to flush deferred entries.
|
|
142
|
+
In that case
|
|
143
|
+
.Va *entry
|
|
144
|
+
is set to an arbitrary deferred entry and the entry itself is removed from the
|
|
145
|
+
internal list.
|
|
146
|
+
If the internal list is empty,
|
|
147
|
+
.Va *entry
|
|
148
|
+
is set to
|
|
149
|
+
.Dv NULL .
|
|
150
|
+
In either case,
|
|
151
|
+
.Va *sparse
|
|
152
|
+
is set to
|
|
153
|
+
.Dv NULL
|
|
154
|
+
and the function returns.
|
|
155
|
+
If the hardlink count of
|
|
156
|
+
.Va *entry
|
|
157
|
+
is one or the file type is a directory or device,
|
|
158
|
+
.Va *sparse
|
|
159
|
+
is set to
|
|
160
|
+
.Dv NULL
|
|
161
|
+
and no further action is taken.
|
|
162
|
+
Otherwise, the internal list is searched for a matching inode.
|
|
163
|
+
If such an inode is not found, the entry is added to the internal list,
|
|
164
|
+
both
|
|
165
|
+
.Va *entry
|
|
166
|
+
and
|
|
167
|
+
.Va *sparse
|
|
168
|
+
are set to
|
|
169
|
+
.Dv NULL
|
|
170
|
+
and the function returns.
|
|
171
|
+
If such an inode is found, the link count is decremented.
|
|
172
|
+
If it remains larger than one, the existing entry on the internal list
|
|
173
|
+
is swapped with
|
|
174
|
+
.Va *entry
|
|
175
|
+
after retaining the link count.
|
|
176
|
+
The existing entry is returned in
|
|
177
|
+
.Va *entry .
|
|
178
|
+
If the link count reached one, the new entry is also removed from the
|
|
179
|
+
internal list and returned in
|
|
180
|
+
.Va *sparse .
|
|
181
|
+
Otherwise
|
|
182
|
+
.Va *sparse
|
|
183
|
+
is set to
|
|
184
|
+
.Dv NULL .
|
|
185
|
+
.El
|
|
186
|
+
.Pp
|
|
187
|
+
The general usage is therefore:
|
|
188
|
+
.Bl -enum
|
|
189
|
+
.It
|
|
190
|
+
For each new archive entry, call
|
|
191
|
+
.Fn archive_entry_linkify .
|
|
192
|
+
.It
|
|
193
|
+
Keep in mind that the entries returned may have a size of 0 now.
|
|
194
|
+
.It
|
|
195
|
+
If
|
|
196
|
+
.Va *entry
|
|
197
|
+
is not
|
|
198
|
+
.Dv NULL ,
|
|
199
|
+
archive it.
|
|
200
|
+
.It
|
|
201
|
+
If
|
|
202
|
+
.Va *sparse
|
|
203
|
+
is not
|
|
204
|
+
.Dv NULL ,
|
|
205
|
+
archive it.
|
|
206
|
+
.It
|
|
207
|
+
After all entries have been written to disk, call
|
|
208
|
+
.Fn archive_entry_linkify
|
|
209
|
+
with
|
|
210
|
+
.Va *entry
|
|
211
|
+
set to
|
|
212
|
+
.Dv NULL
|
|
213
|
+
and archive the returned entry as long as it is not
|
|
214
|
+
.Dv NULL .
|
|
215
|
+
.El
|
|
216
|
+
.Sh RETURN VALUES
|
|
217
|
+
.Fn archive_entry_linkresolver_new
|
|
218
|
+
returns
|
|
219
|
+
.Dv NULL
|
|
220
|
+
on
|
|
221
|
+
.Xr malloc 3
|
|
222
|
+
failures.
|
|
223
|
+
.Sh SEE ALSO
|
|
224
|
+
.Xr archive_entry 3
|