read.c (311041) | read.c (315432) |
---|---|
1/*- 2 * Copyright (c) 2003-2007 Tim Kientzle 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 10 unchanged lines hidden (view full) --- 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#include "bsdtar_platform.h" | 1/*- 2 * Copyright (c) 2003-2007 Tim Kientzle 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 10 unchanged lines hidden (view full) --- 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#include "bsdtar_platform.h" |
27__FBSDID("$FreeBSD: stable/11/contrib/libarchive/tar/read.c 311041 2017-01-02 01:41:31Z mm $"); | 27__FBSDID("$FreeBSD: stable/11/contrib/libarchive/tar/read.c 315432 2017-03-16 23:07:35Z mm $"); |
28 29#ifdef HAVE_SYS_TYPES_H 30#include <sys/types.h> 31#endif 32#ifdef HAVE_SYS_PARAM_H 33#include <sys/param.h> 34#endif 35#ifdef HAVE_SYS_STAT_H --- 64 unchanged lines hidden (view full) --- 100void 101tar_mode_x(struct bsdtar *bsdtar) 102{ 103 struct archive *writer; 104 105 writer = archive_write_disk_new(); 106 if (writer == NULL) 107 lafe_errc(1, ENOMEM, "Cannot allocate disk writer object"); | 28 29#ifdef HAVE_SYS_TYPES_H 30#include <sys/types.h> 31#endif 32#ifdef HAVE_SYS_PARAM_H 33#include <sys/param.h> 34#endif 35#ifdef HAVE_SYS_STAT_H --- 64 unchanged lines hidden (view full) --- 100void 101tar_mode_x(struct bsdtar *bsdtar) 102{ 103 struct archive *writer; 104 105 writer = archive_write_disk_new(); 106 if (writer == NULL) 107 lafe_errc(1, ENOMEM, "Cannot allocate disk writer object"); |
108 if (!bsdtar->option_numeric_owner) | 108 if ((bsdtar->flags & OPTFLAG_NUMERIC_OWNER) == 0) |
109 archive_write_disk_set_standard_lookup(writer); 110 archive_write_disk_set_options(writer, bsdtar->extract_flags); 111 112 read_archive(bsdtar, 'x', writer); 113 114 if (unmatched_inclusions_warn(bsdtar->matching, 115 "Not found in archive") != 0) 116 bsdtar->return_value = 1; --- 55 unchanged lines hidden (view full) --- 172 lafe_errc(1, 0, "Error inclusion pattern: %s", 173 archive_error_string(bsdtar->matching)); 174 bsdtar->argv++; 175 } 176 177 if (bsdtar->names_from_file != NULL) 178 if (archive_match_include_pattern_from_file( 179 bsdtar->matching, bsdtar->names_from_file, | 109 archive_write_disk_set_standard_lookup(writer); 110 archive_write_disk_set_options(writer, bsdtar->extract_flags); 111 112 read_archive(bsdtar, 'x', writer); 113 114 if (unmatched_inclusions_warn(bsdtar->matching, 115 "Not found in archive") != 0) 116 bsdtar->return_value = 1; --- 55 unchanged lines hidden (view full) --- 172 lafe_errc(1, 0, "Error inclusion pattern: %s", 173 archive_error_string(bsdtar->matching)); 174 bsdtar->argv++; 175 } 176 177 if (bsdtar->names_from_file != NULL) 178 if (archive_match_include_pattern_from_file( 179 bsdtar->matching, bsdtar->names_from_file, |
180 bsdtar->option_null) != ARCHIVE_OK) | 180 (bsdtar->flags & OPTFLAG_NULL)) != ARCHIVE_OK) |
181 lafe_errc(1, 0, "Error inclusion pattern: %s", 182 archive_error_string(bsdtar->matching)); 183 184 a = archive_read_new(); 185 if (cset_read_support_filter_program(bsdtar->cset, a) == 0) 186 archive_read_support_filter_all(a); 187 archive_read_support_format_all(a); 188 --- 14 unchanged lines hidden (view full) --- 203 free(p); 204 if (r == ARCHIVE_FATAL) 205 lafe_errc(1, 0, "%s", archive_error_string(a)); 206 else 207 archive_clear_error(a); 208 } 209 if (ARCHIVE_OK != archive_read_set_options(a, bsdtar->option_options)) 210 lafe_errc(1, 0, "%s", archive_error_string(a)); | 181 lafe_errc(1, 0, "Error inclusion pattern: %s", 182 archive_error_string(bsdtar->matching)); 183 184 a = archive_read_new(); 185 if (cset_read_support_filter_program(bsdtar->cset, a) == 0) 186 archive_read_support_filter_all(a); 187 archive_read_support_format_all(a); 188 --- 14 unchanged lines hidden (view full) --- 203 free(p); 204 if (r == ARCHIVE_FATAL) 205 lafe_errc(1, 0, "%s", archive_error_string(a)); 206 else 207 archive_clear_error(a); 208 } 209 if (ARCHIVE_OK != archive_read_set_options(a, bsdtar->option_options)) 210 lafe_errc(1, 0, "%s", archive_error_string(a)); |
211 if (bsdtar->option_ignore_zeros) | 211 if (bsdtar->flags & OPTFLAG_IGNORE_ZEROS) |
212 if (archive_read_set_options(a, 213 "read_concatenated_archives") != ARCHIVE_OK) 214 lafe_errc(1, 0, "%s", archive_error_string(a)); 215 if (bsdtar->passphrase != NULL) 216 r = archive_read_add_passphrase(a, bsdtar->passphrase); 217 else 218 r = archive_read_set_passphrase_callback(a, bsdtar, 219 &passphrase_callback); --- 9 unchanged lines hidden (view full) --- 229 if (mode == 'x') { 230 /* Set an extract callback so that we can handle SIGINFO. */ 231 progress_data.bsdtar = bsdtar; 232 progress_data.archive = a; 233 archive_read_extract_set_progress_callback(a, progress_func, 234 &progress_data); 235 } 236 | 212 if (archive_read_set_options(a, 213 "read_concatenated_archives") != ARCHIVE_OK) 214 lafe_errc(1, 0, "%s", archive_error_string(a)); 215 if (bsdtar->passphrase != NULL) 216 r = archive_read_add_passphrase(a, bsdtar->passphrase); 217 else 218 r = archive_read_set_passphrase_callback(a, bsdtar, 219 &passphrase_callback); --- 9 unchanged lines hidden (view full) --- 229 if (mode == 'x') { 230 /* Set an extract callback so that we can handle SIGINFO. */ 231 progress_data.bsdtar = bsdtar; 232 progress_data.archive = a; 233 archive_read_extract_set_progress_callback(a, progress_func, 234 &progress_data); 235 } 236 |
237 if (mode == 'x' && bsdtar->option_chroot) { | 237 if (mode == 'x' && (bsdtar->flags & OPTFLAG_CHROOT)) { |
238#if HAVE_CHROOT 239 if (chroot(".") != 0) 240 lafe_errc(1, errno, "Can't chroot to \".\""); 241#else 242 lafe_errc(1, 0, 243 "chroot isn't supported on this platform"); 244#endif 245 } 246 247#if defined(_WIN32) && !defined(__CYGWIN__) | 238#if HAVE_CHROOT 239 if (chroot(".") != 0) 240 lafe_errc(1, errno, "Can't chroot to \".\""); 241#else 242 lafe_errc(1, 0, 243 "chroot isn't supported on this platform"); 244#endif 245 } 246 247#if defined(_WIN32) && !defined(__CYGWIN__) |
248 if (mode == 'x' && bsdtar->option_stdout) { | 248 if (mode == 'x' && (bsdtar->flags & OPTFLAG_STDOUT)) { |
249 _setmode(1, _O_BINARY); 250 } 251#endif 252 253 for (;;) { 254 /* Support --fast-read option */ 255 const char *p; | 249 _setmode(1, _O_BINARY); 250 } 251#endif 252 253 for (;;) { 254 /* Support --fast-read option */ 255 const char *p; |
256 if (bsdtar->option_fast_read && | 256 if ((bsdtar->flags & OPTFLAG_FAST_READ) && |
257 archive_match_path_unmatched_inclusions(bsdtar->matching) == 0) 258 break; 259 260 r = archive_read_next_header(a, &entry); 261 progress_data.entry = entry; 262 if (r == ARCHIVE_EOF) 263 break; 264 if (r < ARCHIVE_OK) --- 37 unchanged lines hidden (view full) --- 302 * while allowing foo2/bar.) 303 */ 304 if (archive_match_excluded(bsdtar->matching, entry)) 305 continue; /* Excluded by a pattern test. */ 306 307 if (mode == 't') { 308 /* Perversely, gtar uses -O to mean "send to stderr" 309 * when used with -t. */ | 257 archive_match_path_unmatched_inclusions(bsdtar->matching) == 0) 258 break; 259 260 r = archive_read_next_header(a, &entry); 261 progress_data.entry = entry; 262 if (r == ARCHIVE_EOF) 263 break; 264 if (r < ARCHIVE_OK) --- 37 unchanged lines hidden (view full) --- 302 * while allowing foo2/bar.) 303 */ 304 if (archive_match_excluded(bsdtar->matching, entry)) 305 continue; /* Excluded by a pattern test. */ 306 307 if (mode == 't') { 308 /* Perversely, gtar uses -O to mean "send to stderr" 309 * when used with -t. */ |
310 out = bsdtar->option_stdout ? stderr : stdout; | 310 out = (bsdtar->flags & OPTFLAG_STDOUT) ? 311 stderr : stdout; |
311 312 /* 313 * TODO: Provide some reasonable way to 314 * preview rewrites. gtar always displays 315 * the unedited path in -t output, which means 316 * you cannot easily preview rewrites. 317 */ 318 if (bsdtar->verbose < 2) --- 21 unchanged lines hidden (view full) --- 340 break; 341 } 342 fprintf(out, "\n"); 343 } else { 344 /* Note: some rewrite failures prevent extraction. */ 345 if (edit_pathname(bsdtar, entry)) 346 continue; /* Excluded by a rewrite failure. */ 347 | 312 313 /* 314 * TODO: Provide some reasonable way to 315 * preview rewrites. gtar always displays 316 * the unedited path in -t output, which means 317 * you cannot easily preview rewrites. 318 */ 319 if (bsdtar->verbose < 2) --- 21 unchanged lines hidden (view full) --- 341 break; 342 } 343 fprintf(out, "\n"); 344 } else { 345 /* Note: some rewrite failures prevent extraction. */ 346 if (edit_pathname(bsdtar, entry)) 347 continue; /* Excluded by a rewrite failure. */ 348 |
348 if (bsdtar->option_interactive && | 349 if ((bsdtar->flags & OPTFLAG_INTERACTIVE) && |
349 !yes("extract '%s'", archive_entry_pathname(entry))) 350 continue; 351 352 if (bsdtar->verbose > 1) { 353 /* GNU tar uses -tv format with -xvv */ 354 safe_fprintf(stderr, "x "); 355 list_item_verbose(bsdtar, stderr, entry); 356 fflush(stderr); 357 } else if (bsdtar->verbose > 0) { 358 /* Format follows SUSv2, including the 359 * deferred '\n'. */ 360 safe_fprintf(stderr, "x %s", 361 archive_entry_pathname(entry)); 362 fflush(stderr); 363 } 364 365 /* TODO siginfo_printinfo(bsdtar, 0); */ 366 | 350 !yes("extract '%s'", archive_entry_pathname(entry))) 351 continue; 352 353 if (bsdtar->verbose > 1) { 354 /* GNU tar uses -tv format with -xvv */ 355 safe_fprintf(stderr, "x "); 356 list_item_verbose(bsdtar, stderr, entry); 357 fflush(stderr); 358 } else if (bsdtar->verbose > 0) { 359 /* Format follows SUSv2, including the 360 * deferred '\n'. */ 361 safe_fprintf(stderr, "x %s", 362 archive_entry_pathname(entry)); 363 fflush(stderr); 364 } 365 366 /* TODO siginfo_printinfo(bsdtar, 0); */ 367 |
367 if (bsdtar->option_stdout) | 368 if (bsdtar->flags & OPTFLAG_STDOUT) |
368 r = archive_read_data_into_fd(a, 1); 369 else 370 r = archive_read_extract2(a, entry, writer); 371 if (r != ARCHIVE_OK) { 372 if (!bsdtar->verbose) 373 safe_fprintf(stderr, "%s", 374 archive_entry_pathname(entry)); 375 safe_fprintf(stderr, ": %s", --- 44 unchanged lines hidden --- | 369 r = archive_read_data_into_fd(a, 1); 370 else 371 r = archive_read_extract2(a, entry, writer); 372 if (r != ARCHIVE_OK) { 373 if (!bsdtar->verbose) 374 safe_fprintf(stderr, "%s", 375 archive_entry_pathname(entry)); 376 safe_fprintf(stderr, ": %s", --- 44 unchanged lines hidden --- |