@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,768 @@
|
|
|
1
|
+
/*-
|
|
2
|
+
* Copyright (c) 2003-2007 Tim Kientzle
|
|
3
|
+
* Copyright (c) 2011-2012 Michihiro NAKAJIMA
|
|
4
|
+
* All rights reserved.
|
|
5
|
+
*
|
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
|
7
|
+
* modification, are permitted provided that the following conditions
|
|
8
|
+
* are met:
|
|
9
|
+
* 1. Redistributions of source code must retain the above copyright
|
|
10
|
+
* notice, this list of conditions and the following disclaimer.
|
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
|
12
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
13
|
+
* documentation and/or other materials provided with the distribution.
|
|
14
|
+
*
|
|
15
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
|
16
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
17
|
+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
18
|
+
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
19
|
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
20
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
21
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
22
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
23
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
24
|
+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
#include "archive_platform.h"
|
|
28
|
+
|
|
29
|
+
#ifdef HAVE_ERRNO_H
|
|
30
|
+
#include <errno.h>
|
|
31
|
+
#endif
|
|
32
|
+
#include <stdio.h>
|
|
33
|
+
#ifdef HAVE_STDLIB_H
|
|
34
|
+
#include <stdlib.h>
|
|
35
|
+
#endif
|
|
36
|
+
#ifdef HAVE_STRING_H
|
|
37
|
+
#include <string.h>
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
#include "archive.h"
|
|
41
|
+
#include "archive_entry.h"
|
|
42
|
+
#include "archive_entry_locale.h"
|
|
43
|
+
#include "archive_private.h"
|
|
44
|
+
#include "archive_write_private.h"
|
|
45
|
+
#include "archive_write_set_format_private.h"
|
|
46
|
+
|
|
47
|
+
struct ustar {
|
|
48
|
+
uint64_t entry_bytes_remaining;
|
|
49
|
+
uint64_t entry_padding;
|
|
50
|
+
|
|
51
|
+
struct archive_string_conv *opt_sconv;
|
|
52
|
+
struct archive_string_conv *sconv_default;
|
|
53
|
+
int init_default_conversion;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/*
|
|
57
|
+
* Define structure of POSIX 'ustar' tar header.
|
|
58
|
+
*/
|
|
59
|
+
#define USTAR_name_offset 0
|
|
60
|
+
#define USTAR_name_size 100
|
|
61
|
+
#define USTAR_mode_offset 100
|
|
62
|
+
#define USTAR_mode_size 6
|
|
63
|
+
#define USTAR_mode_max_size 8
|
|
64
|
+
#define USTAR_uid_offset 108
|
|
65
|
+
#define USTAR_uid_size 6
|
|
66
|
+
#define USTAR_uid_max_size 8
|
|
67
|
+
#define USTAR_gid_offset 116
|
|
68
|
+
#define USTAR_gid_size 6
|
|
69
|
+
#define USTAR_gid_max_size 8
|
|
70
|
+
#define USTAR_size_offset 124
|
|
71
|
+
#define USTAR_size_size 11
|
|
72
|
+
#define USTAR_size_max_size 12
|
|
73
|
+
#define USTAR_mtime_offset 136
|
|
74
|
+
#define USTAR_mtime_size 11
|
|
75
|
+
#define USTAR_mtime_max_size 11
|
|
76
|
+
#define USTAR_checksum_offset 148
|
|
77
|
+
#define USTAR_checksum_size 8
|
|
78
|
+
#define USTAR_typeflag_offset 156
|
|
79
|
+
#define USTAR_typeflag_size 1
|
|
80
|
+
#define USTAR_linkname_offset 157
|
|
81
|
+
#define USTAR_linkname_size 100
|
|
82
|
+
#define USTAR_magic_offset 257
|
|
83
|
+
#define USTAR_magic_size 6
|
|
84
|
+
#define USTAR_version_offset 263
|
|
85
|
+
#define USTAR_version_size 2
|
|
86
|
+
#define USTAR_uname_offset 265
|
|
87
|
+
#define USTAR_uname_size 32
|
|
88
|
+
#define USTAR_gname_offset 297
|
|
89
|
+
#define USTAR_gname_size 32
|
|
90
|
+
#define USTAR_rdevmajor_offset 329
|
|
91
|
+
#define USTAR_rdevmajor_size 6
|
|
92
|
+
#define USTAR_rdevmajor_max_size 8
|
|
93
|
+
#define USTAR_rdevminor_offset 337
|
|
94
|
+
#define USTAR_rdevminor_size 6
|
|
95
|
+
#define USTAR_rdevminor_max_size 8
|
|
96
|
+
#define USTAR_prefix_offset 345
|
|
97
|
+
#define USTAR_prefix_size 155
|
|
98
|
+
#define USTAR_padding_offset 500
|
|
99
|
+
#define USTAR_padding_size 12
|
|
100
|
+
|
|
101
|
+
/*
|
|
102
|
+
* A filled-in copy of the header for initialization.
|
|
103
|
+
*/
|
|
104
|
+
static const char template_header[] = {
|
|
105
|
+
/* name: 100 bytes */
|
|
106
|
+
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
|
|
107
|
+
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
|
|
108
|
+
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
|
|
109
|
+
0,0,0,0,
|
|
110
|
+
/* Mode, space-null termination: 8 bytes */
|
|
111
|
+
'0','0','0','0','0','0', ' ','\0',
|
|
112
|
+
/* uid, space-null termination: 8 bytes */
|
|
113
|
+
'0','0','0','0','0','0', ' ','\0',
|
|
114
|
+
/* gid, space-null termination: 8 bytes */
|
|
115
|
+
'0','0','0','0','0','0', ' ','\0',
|
|
116
|
+
/* size, space termination: 12 bytes */
|
|
117
|
+
'0','0','0','0','0','0','0','0','0','0','0', ' ',
|
|
118
|
+
/* mtime, space termination: 12 bytes */
|
|
119
|
+
'0','0','0','0','0','0','0','0','0','0','0', ' ',
|
|
120
|
+
/* Initial checksum value: 8 spaces */
|
|
121
|
+
' ',' ',' ',' ',' ',' ',' ',' ',
|
|
122
|
+
/* Typeflag: 1 byte */
|
|
123
|
+
'0', /* '0' = regular file */
|
|
124
|
+
/* Linkname: 100 bytes */
|
|
125
|
+
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
|
|
126
|
+
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
|
|
127
|
+
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
|
|
128
|
+
0,0,0,0,
|
|
129
|
+
/* Magic: 6 bytes, Version: 2 bytes */
|
|
130
|
+
'u','s','t','a','r','\0', '0','0',
|
|
131
|
+
/* Uname: 32 bytes */
|
|
132
|
+
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
|
|
133
|
+
/* Gname: 32 bytes */
|
|
134
|
+
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
|
|
135
|
+
/* rdevmajor + space/null padding: 8 bytes */
|
|
136
|
+
'0','0','0','0','0','0', ' ','\0',
|
|
137
|
+
/* rdevminor + space/null padding: 8 bytes */
|
|
138
|
+
'0','0','0','0','0','0', ' ','\0',
|
|
139
|
+
/* Prefix: 155 bytes */
|
|
140
|
+
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
|
|
141
|
+
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
|
|
142
|
+
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
|
|
143
|
+
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
|
|
144
|
+
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,
|
|
145
|
+
/* Padding: 12 bytes */
|
|
146
|
+
0,0,0,0,0,0,0,0, 0,0,0,0
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
static ssize_t archive_write_ustar_data(struct archive_write *a, const void *buff,
|
|
150
|
+
size_t s);
|
|
151
|
+
static int archive_write_ustar_free(struct archive_write *);
|
|
152
|
+
static int archive_write_ustar_close(struct archive_write *);
|
|
153
|
+
static int archive_write_ustar_finish_entry(struct archive_write *);
|
|
154
|
+
static int archive_write_ustar_header(struct archive_write *,
|
|
155
|
+
struct archive_entry *entry);
|
|
156
|
+
static int archive_write_ustar_options(struct archive_write *,
|
|
157
|
+
const char *, const char *);
|
|
158
|
+
static int format_256(int64_t, char *, int);
|
|
159
|
+
static int format_number(int64_t, char *, int size, int max, int strict);
|
|
160
|
+
static int format_octal(int64_t, char *, int);
|
|
161
|
+
|
|
162
|
+
/*
|
|
163
|
+
* Set output format to 'ustar' format.
|
|
164
|
+
*/
|
|
165
|
+
int
|
|
166
|
+
archive_write_set_format_ustar(struct archive *_a)
|
|
167
|
+
{
|
|
168
|
+
struct archive_write *a = (struct archive_write *)_a;
|
|
169
|
+
struct ustar *ustar;
|
|
170
|
+
|
|
171
|
+
archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
|
|
172
|
+
ARCHIVE_STATE_NEW, "archive_write_set_format_ustar");
|
|
173
|
+
|
|
174
|
+
/* If someone else was already registered, unregister them. */
|
|
175
|
+
(void)__archive_write_unregister_format(a);
|
|
176
|
+
|
|
177
|
+
/* Basic internal sanity test. */
|
|
178
|
+
if (sizeof(template_header) != 512) {
|
|
179
|
+
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
|
|
180
|
+
"Internal: template_header wrong size: %zu should be 512",
|
|
181
|
+
sizeof(template_header));
|
|
182
|
+
return (ARCHIVE_FATAL);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
ustar = calloc(1, sizeof(*ustar));
|
|
186
|
+
if (ustar == NULL) {
|
|
187
|
+
archive_set_error(&a->archive, ENOMEM,
|
|
188
|
+
"Can't allocate ustar data");
|
|
189
|
+
return (ARCHIVE_FATAL);
|
|
190
|
+
}
|
|
191
|
+
a->format_data = ustar;
|
|
192
|
+
a->format_name = "ustar";
|
|
193
|
+
a->format_options = archive_write_ustar_options;
|
|
194
|
+
a->format_write_header = archive_write_ustar_header;
|
|
195
|
+
a->format_write_data = archive_write_ustar_data;
|
|
196
|
+
a->format_close = archive_write_ustar_close;
|
|
197
|
+
a->format_free = archive_write_ustar_free;
|
|
198
|
+
a->format_finish_entry = archive_write_ustar_finish_entry;
|
|
199
|
+
a->archive.archive_format = ARCHIVE_FORMAT_TAR_USTAR;
|
|
200
|
+
a->archive.archive_format_name = "POSIX ustar";
|
|
201
|
+
return (ARCHIVE_OK);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
static int
|
|
205
|
+
archive_write_ustar_options(struct archive_write *a, const char *key,
|
|
206
|
+
const char *val)
|
|
207
|
+
{
|
|
208
|
+
struct ustar *ustar = a->format_data;
|
|
209
|
+
int ret = ARCHIVE_FAILED;
|
|
210
|
+
|
|
211
|
+
if (strcmp(key, "hdrcharset") == 0) {
|
|
212
|
+
if (val == NULL || val[0] == 0)
|
|
213
|
+
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
|
|
214
|
+
"%s: hdrcharset option needs a character-set name",
|
|
215
|
+
a->format_name);
|
|
216
|
+
else {
|
|
217
|
+
ustar->opt_sconv = archive_string_conversion_to_charset(
|
|
218
|
+
&a->archive, val, 0);
|
|
219
|
+
if (ustar->opt_sconv != NULL)
|
|
220
|
+
ret = ARCHIVE_OK;
|
|
221
|
+
else
|
|
222
|
+
ret = ARCHIVE_FATAL;
|
|
223
|
+
}
|
|
224
|
+
return (ret);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/* Note: The "warn" return is just to inform the options
|
|
228
|
+
* supervisor that we didn't handle it. It will generate
|
|
229
|
+
* a suitable error if no one used this option. */
|
|
230
|
+
return (ARCHIVE_WARN);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
static int
|
|
234
|
+
archive_write_ustar_header(struct archive_write *a, struct archive_entry *entry)
|
|
235
|
+
{
|
|
236
|
+
struct ustar *ustar = a->format_data;
|
|
237
|
+
char buff[512];
|
|
238
|
+
int ret, ret2;
|
|
239
|
+
struct archive_entry *entry_main;
|
|
240
|
+
struct archive_string_conv *sconv;
|
|
241
|
+
|
|
242
|
+
/* Setup default string conversion. */
|
|
243
|
+
if (ustar->opt_sconv == NULL) {
|
|
244
|
+
if (!ustar->init_default_conversion) {
|
|
245
|
+
ustar->sconv_default =
|
|
246
|
+
archive_string_default_conversion_for_write(&(a->archive));
|
|
247
|
+
ustar->init_default_conversion = 1;
|
|
248
|
+
}
|
|
249
|
+
sconv = ustar->sconv_default;
|
|
250
|
+
} else
|
|
251
|
+
sconv = ustar->opt_sconv;
|
|
252
|
+
|
|
253
|
+
/* Sanity check. */
|
|
254
|
+
if (archive_entry_pathname(entry) == NULL
|
|
255
|
+
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
256
|
+
&& archive_entry_pathname_w(entry) == NULL
|
|
257
|
+
#endif
|
|
258
|
+
) {
|
|
259
|
+
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
|
|
260
|
+
"Can't record entry in tar file without pathname");
|
|
261
|
+
return (ARCHIVE_FAILED);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/* Only regular files (not hardlinks) have data. */
|
|
265
|
+
if (archive_entry_hardlink(entry) != NULL ||
|
|
266
|
+
archive_entry_symlink(entry) != NULL ||
|
|
267
|
+
archive_entry_filetype(entry) != AE_IFREG)
|
|
268
|
+
archive_entry_set_size(entry, 0);
|
|
269
|
+
|
|
270
|
+
if (AE_IFDIR == archive_entry_filetype(entry)) {
|
|
271
|
+
const char *p;
|
|
272
|
+
size_t path_length;
|
|
273
|
+
/*
|
|
274
|
+
* Ensure a trailing '/'. Modify the entry so
|
|
275
|
+
* the client sees the change.
|
|
276
|
+
*/
|
|
277
|
+
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
278
|
+
const wchar_t *wp;
|
|
279
|
+
|
|
280
|
+
wp = archive_entry_pathname_w(entry);
|
|
281
|
+
if (wp != NULL && wp[0] != L'\0' &&
|
|
282
|
+
wp[wcslen(wp) - 1] != L'/') {
|
|
283
|
+
struct archive_wstring ws;
|
|
284
|
+
|
|
285
|
+
archive_string_init(&ws);
|
|
286
|
+
path_length = wcslen(wp);
|
|
287
|
+
if (archive_wstring_ensure(&ws,
|
|
288
|
+
path_length + 2) == NULL) {
|
|
289
|
+
archive_set_error(&a->archive, ENOMEM,
|
|
290
|
+
"Can't allocate ustar data");
|
|
291
|
+
archive_wstring_free(&ws);
|
|
292
|
+
return(ARCHIVE_FATAL);
|
|
293
|
+
}
|
|
294
|
+
/* Should we keep '\' ? */
|
|
295
|
+
if (wp[path_length -1] == L'\\')
|
|
296
|
+
path_length--;
|
|
297
|
+
archive_wstrncpy(&ws, wp, path_length);
|
|
298
|
+
archive_wstrappend_wchar(&ws, L'/');
|
|
299
|
+
archive_entry_copy_pathname_w(entry, ws.s);
|
|
300
|
+
archive_wstring_free(&ws);
|
|
301
|
+
p = NULL;
|
|
302
|
+
} else
|
|
303
|
+
#endif
|
|
304
|
+
p = archive_entry_pathname(entry);
|
|
305
|
+
/*
|
|
306
|
+
* On Windows, this is a backup operation just in
|
|
307
|
+
* case getting WCS failed. On POSIX, this is a
|
|
308
|
+
* normal operation.
|
|
309
|
+
*/
|
|
310
|
+
if (p != NULL && p[0] != '\0' && p[strlen(p) - 1] != '/') {
|
|
311
|
+
struct archive_string as;
|
|
312
|
+
|
|
313
|
+
archive_string_init(&as);
|
|
314
|
+
path_length = strlen(p);
|
|
315
|
+
if (archive_string_ensure(&as,
|
|
316
|
+
path_length + 2) == NULL) {
|
|
317
|
+
archive_set_error(&a->archive, ENOMEM,
|
|
318
|
+
"Can't allocate ustar data");
|
|
319
|
+
archive_string_free(&as);
|
|
320
|
+
return(ARCHIVE_FATAL);
|
|
321
|
+
}
|
|
322
|
+
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
323
|
+
/* NOTE: This might break the pathname
|
|
324
|
+
* if the current code page is CP932 and
|
|
325
|
+
* the pathname includes a character '\'
|
|
326
|
+
* as a part of its multibyte pathname. */
|
|
327
|
+
if (p[strlen(p) -1] == '\\')
|
|
328
|
+
path_length--;
|
|
329
|
+
else
|
|
330
|
+
#endif
|
|
331
|
+
archive_strncpy(&as, p, path_length);
|
|
332
|
+
archive_strappend_char(&as, '/');
|
|
333
|
+
archive_entry_copy_pathname(entry, as.s);
|
|
334
|
+
archive_string_free(&as);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
339
|
+
/* Make sure the path separators in pathname, hardlink and symlink
|
|
340
|
+
* are all slash '/', not the Windows path separator '\'. */
|
|
341
|
+
entry_main = __la_win_entry_in_posix_pathseparator(entry);
|
|
342
|
+
if (entry_main == NULL) {
|
|
343
|
+
archive_set_error(&a->archive, ENOMEM,
|
|
344
|
+
"Can't allocate ustar data");
|
|
345
|
+
return(ARCHIVE_FATAL);
|
|
346
|
+
}
|
|
347
|
+
if (entry != entry_main)
|
|
348
|
+
entry = entry_main;
|
|
349
|
+
else
|
|
350
|
+
entry_main = NULL;
|
|
351
|
+
#else
|
|
352
|
+
entry_main = NULL;
|
|
353
|
+
#endif
|
|
354
|
+
ret = __archive_write_format_header_ustar(a, buff, entry, -1, 1, sconv);
|
|
355
|
+
if (ret < ARCHIVE_WARN) {
|
|
356
|
+
archive_entry_free(entry_main);
|
|
357
|
+
return (ret);
|
|
358
|
+
}
|
|
359
|
+
ret2 = __archive_write_output(a, buff, 512);
|
|
360
|
+
if (ret2 < ARCHIVE_WARN) {
|
|
361
|
+
archive_entry_free(entry_main);
|
|
362
|
+
return (ret2);
|
|
363
|
+
}
|
|
364
|
+
if (ret2 < ret)
|
|
365
|
+
ret = ret2;
|
|
366
|
+
|
|
367
|
+
ustar->entry_bytes_remaining = archive_entry_size(entry);
|
|
368
|
+
ustar->entry_padding = 0x1ff & (-(int64_t)ustar->entry_bytes_remaining);
|
|
369
|
+
archive_entry_free(entry_main);
|
|
370
|
+
return (ret);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/*
|
|
374
|
+
* Format a basic 512-byte "ustar" header.
|
|
375
|
+
*
|
|
376
|
+
* Returns -1 if format failed (due to field overflow).
|
|
377
|
+
* Note that this always formats as much of the header as possible.
|
|
378
|
+
* If "strict" is set to zero, it will extend numeric fields as
|
|
379
|
+
* necessary (overwriting terminators or using base-256 extensions).
|
|
380
|
+
*
|
|
381
|
+
* This is exported so that other 'tar' formats can use it.
|
|
382
|
+
*/
|
|
383
|
+
int
|
|
384
|
+
__archive_write_format_header_ustar(struct archive_write *a, char h[512],
|
|
385
|
+
struct archive_entry *entry, int tartype, int strict,
|
|
386
|
+
struct archive_string_conv *sconv)
|
|
387
|
+
{
|
|
388
|
+
unsigned int checksum;
|
|
389
|
+
int i, r, ret;
|
|
390
|
+
size_t copy_length;
|
|
391
|
+
const char *p, *pp;
|
|
392
|
+
int mytartype;
|
|
393
|
+
|
|
394
|
+
ret = 0;
|
|
395
|
+
mytartype = -1;
|
|
396
|
+
/*
|
|
397
|
+
* The "template header" already includes the "ustar"
|
|
398
|
+
* signature, various end-of-field markers and other required
|
|
399
|
+
* elements.
|
|
400
|
+
*/
|
|
401
|
+
memcpy(h, &template_header, 512);
|
|
402
|
+
|
|
403
|
+
/*
|
|
404
|
+
* Because the block is already null-filled, and strings
|
|
405
|
+
* are allowed to exactly fill their destination (without null),
|
|
406
|
+
* I use memcpy(dest, src, strlen()) here a lot to copy strings.
|
|
407
|
+
*/
|
|
408
|
+
r = archive_entry_pathname_l(entry, &pp, ©_length, sconv);
|
|
409
|
+
if (r != 0) {
|
|
410
|
+
const char* p_mbs;
|
|
411
|
+
if (errno == ENOMEM) {
|
|
412
|
+
archive_set_error(&a->archive, ENOMEM,
|
|
413
|
+
"Can't allocate memory for Pathname");
|
|
414
|
+
return (ARCHIVE_FATAL);
|
|
415
|
+
}
|
|
416
|
+
p_mbs = archive_entry_pathname(entry);
|
|
417
|
+
if (p_mbs) {
|
|
418
|
+
/* We have a wrongly-encoded MBS pathname.
|
|
419
|
+
* Warn and use it. */
|
|
420
|
+
archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
|
|
421
|
+
"Can't translate pathname '%s' to %s", p_mbs,
|
|
422
|
+
archive_string_conversion_charset_name(sconv));
|
|
423
|
+
ret = ARCHIVE_WARN;
|
|
424
|
+
} else {
|
|
425
|
+
/* We have no MBS pathname. Fail. */
|
|
426
|
+
archive_set_error(&a->archive,
|
|
427
|
+
ARCHIVE_ERRNO_FILE_FORMAT,
|
|
428
|
+
"Can't translate pathname to %s",
|
|
429
|
+
archive_string_conversion_charset_name(sconv));
|
|
430
|
+
return ARCHIVE_FAILED;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
if (copy_length <= USTAR_name_size)
|
|
434
|
+
memcpy(h + USTAR_name_offset, pp, copy_length);
|
|
435
|
+
else {
|
|
436
|
+
/* Store in two pieces, splitting at a '/'. */
|
|
437
|
+
p = strchr(pp + copy_length - USTAR_name_size - 1, '/');
|
|
438
|
+
/*
|
|
439
|
+
* Look for the next '/' if we chose the first character
|
|
440
|
+
* as the separator. (ustar format doesn't permit
|
|
441
|
+
* an empty prefix.)
|
|
442
|
+
*/
|
|
443
|
+
if (p == pp)
|
|
444
|
+
p = strchr(p + 1, '/');
|
|
445
|
+
/* Fail if the name won't fit. */
|
|
446
|
+
if (!p) {
|
|
447
|
+
/* No separator. */
|
|
448
|
+
archive_set_error(&a->archive, ENAMETOOLONG,
|
|
449
|
+
"Pathname too long");
|
|
450
|
+
ret = ARCHIVE_FAILED;
|
|
451
|
+
} else if (p[1] == '\0') {
|
|
452
|
+
/*
|
|
453
|
+
* The only feasible separator is a final '/';
|
|
454
|
+
* this would result in a non-empty prefix and
|
|
455
|
+
* an empty name, which POSIX doesn't
|
|
456
|
+
* explicitly forbid, but it just feels wrong.
|
|
457
|
+
*/
|
|
458
|
+
archive_set_error(&a->archive, ENAMETOOLONG,
|
|
459
|
+
"Pathname too long");
|
|
460
|
+
ret = ARCHIVE_FAILED;
|
|
461
|
+
} else if (p > pp + USTAR_prefix_size) {
|
|
462
|
+
/* Prefix is too long. */
|
|
463
|
+
archive_set_error(&a->archive, ENAMETOOLONG,
|
|
464
|
+
"Pathname too long");
|
|
465
|
+
ret = ARCHIVE_FAILED;
|
|
466
|
+
} else {
|
|
467
|
+
/* Copy prefix and remainder to appropriate places */
|
|
468
|
+
memcpy(h + USTAR_prefix_offset, pp, p - pp);
|
|
469
|
+
memcpy(h + USTAR_name_offset, p + 1,
|
|
470
|
+
pp + copy_length - p - 1);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
r = archive_entry_hardlink_l(entry, &p, ©_length, sconv);
|
|
475
|
+
if (r != 0) {
|
|
476
|
+
if (errno == ENOMEM) {
|
|
477
|
+
archive_set_error(&a->archive, ENOMEM,
|
|
478
|
+
"Can't allocate memory for Linkname");
|
|
479
|
+
return (ARCHIVE_FATAL);
|
|
480
|
+
}
|
|
481
|
+
archive_set_error(&a->archive,
|
|
482
|
+
ARCHIVE_ERRNO_FILE_FORMAT,
|
|
483
|
+
"Can't translate linkname '%s' to %s",
|
|
484
|
+
p, archive_string_conversion_charset_name(sconv));
|
|
485
|
+
ret = ARCHIVE_WARN;
|
|
486
|
+
}
|
|
487
|
+
if (copy_length > 0)
|
|
488
|
+
mytartype = '1';
|
|
489
|
+
else {
|
|
490
|
+
r = archive_entry_symlink_l(entry, &p, ©_length, sconv);
|
|
491
|
+
if (r != 0) {
|
|
492
|
+
if (errno == ENOMEM) {
|
|
493
|
+
archive_set_error(&a->archive, ENOMEM,
|
|
494
|
+
"Can't allocate memory for Linkname");
|
|
495
|
+
return (ARCHIVE_FATAL);
|
|
496
|
+
}
|
|
497
|
+
archive_set_error(&a->archive,
|
|
498
|
+
ARCHIVE_ERRNO_FILE_FORMAT,
|
|
499
|
+
"Can't translate linkname '%s' to %s",
|
|
500
|
+
p, archive_string_conversion_charset_name(sconv));
|
|
501
|
+
ret = ARCHIVE_WARN;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
if (copy_length > 0) {
|
|
505
|
+
if (copy_length > USTAR_linkname_size) {
|
|
506
|
+
archive_set_error(&a->archive, ENAMETOOLONG,
|
|
507
|
+
"Link contents too long");
|
|
508
|
+
ret = ARCHIVE_FAILED;
|
|
509
|
+
copy_length = USTAR_linkname_size;
|
|
510
|
+
}
|
|
511
|
+
memcpy(h + USTAR_linkname_offset, p, copy_length);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
r = archive_entry_uname_l(entry, &p, ©_length, sconv);
|
|
515
|
+
if (r != 0) {
|
|
516
|
+
if (errno == ENOMEM) {
|
|
517
|
+
archive_set_error(&a->archive, ENOMEM,
|
|
518
|
+
"Can't allocate memory for Uname");
|
|
519
|
+
return (ARCHIVE_FATAL);
|
|
520
|
+
}
|
|
521
|
+
archive_set_error(&a->archive,
|
|
522
|
+
ARCHIVE_ERRNO_FILE_FORMAT,
|
|
523
|
+
"Can't translate uname '%s' to %s",
|
|
524
|
+
p, archive_string_conversion_charset_name(sconv));
|
|
525
|
+
ret = ARCHIVE_WARN;
|
|
526
|
+
}
|
|
527
|
+
if (copy_length > 0) {
|
|
528
|
+
if (copy_length > USTAR_uname_size) {
|
|
529
|
+
if (tartype != 'x') {
|
|
530
|
+
archive_set_error(&a->archive,
|
|
531
|
+
ARCHIVE_ERRNO_MISC, "Username too long");
|
|
532
|
+
ret = ARCHIVE_FAILED;
|
|
533
|
+
}
|
|
534
|
+
copy_length = USTAR_uname_size;
|
|
535
|
+
}
|
|
536
|
+
memcpy(h + USTAR_uname_offset, p, copy_length);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
r = archive_entry_gname_l(entry, &p, ©_length, sconv);
|
|
540
|
+
if (r != 0) {
|
|
541
|
+
if (errno == ENOMEM) {
|
|
542
|
+
archive_set_error(&a->archive, ENOMEM,
|
|
543
|
+
"Can't allocate memory for Gname");
|
|
544
|
+
return (ARCHIVE_FATAL);
|
|
545
|
+
}
|
|
546
|
+
archive_set_error(&a->archive,
|
|
547
|
+
ARCHIVE_ERRNO_FILE_FORMAT,
|
|
548
|
+
"Can't translate gname '%s' to %s",
|
|
549
|
+
p, archive_string_conversion_charset_name(sconv));
|
|
550
|
+
ret = ARCHIVE_WARN;
|
|
551
|
+
}
|
|
552
|
+
if (copy_length > 0) {
|
|
553
|
+
if (copy_length > USTAR_gname_size) {
|
|
554
|
+
if (tartype != 'x') {
|
|
555
|
+
archive_set_error(&a->archive,
|
|
556
|
+
ARCHIVE_ERRNO_MISC, "Group name too long");
|
|
557
|
+
ret = ARCHIVE_FAILED;
|
|
558
|
+
}
|
|
559
|
+
copy_length = USTAR_gname_size;
|
|
560
|
+
}
|
|
561
|
+
memcpy(h + USTAR_gname_offset, p, copy_length);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
if (format_number(archive_entry_mode(entry) & 07777,
|
|
565
|
+
h + USTAR_mode_offset, USTAR_mode_size, USTAR_mode_max_size, strict)) {
|
|
566
|
+
archive_set_error(&a->archive, ERANGE,
|
|
567
|
+
"Numeric mode too large");
|
|
568
|
+
ret = ARCHIVE_FAILED;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
if (format_number(archive_entry_uid(entry),
|
|
572
|
+
h + USTAR_uid_offset, USTAR_uid_size, USTAR_uid_max_size, strict)) {
|
|
573
|
+
archive_set_error(&a->archive, ERANGE,
|
|
574
|
+
"Numeric user ID too large");
|
|
575
|
+
ret = ARCHIVE_FAILED;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
if (format_number(archive_entry_gid(entry),
|
|
579
|
+
h + USTAR_gid_offset, USTAR_gid_size, USTAR_gid_max_size, strict)) {
|
|
580
|
+
archive_set_error(&a->archive, ERANGE,
|
|
581
|
+
"Numeric group ID too large");
|
|
582
|
+
ret = ARCHIVE_FAILED;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
if (format_number(archive_entry_size(entry),
|
|
586
|
+
h + USTAR_size_offset, USTAR_size_size, USTAR_size_max_size, strict)) {
|
|
587
|
+
archive_set_error(&a->archive, ERANGE,
|
|
588
|
+
"File size out of range");
|
|
589
|
+
ret = ARCHIVE_FAILED;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
if (format_number(archive_entry_mtime(entry),
|
|
593
|
+
h + USTAR_mtime_offset, USTAR_mtime_size, USTAR_mtime_max_size, strict)) {
|
|
594
|
+
archive_set_error(&a->archive, ERANGE,
|
|
595
|
+
"File modification time too large");
|
|
596
|
+
ret = ARCHIVE_FAILED;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
if (archive_entry_filetype(entry) == AE_IFBLK
|
|
600
|
+
|| archive_entry_filetype(entry) == AE_IFCHR) {
|
|
601
|
+
if (format_number(archive_entry_rdevmajor(entry),
|
|
602
|
+
h + USTAR_rdevmajor_offset, USTAR_rdevmajor_size,
|
|
603
|
+
USTAR_rdevmajor_max_size, strict)) {
|
|
604
|
+
archive_set_error(&a->archive, ERANGE,
|
|
605
|
+
"Major device number too large");
|
|
606
|
+
ret = ARCHIVE_FAILED;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
if (format_number(archive_entry_rdevminor(entry),
|
|
610
|
+
h + USTAR_rdevminor_offset, USTAR_rdevminor_size,
|
|
611
|
+
USTAR_rdevminor_max_size, strict)) {
|
|
612
|
+
archive_set_error(&a->archive, ERANGE,
|
|
613
|
+
"Minor device number too large");
|
|
614
|
+
ret = ARCHIVE_FAILED;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
if (tartype >= 0) {
|
|
619
|
+
h[USTAR_typeflag_offset] = tartype;
|
|
620
|
+
} else if (mytartype >= 0) {
|
|
621
|
+
h[USTAR_typeflag_offset] = mytartype;
|
|
622
|
+
} else {
|
|
623
|
+
switch (archive_entry_filetype(entry)) {
|
|
624
|
+
case AE_IFREG: h[USTAR_typeflag_offset] = '0' ; break;
|
|
625
|
+
case AE_IFLNK: h[USTAR_typeflag_offset] = '2' ; break;
|
|
626
|
+
case AE_IFCHR: h[USTAR_typeflag_offset] = '3' ; break;
|
|
627
|
+
case AE_IFBLK: h[USTAR_typeflag_offset] = '4' ; break;
|
|
628
|
+
case AE_IFDIR: h[USTAR_typeflag_offset] = '5' ; break;
|
|
629
|
+
case AE_IFIFO: h[USTAR_typeflag_offset] = '6' ; break;
|
|
630
|
+
default: /* AE_IFSOCK and unknown */
|
|
631
|
+
__archive_write_entry_filetype_unsupported(
|
|
632
|
+
&a->archive, entry, "ustar");
|
|
633
|
+
ret = ARCHIVE_FAILED;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
checksum = 0;
|
|
638
|
+
for (i = 0; i < 512; i++)
|
|
639
|
+
checksum += 255 & (unsigned int)h[i];
|
|
640
|
+
h[USTAR_checksum_offset + 6] = '\0'; /* Can't be pre-set in the template. */
|
|
641
|
+
/* h[USTAR_checksum_offset + 7] = ' '; */ /* This is pre-set in the template. */
|
|
642
|
+
format_octal(checksum, h + USTAR_checksum_offset, 6);
|
|
643
|
+
return (ret);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/*
|
|
647
|
+
* Format a number into a field, with some intelligence.
|
|
648
|
+
*/
|
|
649
|
+
static int
|
|
650
|
+
format_number(int64_t v, char *p, int s, int maxsize, int strict)
|
|
651
|
+
{
|
|
652
|
+
int64_t limit;
|
|
653
|
+
|
|
654
|
+
limit = ((int64_t)1 << (s*3));
|
|
655
|
+
|
|
656
|
+
/* "Strict" only permits octal values with proper termination. */
|
|
657
|
+
if (strict)
|
|
658
|
+
return (format_octal(v, p, s));
|
|
659
|
+
|
|
660
|
+
/*
|
|
661
|
+
* In non-strict mode, we allow the number to overwrite one or
|
|
662
|
+
* more bytes of the field termination. Even old tar
|
|
663
|
+
* implementations should be able to handle this with no
|
|
664
|
+
* problem.
|
|
665
|
+
*/
|
|
666
|
+
if (v >= 0) {
|
|
667
|
+
while (s <= maxsize) {
|
|
668
|
+
if (v < limit)
|
|
669
|
+
return (format_octal(v, p, s));
|
|
670
|
+
s++;
|
|
671
|
+
limit <<= 3;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/* Base-256 can handle any number, positive or negative. */
|
|
676
|
+
return (format_256(v, p, maxsize));
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
/*
|
|
680
|
+
* Format a number into the specified field using base-256.
|
|
681
|
+
*/
|
|
682
|
+
static int
|
|
683
|
+
format_256(int64_t v, char *p, int s)
|
|
684
|
+
{
|
|
685
|
+
p += s;
|
|
686
|
+
while (s-- > 0) {
|
|
687
|
+
*--p = (char)(v & 0xff);
|
|
688
|
+
v >>= 8;
|
|
689
|
+
}
|
|
690
|
+
*p |= 0x80; /* Set the base-256 marker bit. */
|
|
691
|
+
return (0);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/*
|
|
695
|
+
* Format a number into the specified field.
|
|
696
|
+
*/
|
|
697
|
+
static int
|
|
698
|
+
format_octal(int64_t v, char *p, int s)
|
|
699
|
+
{
|
|
700
|
+
int len;
|
|
701
|
+
|
|
702
|
+
len = s;
|
|
703
|
+
|
|
704
|
+
/* Octal values can't be negative, so use 0. */
|
|
705
|
+
if (v < 0) {
|
|
706
|
+
while (len-- > 0)
|
|
707
|
+
*p++ = '0';
|
|
708
|
+
return (-1);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
p += s; /* Start at the end and work backwards. */
|
|
712
|
+
while (s-- > 0) {
|
|
713
|
+
*--p = (char)('0' + (v & 7));
|
|
714
|
+
v >>= 3;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
if (v == 0)
|
|
718
|
+
return (0);
|
|
719
|
+
|
|
720
|
+
/* If it overflowed, fill field with max value. */
|
|
721
|
+
while (len-- > 0)
|
|
722
|
+
*p++ = '7';
|
|
723
|
+
|
|
724
|
+
return (-1);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
static int
|
|
728
|
+
archive_write_ustar_close(struct archive_write *a)
|
|
729
|
+
{
|
|
730
|
+
return (__archive_write_nulls(a, 512*2));
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
static int
|
|
734
|
+
archive_write_ustar_free(struct archive_write *a)
|
|
735
|
+
{
|
|
736
|
+
struct ustar *ustar = a->format_data;
|
|
737
|
+
|
|
738
|
+
free(ustar);
|
|
739
|
+
a->format_data = NULL;
|
|
740
|
+
return (ARCHIVE_OK);
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
static int
|
|
744
|
+
archive_write_ustar_finish_entry(struct archive_write *a)
|
|
745
|
+
{
|
|
746
|
+
struct ustar *ustar = a->format_data;
|
|
747
|
+
int ret;
|
|
748
|
+
|
|
749
|
+
ret = __archive_write_nulls(a,
|
|
750
|
+
ustar->entry_bytes_remaining + ustar->entry_padding);
|
|
751
|
+
ustar->entry_bytes_remaining = ustar->entry_padding = 0;
|
|
752
|
+
return (ret);
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
static ssize_t
|
|
756
|
+
archive_write_ustar_data(struct archive_write *a, const void *buff, size_t s)
|
|
757
|
+
{
|
|
758
|
+
struct ustar *ustar = a->format_data;
|
|
759
|
+
int ret;
|
|
760
|
+
|
|
761
|
+
if (s > ustar->entry_bytes_remaining)
|
|
762
|
+
s = (size_t)ustar->entry_bytes_remaining;
|
|
763
|
+
ret = __archive_write_output(a, buff, s);
|
|
764
|
+
ustar->entry_bytes_remaining -= s;
|
|
765
|
+
if (ret != ARCHIVE_OK)
|
|
766
|
+
return (ret);
|
|
767
|
+
return (s);
|
|
768
|
+
}
|