@papyrus-sdk/engine-native 0.2.22-beta.2 → 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 +116 -9
- 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,650 @@
|
|
|
1
|
+
/*-
|
|
2
|
+
* Copyright (c) 2003-2007 Tim Kientzle
|
|
3
|
+
* Copyright (c) 2008 Joerg Sonnenberger
|
|
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_endian.h"
|
|
42
|
+
#include "archive_entry.h"
|
|
43
|
+
#include "archive_private.h"
|
|
44
|
+
#include "archive_write_private.h"
|
|
45
|
+
#include "archive_write_set_format_private.h"
|
|
46
|
+
|
|
47
|
+
struct shar {
|
|
48
|
+
int dump;
|
|
49
|
+
int end_of_line;
|
|
50
|
+
struct archive_entry *entry;
|
|
51
|
+
int has_data;
|
|
52
|
+
char *last_dir;
|
|
53
|
+
|
|
54
|
+
/* Line buffer for uuencoded dump format */
|
|
55
|
+
char outbuff[45];
|
|
56
|
+
size_t outpos;
|
|
57
|
+
|
|
58
|
+
int wrote_header;
|
|
59
|
+
struct archive_string work;
|
|
60
|
+
struct archive_string quoted_name;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
static int archive_write_shar_close(struct archive_write *);
|
|
64
|
+
static int archive_write_shar_free(struct archive_write *);
|
|
65
|
+
static int archive_write_shar_header(struct archive_write *,
|
|
66
|
+
struct archive_entry *);
|
|
67
|
+
static ssize_t archive_write_shar_data_sed(struct archive_write *,
|
|
68
|
+
const void * buff, size_t);
|
|
69
|
+
static ssize_t archive_write_shar_data_uuencode(struct archive_write *,
|
|
70
|
+
const void * buff, size_t);
|
|
71
|
+
static int archive_write_shar_finish_entry(struct archive_write *);
|
|
72
|
+
|
|
73
|
+
/*
|
|
74
|
+
* Copy the given string to the buffer, quoting all shell meta characters
|
|
75
|
+
* found.
|
|
76
|
+
*/
|
|
77
|
+
static void
|
|
78
|
+
shar_quote(struct archive_string *buf, const char *str, int in_shell)
|
|
79
|
+
{
|
|
80
|
+
static const char meta[] = "\n \t'`\";&<>()|*?{}[]\\$!#^~";
|
|
81
|
+
size_t len;
|
|
82
|
+
|
|
83
|
+
while (*str != '\0') {
|
|
84
|
+
if ((len = strcspn(str, meta)) != 0) {
|
|
85
|
+
archive_strncat(buf, str, len);
|
|
86
|
+
str += len;
|
|
87
|
+
} else if (*str == '\n') {
|
|
88
|
+
if (in_shell)
|
|
89
|
+
archive_strcat(buf, "\"\n\"");
|
|
90
|
+
else
|
|
91
|
+
archive_strcat(buf, "\\n");
|
|
92
|
+
++str;
|
|
93
|
+
} else {
|
|
94
|
+
archive_strappend_char(buf, '\\');
|
|
95
|
+
archive_strappend_char(buf, *str);
|
|
96
|
+
++str;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
static int
|
|
102
|
+
shar_set_format(struct archive *_a, int dump)
|
|
103
|
+
{
|
|
104
|
+
struct archive_write *a = (struct archive_write *)_a;
|
|
105
|
+
struct shar *shar;
|
|
106
|
+
|
|
107
|
+
archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
|
|
108
|
+
ARCHIVE_STATE_NEW, "archive_write_set_format_shar");
|
|
109
|
+
|
|
110
|
+
/* If someone else was already registered, unregister them. */
|
|
111
|
+
(void)__archive_write_unregister_format(a);
|
|
112
|
+
|
|
113
|
+
shar = calloc(1, sizeof(*shar));
|
|
114
|
+
if (shar == NULL) {
|
|
115
|
+
archive_set_error(&a->archive, ENOMEM, "Can't allocate shar data");
|
|
116
|
+
return (ARCHIVE_FATAL);
|
|
117
|
+
}
|
|
118
|
+
archive_string_init(&shar->work);
|
|
119
|
+
archive_string_init(&shar->quoted_name);
|
|
120
|
+
if (dump) {
|
|
121
|
+
shar->dump = 1;
|
|
122
|
+
a->format_write_data = archive_write_shar_data_uuencode;
|
|
123
|
+
a->archive.archive_format = ARCHIVE_FORMAT_SHAR_DUMP;
|
|
124
|
+
a->archive.archive_format_name = "shar dump";
|
|
125
|
+
} else {
|
|
126
|
+
a->format_write_data = archive_write_shar_data_sed;
|
|
127
|
+
a->archive.archive_format = ARCHIVE_FORMAT_SHAR_BASE;
|
|
128
|
+
a->archive.archive_format_name = "shar";
|
|
129
|
+
}
|
|
130
|
+
a->format_data = shar;
|
|
131
|
+
a->format_name = "shar";
|
|
132
|
+
a->format_write_header = archive_write_shar_header;
|
|
133
|
+
a->format_close = archive_write_shar_close;
|
|
134
|
+
a->format_free = archive_write_shar_free;
|
|
135
|
+
a->format_finish_entry = archive_write_shar_finish_entry;
|
|
136
|
+
return (ARCHIVE_OK);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/*
|
|
140
|
+
* Set output format to 'shar' format.
|
|
141
|
+
*/
|
|
142
|
+
int
|
|
143
|
+
archive_write_set_format_shar(struct archive *a)
|
|
144
|
+
{
|
|
145
|
+
return shar_set_format(a, 0);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/*
|
|
149
|
+
* An alternate 'shar' that uses uudecode instead of 'sed' to encode
|
|
150
|
+
* file contents and can therefore be used to archive binary files.
|
|
151
|
+
* In addition, this variant also attempts to restore ownership, file modes,
|
|
152
|
+
* and other extended file information.
|
|
153
|
+
*/
|
|
154
|
+
int
|
|
155
|
+
archive_write_set_format_shar_dump(struct archive *a)
|
|
156
|
+
{
|
|
157
|
+
return shar_set_format(a, 1);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
static int
|
|
161
|
+
archive_write_shar_header(struct archive_write *a, struct archive_entry *entry)
|
|
162
|
+
{
|
|
163
|
+
struct shar *shar = a->format_data;
|
|
164
|
+
const char *linkname;
|
|
165
|
+
const char *name;
|
|
166
|
+
char *p, *pp;
|
|
167
|
+
|
|
168
|
+
if (!shar->wrote_header) {
|
|
169
|
+
archive_strcat(&shar->work, "#!/bin/sh\n");
|
|
170
|
+
archive_strcat(&shar->work, "# This is a shell archive\n");
|
|
171
|
+
shar->wrote_header = 1;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/* Save the entry for the closing. */
|
|
175
|
+
archive_entry_free(shar->entry);
|
|
176
|
+
shar->entry = archive_entry_clone(entry);
|
|
177
|
+
if (shar->entry == NULL) {
|
|
178
|
+
archive_set_error(&a->archive, ENOMEM, "Out of memory");
|
|
179
|
+
return (ARCHIVE_FATAL);
|
|
180
|
+
}
|
|
181
|
+
name = archive_entry_pathname(entry);
|
|
182
|
+
|
|
183
|
+
/* Handle some preparatory issues. */
|
|
184
|
+
switch(archive_entry_filetype(entry)) {
|
|
185
|
+
case AE_IFREG:
|
|
186
|
+
/* Only regular files have non-zero size. */
|
|
187
|
+
break;
|
|
188
|
+
case AE_IFDIR:
|
|
189
|
+
archive_entry_set_size(entry, 0);
|
|
190
|
+
/* Don't bother trying to recreate '.' */
|
|
191
|
+
if (strcmp(name, ".") == 0 || strcmp(name, "./") == 0)
|
|
192
|
+
return (ARCHIVE_OK);
|
|
193
|
+
break;
|
|
194
|
+
case AE_IFIFO:
|
|
195
|
+
case AE_IFCHR:
|
|
196
|
+
case AE_IFBLK:
|
|
197
|
+
/* All other file types have zero size in the archive. */
|
|
198
|
+
archive_entry_set_size(entry, 0);
|
|
199
|
+
break;
|
|
200
|
+
default:
|
|
201
|
+
archive_entry_set_size(entry, 0);
|
|
202
|
+
if (archive_entry_hardlink(entry) == NULL &&
|
|
203
|
+
archive_entry_symlink(entry) == NULL) {
|
|
204
|
+
__archive_write_entry_filetype_unsupported(
|
|
205
|
+
&a->archive, entry, "shar");
|
|
206
|
+
return (ARCHIVE_WARN);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
archive_string_empty(&shar->quoted_name);
|
|
211
|
+
shar_quote(&shar->quoted_name, name, 1);
|
|
212
|
+
|
|
213
|
+
/* Stock preparation for all file types. */
|
|
214
|
+
archive_string_sprintf(&shar->work, "echo x %s\n", shar->quoted_name.s);
|
|
215
|
+
|
|
216
|
+
if (archive_entry_filetype(entry) != AE_IFDIR) {
|
|
217
|
+
/* Try to create the dir. */
|
|
218
|
+
p = strdup(name);
|
|
219
|
+
if (p == NULL) {
|
|
220
|
+
archive_set_error(&a->archive, ENOMEM, "Out of memory");
|
|
221
|
+
return (ARCHIVE_FATAL);
|
|
222
|
+
}
|
|
223
|
+
pp = strrchr(p, '/');
|
|
224
|
+
/* If there is a / character, try to create the dir. */
|
|
225
|
+
if (pp != NULL) {
|
|
226
|
+
*pp = '\0';
|
|
227
|
+
|
|
228
|
+
/* Try to avoid a lot of redundant mkdir commands. */
|
|
229
|
+
if (strcmp(p, ".") == 0) {
|
|
230
|
+
/* Don't try to "mkdir ." */
|
|
231
|
+
free(p);
|
|
232
|
+
} else if (shar->last_dir == NULL) {
|
|
233
|
+
archive_strcat(&shar->work, "mkdir -p ");
|
|
234
|
+
shar_quote(&shar->work, p, 1);
|
|
235
|
+
archive_strcat(&shar->work,
|
|
236
|
+
" > /dev/null 2>&1\n");
|
|
237
|
+
shar->last_dir = p;
|
|
238
|
+
} else if (strcmp(p, shar->last_dir) == 0) {
|
|
239
|
+
/* We've already created this exact dir. */
|
|
240
|
+
free(p);
|
|
241
|
+
} else if (strlen(p) < strlen(shar->last_dir) &&
|
|
242
|
+
strncmp(p, shar->last_dir, strlen(p)) == 0) {
|
|
243
|
+
/* We've already created a subdir. */
|
|
244
|
+
free(p);
|
|
245
|
+
} else {
|
|
246
|
+
archive_strcat(&shar->work, "mkdir -p ");
|
|
247
|
+
shar_quote(&shar->work, p, 1);
|
|
248
|
+
archive_strcat(&shar->work,
|
|
249
|
+
" > /dev/null 2>&1\n");
|
|
250
|
+
free(shar->last_dir);
|
|
251
|
+
shar->last_dir = p;
|
|
252
|
+
}
|
|
253
|
+
} else {
|
|
254
|
+
free(p);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/* Handle file-type specific issues. */
|
|
259
|
+
shar->has_data = 0;
|
|
260
|
+
if ((linkname = archive_entry_hardlink(entry)) != NULL) {
|
|
261
|
+
archive_strcat(&shar->work, "ln -f ");
|
|
262
|
+
shar_quote(&shar->work, linkname, 1);
|
|
263
|
+
archive_string_sprintf(&shar->work, " %s\n",
|
|
264
|
+
shar->quoted_name.s);
|
|
265
|
+
} else if ((linkname = archive_entry_symlink(entry)) != NULL) {
|
|
266
|
+
archive_strcat(&shar->work, "ln -fs ");
|
|
267
|
+
shar_quote(&shar->work, linkname, 1);
|
|
268
|
+
archive_string_sprintf(&shar->work, " %s\n",
|
|
269
|
+
shar->quoted_name.s);
|
|
270
|
+
} else {
|
|
271
|
+
switch(archive_entry_filetype(entry)) {
|
|
272
|
+
case AE_IFREG:
|
|
273
|
+
if (archive_entry_size(entry) == 0) {
|
|
274
|
+
/* More portable than "touch." */
|
|
275
|
+
archive_string_sprintf(&shar->work,
|
|
276
|
+
"test -e \"%s\" || :> \"%s\"\n",
|
|
277
|
+
shar->quoted_name.s, shar->quoted_name.s);
|
|
278
|
+
} else {
|
|
279
|
+
if (shar->dump) {
|
|
280
|
+
unsigned int mode = archive_entry_mode(entry) & 0777;
|
|
281
|
+
archive_string_sprintf(&shar->work,
|
|
282
|
+
"uudecode -p > %s << 'SHAR_END'\n",
|
|
283
|
+
shar->quoted_name.s);
|
|
284
|
+
archive_string_sprintf(&shar->work,
|
|
285
|
+
"begin %o ", mode);
|
|
286
|
+
shar_quote(&shar->work, name, 0);
|
|
287
|
+
archive_strcat(&shar->work, "\n");
|
|
288
|
+
} else {
|
|
289
|
+
archive_string_sprintf(&shar->work,
|
|
290
|
+
"sed 's/^X//' > %s << 'SHAR_END'\n",
|
|
291
|
+
shar->quoted_name.s);
|
|
292
|
+
}
|
|
293
|
+
shar->has_data = 1;
|
|
294
|
+
shar->end_of_line = 1;
|
|
295
|
+
shar->outpos = 0;
|
|
296
|
+
}
|
|
297
|
+
break;
|
|
298
|
+
case AE_IFDIR:
|
|
299
|
+
archive_string_sprintf(&shar->work,
|
|
300
|
+
"mkdir -p %s > /dev/null 2>&1\n",
|
|
301
|
+
shar->quoted_name.s);
|
|
302
|
+
/* Record that we just created this directory. */
|
|
303
|
+
free(shar->last_dir);
|
|
304
|
+
|
|
305
|
+
shar->last_dir = strdup(name);
|
|
306
|
+
if (shar->last_dir == NULL) {
|
|
307
|
+
archive_set_error(&a->archive, ENOMEM, "Out of memory");
|
|
308
|
+
return (ARCHIVE_FATAL);
|
|
309
|
+
}
|
|
310
|
+
/* Trim a trailing '/'. */
|
|
311
|
+
pp = strrchr(shar->last_dir, '/');
|
|
312
|
+
if (pp != NULL && pp[1] == '\0')
|
|
313
|
+
*pp = '\0';
|
|
314
|
+
/*
|
|
315
|
+
* TODO: Put dir name/mode on a list to be fixed
|
|
316
|
+
* up at end of archive.
|
|
317
|
+
*/
|
|
318
|
+
break;
|
|
319
|
+
case AE_IFIFO:
|
|
320
|
+
archive_string_sprintf(&shar->work,
|
|
321
|
+
"mkfifo %s\n", shar->quoted_name.s);
|
|
322
|
+
break;
|
|
323
|
+
case AE_IFCHR:
|
|
324
|
+
archive_string_sprintf(&shar->work,
|
|
325
|
+
"mknod %s c %ju %ju\n", shar->quoted_name.s,
|
|
326
|
+
(uintmax_t)archive_entry_rdevmajor(entry),
|
|
327
|
+
(uintmax_t)archive_entry_rdevminor(entry));
|
|
328
|
+
break;
|
|
329
|
+
case AE_IFBLK:
|
|
330
|
+
archive_string_sprintf(&shar->work,
|
|
331
|
+
"mknod %s b %ju %ju\n", shar->quoted_name.s,
|
|
332
|
+
(uintmax_t)archive_entry_rdevmajor(entry),
|
|
333
|
+
(uintmax_t)archive_entry_rdevminor(entry));
|
|
334
|
+
break;
|
|
335
|
+
default:
|
|
336
|
+
return (ARCHIVE_WARN);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return (ARCHIVE_OK);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
static ssize_t
|
|
344
|
+
archive_write_shar_data_sed(struct archive_write *a, const void *buff, size_t n)
|
|
345
|
+
{
|
|
346
|
+
struct shar *shar = a->format_data;
|
|
347
|
+
static const size_t ensured = 65533;
|
|
348
|
+
const char *src;
|
|
349
|
+
char *buf, *buf_end;
|
|
350
|
+
int ret;
|
|
351
|
+
size_t written = n;
|
|
352
|
+
|
|
353
|
+
if (!shar->has_data || n == 0)
|
|
354
|
+
return (0);
|
|
355
|
+
|
|
356
|
+
src = (const char *)buff;
|
|
357
|
+
|
|
358
|
+
/*
|
|
359
|
+
* ensure is the number of bytes in buffer before expanding the
|
|
360
|
+
* current character. Each operation writes the current character
|
|
361
|
+
* and optionally the start-of-new-line marker. This can happen
|
|
362
|
+
* twice before entering the loop, so make sure three additional
|
|
363
|
+
* bytes can be written.
|
|
364
|
+
*/
|
|
365
|
+
if (archive_string_ensure(&shar->work, ensured + 3) == NULL) {
|
|
366
|
+
archive_set_error(&a->archive, ENOMEM, "Out of memory");
|
|
367
|
+
return (ARCHIVE_FATAL);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (shar->work.length > ensured) {
|
|
371
|
+
ret = __archive_write_output(a, shar->work.s,
|
|
372
|
+
shar->work.length);
|
|
373
|
+
if (ret != ARCHIVE_OK)
|
|
374
|
+
return (ARCHIVE_FATAL);
|
|
375
|
+
archive_string_empty(&shar->work);
|
|
376
|
+
}
|
|
377
|
+
buf = shar->work.s + shar->work.length;
|
|
378
|
+
buf_end = shar->work.s + ensured;
|
|
379
|
+
|
|
380
|
+
if (shar->end_of_line) {
|
|
381
|
+
*buf++ = 'X';
|
|
382
|
+
shar->end_of_line = 0;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
while (n-- != 0) {
|
|
386
|
+
if ((*buf++ = *src++) == '\n') {
|
|
387
|
+
if (n == 0)
|
|
388
|
+
shar->end_of_line = 1;
|
|
389
|
+
else
|
|
390
|
+
*buf++ = 'X';
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
if (buf >= buf_end) {
|
|
394
|
+
shar->work.length = buf - shar->work.s;
|
|
395
|
+
ret = __archive_write_output(a, shar->work.s,
|
|
396
|
+
shar->work.length);
|
|
397
|
+
if (ret != ARCHIVE_OK)
|
|
398
|
+
return (ARCHIVE_FATAL);
|
|
399
|
+
archive_string_empty(&shar->work);
|
|
400
|
+
buf = shar->work.s;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
shar->work.length = buf - shar->work.s;
|
|
405
|
+
|
|
406
|
+
return (written);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
#define UUENC(c) (((c)!=0) ? ((c) & 077) + ' ': '`')
|
|
410
|
+
|
|
411
|
+
static void
|
|
412
|
+
uuencode_group(const char _in[3], char out[4])
|
|
413
|
+
{
|
|
414
|
+
const unsigned char *in = (const unsigned char *)_in;
|
|
415
|
+
uint32_t t;
|
|
416
|
+
|
|
417
|
+
t = archive_be24dec(in);
|
|
418
|
+
out[0] = UUENC( 0x3f & (t >> 18) );
|
|
419
|
+
out[1] = UUENC( 0x3f & (t >> 12) );
|
|
420
|
+
out[2] = UUENC( 0x3f & (t >> 6) );
|
|
421
|
+
out[3] = UUENC( 0x3f & t );
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
static int
|
|
425
|
+
_uuencode_line(struct archive_write *a, struct shar *shar, const char *inbuf, size_t len)
|
|
426
|
+
{
|
|
427
|
+
char *buf;
|
|
428
|
+
size_t alloc_len;
|
|
429
|
+
|
|
430
|
+
/* len <= 45 -> expanded to 60 + len byte + new line */
|
|
431
|
+
alloc_len = shar->work.length + 62;
|
|
432
|
+
if (archive_string_ensure(&shar->work, alloc_len) == NULL) {
|
|
433
|
+
archive_set_error(&a->archive, ENOMEM, "Out of memory");
|
|
434
|
+
return (ARCHIVE_FATAL);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
buf = shar->work.s + shar->work.length;
|
|
438
|
+
*buf++ = UUENC(len);
|
|
439
|
+
while (len >= 3) {
|
|
440
|
+
uuencode_group(inbuf, buf);
|
|
441
|
+
len -= 3;
|
|
442
|
+
inbuf += 3;
|
|
443
|
+
buf += 4;
|
|
444
|
+
}
|
|
445
|
+
if (len != 0) {
|
|
446
|
+
char tmp_buf[3];
|
|
447
|
+
tmp_buf[0] = inbuf[0];
|
|
448
|
+
if (len == 1)
|
|
449
|
+
tmp_buf[1] = '\0';
|
|
450
|
+
else
|
|
451
|
+
tmp_buf[1] = inbuf[1];
|
|
452
|
+
tmp_buf[2] = '\0';
|
|
453
|
+
uuencode_group(tmp_buf, buf);
|
|
454
|
+
buf += 4;
|
|
455
|
+
}
|
|
456
|
+
*buf++ = '\n';
|
|
457
|
+
if ((buf - shar->work.s) > (ptrdiff_t)(shar->work.length + 62)) {
|
|
458
|
+
archive_set_error(&a->archive,
|
|
459
|
+
ARCHIVE_ERRNO_MISC, "Buffer overflow");
|
|
460
|
+
return (ARCHIVE_FATAL);
|
|
461
|
+
}
|
|
462
|
+
shar->work.length = buf - shar->work.s;
|
|
463
|
+
return (ARCHIVE_OK);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
#define uuencode_line(__a, __shar, __inbuf, __len) \
|
|
467
|
+
do { \
|
|
468
|
+
int r = _uuencode_line(__a, __shar, __inbuf, __len); \
|
|
469
|
+
if (r != ARCHIVE_OK) \
|
|
470
|
+
return (ARCHIVE_FATAL); \
|
|
471
|
+
} while (0)
|
|
472
|
+
|
|
473
|
+
static ssize_t
|
|
474
|
+
archive_write_shar_data_uuencode(struct archive_write *a, const void *buff,
|
|
475
|
+
size_t length)
|
|
476
|
+
{
|
|
477
|
+
struct shar *shar = a->format_data;
|
|
478
|
+
const char *src;
|
|
479
|
+
size_t n;
|
|
480
|
+
int ret;
|
|
481
|
+
|
|
482
|
+
if (!shar->has_data)
|
|
483
|
+
return (ARCHIVE_OK);
|
|
484
|
+
src = (const char *)buff;
|
|
485
|
+
|
|
486
|
+
if (shar->outpos != 0) {
|
|
487
|
+
n = 45 - shar->outpos;
|
|
488
|
+
if (n > length)
|
|
489
|
+
n = length;
|
|
490
|
+
memcpy(shar->outbuff + shar->outpos, src, n);
|
|
491
|
+
if (shar->outpos + n < 45) {
|
|
492
|
+
shar->outpos += n;
|
|
493
|
+
return length;
|
|
494
|
+
}
|
|
495
|
+
uuencode_line(a, shar, shar->outbuff, 45);
|
|
496
|
+
src += n;
|
|
497
|
+
n = length - n;
|
|
498
|
+
} else {
|
|
499
|
+
n = length;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
while (n >= 45) {
|
|
503
|
+
uuencode_line(a, shar, src, 45);
|
|
504
|
+
src += 45;
|
|
505
|
+
n -= 45;
|
|
506
|
+
|
|
507
|
+
if (shar->work.length < 65536)
|
|
508
|
+
continue;
|
|
509
|
+
ret = __archive_write_output(a, shar->work.s,
|
|
510
|
+
shar->work.length);
|
|
511
|
+
if (ret != ARCHIVE_OK)
|
|
512
|
+
return (ARCHIVE_FATAL);
|
|
513
|
+
archive_string_empty(&shar->work);
|
|
514
|
+
}
|
|
515
|
+
if (n != 0) {
|
|
516
|
+
memcpy(shar->outbuff, src, n);
|
|
517
|
+
shar->outpos = n;
|
|
518
|
+
}
|
|
519
|
+
return (length);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
static int
|
|
523
|
+
archive_write_shar_finish_entry(struct archive_write *a)
|
|
524
|
+
{
|
|
525
|
+
struct shar *shar = a->format_data;
|
|
526
|
+
const char *g, *p, *u;
|
|
527
|
+
int ret;
|
|
528
|
+
|
|
529
|
+
if (shar->entry == NULL)
|
|
530
|
+
return (ARCHIVE_OK);
|
|
531
|
+
|
|
532
|
+
if (shar->dump) {
|
|
533
|
+
/* Finish uuencoded data. */
|
|
534
|
+
if (shar->has_data) {
|
|
535
|
+
if (shar->outpos > 0)
|
|
536
|
+
uuencode_line(a, shar, shar->outbuff,
|
|
537
|
+
shar->outpos);
|
|
538
|
+
archive_strcat(&shar->work, "`\nend\n");
|
|
539
|
+
archive_strcat(&shar->work, "SHAR_END\n");
|
|
540
|
+
}
|
|
541
|
+
/* Restore file mode, owner, flags. */
|
|
542
|
+
/*
|
|
543
|
+
* TODO: Don't immediately restore mode for
|
|
544
|
+
* directories; defer that to end of script.
|
|
545
|
+
*/
|
|
546
|
+
archive_string_sprintf(&shar->work, "chmod %o ",
|
|
547
|
+
(unsigned int)(archive_entry_mode(shar->entry) & 07777));
|
|
548
|
+
shar_quote(&shar->work, archive_entry_pathname(shar->entry), 1);
|
|
549
|
+
archive_strcat(&shar->work, "\n");
|
|
550
|
+
|
|
551
|
+
u = archive_entry_uname(shar->entry);
|
|
552
|
+
g = archive_entry_gname(shar->entry);
|
|
553
|
+
if (u != NULL || g != NULL) {
|
|
554
|
+
archive_strcat(&shar->work, "chown ");
|
|
555
|
+
if (u != NULL)
|
|
556
|
+
shar_quote(&shar->work, u, 1);
|
|
557
|
+
if (g != NULL) {
|
|
558
|
+
archive_strcat(&shar->work, ":");
|
|
559
|
+
shar_quote(&shar->work, g, 1);
|
|
560
|
+
}
|
|
561
|
+
archive_strcat(&shar->work, " ");
|
|
562
|
+
shar_quote(&shar->work,
|
|
563
|
+
archive_entry_pathname(shar->entry), 1);
|
|
564
|
+
archive_strcat(&shar->work, "\n");
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if ((p = archive_entry_fflags_text(shar->entry)) != NULL) {
|
|
568
|
+
archive_string_sprintf(&shar->work, "chflags %s ", p);
|
|
569
|
+
shar_quote(&shar->work,
|
|
570
|
+
archive_entry_pathname(shar->entry), 1);
|
|
571
|
+
archive_strcat(&shar->work, "\n");
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/* TODO: restore ACLs */
|
|
575
|
+
|
|
576
|
+
} else {
|
|
577
|
+
if (shar->has_data) {
|
|
578
|
+
/* Finish sed-encoded data: ensure last line ends. */
|
|
579
|
+
if (!shar->end_of_line)
|
|
580
|
+
archive_strappend_char(&shar->work, '\n');
|
|
581
|
+
archive_strcat(&shar->work, "SHAR_END\n");
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
archive_entry_free(shar->entry);
|
|
586
|
+
shar->entry = NULL;
|
|
587
|
+
|
|
588
|
+
if (shar->work.length < 65536)
|
|
589
|
+
return (ARCHIVE_OK);
|
|
590
|
+
|
|
591
|
+
ret = __archive_write_output(a, shar->work.s, shar->work.length);
|
|
592
|
+
if (ret != ARCHIVE_OK)
|
|
593
|
+
return (ARCHIVE_FATAL);
|
|
594
|
+
archive_string_empty(&shar->work);
|
|
595
|
+
|
|
596
|
+
return (ARCHIVE_OK);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
static int
|
|
600
|
+
archive_write_shar_close(struct archive_write *a)
|
|
601
|
+
{
|
|
602
|
+
struct shar *shar = a->format_data;
|
|
603
|
+
int ret;
|
|
604
|
+
|
|
605
|
+
/*
|
|
606
|
+
* TODO: Accumulate list of directory names/modes and
|
|
607
|
+
* fix them all up at end-of-archive.
|
|
608
|
+
*/
|
|
609
|
+
|
|
610
|
+
/*
|
|
611
|
+
* Only write the end-of-archive markers if the archive was
|
|
612
|
+
* actually started. This avoids problems if someone sets
|
|
613
|
+
* shar format, then sets another format (which would invoke
|
|
614
|
+
* shar_finish to free the format-specific data).
|
|
615
|
+
*/
|
|
616
|
+
if (shar->wrote_header == 0)
|
|
617
|
+
return (ARCHIVE_OK);
|
|
618
|
+
|
|
619
|
+
archive_strcat(&shar->work, "exit\n");
|
|
620
|
+
|
|
621
|
+
ret = __archive_write_output(a, shar->work.s, shar->work.length);
|
|
622
|
+
if (ret != ARCHIVE_OK)
|
|
623
|
+
return (ARCHIVE_FATAL);
|
|
624
|
+
|
|
625
|
+
/* Shar output is never padded. */
|
|
626
|
+
archive_write_set_bytes_in_last_block(&a->archive, 1);
|
|
627
|
+
/*
|
|
628
|
+
* TODO: shar should also suppress padding of
|
|
629
|
+
* uncompressed data within gzip/bzip2 streams.
|
|
630
|
+
*/
|
|
631
|
+
|
|
632
|
+
return (ARCHIVE_OK);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
static int
|
|
636
|
+
archive_write_shar_free(struct archive_write *a)
|
|
637
|
+
{
|
|
638
|
+
struct shar *shar = a->format_data;
|
|
639
|
+
|
|
640
|
+
if (shar == NULL)
|
|
641
|
+
return (ARCHIVE_OK);
|
|
642
|
+
|
|
643
|
+
archive_entry_free(shar->entry);
|
|
644
|
+
free(shar->last_dir);
|
|
645
|
+
archive_string_free(&(shar->work));
|
|
646
|
+
archive_string_free(&(shar->quoted_name));
|
|
647
|
+
free(shar);
|
|
648
|
+
a->format_data = NULL;
|
|
649
|
+
return (ARCHIVE_OK);
|
|
650
|
+
}
|