778 Commits

Author SHA1 Message Date
Collin Funk
2737e1aec0 maint: Update library names used by Gnulib.
* src/Makefile.am (tar_LDADD):
* tests/Makefile.am (LDADD): Update library names according to Gnulib.

Copyright-paperwork-exempt: yes
2025-08-19 21:12:59 -07:00
Paul Eggert
ca02de4050 Avoid overrun when converting ns-resolution timestamps to text
Caught by gcc -fsanitize=address.
Inspired by Matthias Andree’s bug report in:
https://lists.gnu.org/r/bug-tar/2025-08/msg00019.html
though I found this bug via a simple "make check"
with sanitization enabled.
* src/common.h (TIMESPEC_STRSIZE_BOUND):
Make room for leading '-', needed in addition to the '-' room
supplied by SYSINT_BUFSIZE due to the way code_timespec works.
2025-08-18 17:14:49 -07:00
Paul Eggert
ea7cfcba77 Avoid hash_meta_directory int overflow
* src/incremen.c (hash_directory_meta):
Avoid possibility of signed integer overflow.
2025-08-14 10:27:28 -07:00
Paul Eggert
bdc442bd5c Use Gnulib’s same-inode module
This is more portable to non-POSIX systems.
However, don’t bother trying to port to systems
where st_ino is not a scalar of type dev_t,
as these systems no longer seem to be active targets
and it’s not worth the maintenance hassle.
* gnulib.modules: Add same-inode, now that we use it
explicitly rather than indirectly.
* src/compare.c (diff_link):
* src/create.c (compare_links, restore_parent_fd):
* src/incremen.c (compare_directory_meta, procdir):
* src/extract.c (dl_compare, repair_delayed_set_stat)
(apply_nonancestor_delayed_set_stat, extract_link)
(apply_delayed_link):
* src/names.c (add_file_id):
* src/system.c (sys_file_is_archive, sys_detect_dev_null_output):
Include same-inode.h, and prefer its macros and functions
to doing things by hand.
* src/create.c (struct link):
* src/extract.c (struct delayed_set_stat, struct delayed_link):
* src/incremen.c (struct directory):
* src/names.c (struct file_id_list):
Rename members to st_dev and st_ino so that SAME_INODE and
PSAME_INODE can be used on the type.  All uses changed.
* src/system.c (sys_compare_links): Remove.
All uses replaced by psame_inode.
2025-08-14 10:27:28 -07:00
Collin Funk
5402831d62 manual: remove '.info' suffix in manual names passed to @xref
Texinfo 7.2 began warning about the '.info' suffix in the manual names
passed to @xref and similar commands.  They eventually plan to stop
stripping the '.info' suffix internally which will lead to broken links
in the manuals without this change.

* doc/tar.texi (files): Remove '.info' suffix from manual name.
2025-08-07 23:56:50 -07:00
Paul Eggert
4e742fc867 --no-overwrite-dir no overwrite even temporarily
Problem and fix reported by Pavel Cahyna in
https://lists.gnu.org/r/bug-tar/2025-01/msg00000.html
* src/extract.c (extract_dir): With --no-overwrite-dir,
skip the chmod if the directory already exists.
* tests/extrac23.at (--no-overwrite-dir on empty directory):
Move the part of the test that looks at a nonempty directory ...
* tests/extrac30.at: ... to this new file, because the test now
must be run as non-root.  Adjust the test to match the new behavior.
* tests/Makefile.am (TESTSUITE_AT), tests/testsuite.at: Add it.
2025-07-26 21:49:20 -07:00
Paul Eggert
076818f8d9 Use flexible array member in struct dumpdir
* src/incremen.c: Include flexmember.h.
(struct dumpdir): contents is now a flexible member, not a pointer.
This is more idiomatic and slightly more efficient.
(dumpdir_create0): Adjust to the new struct dumpdir layout.
2025-07-26 02:20:53 -07:00
Paul Eggert
c11084bcc2 Avoid undefined behavior in magic checking
* src/buffer.c (check_compressed_archive):
* src/list.c (read_header, decode_header):
Use memcmp, not strcmp, when looking for magic strings in
headers, since input headers are not guaranteed to be
strings and strcmp has undefined behavior otherwise.
2025-07-26 02:20:53 -07:00
Paul Eggert
75735940f1 Port more code to UBSan, and fix alignment bug
Problem with extract_file reported by Kirill Furman in:
https://lists.gnu.org/r/bug-tar/2025-07/msg00003.html
Since the UBSan thing seems to be a recurring issue,
I fixed other instances of the problem that I found.
Also, I noticed that the same line of code had another failure to
conform to C23’s rules for pointers (an alignment issue not caught
by UBSan), so I fixed that too.  None of these issues matter on
practical production hosts.
* src/common.h (charptr): New function.
* src/buffer.c (available_space_after, short_read, flush_archive)
(backspace_output, try_new_volume, simple_flush_read)
(_gnu_flush_read, _gnu_flush_write):
* src/compare.c (read_and_process):
* src/create.c (write_eot, write_gnu_long_link)
(dump_regular_file, dump_dir0):
* src/extract.c (extract_file):
* src/incremen.c (get_gnu_dumpdir):
* src/list.c (read_header):
* src/sparse.c (sparse_dump_region, sparse_extract_region):
* src/system.c (sys_write_archive_buffer)
(sys_child_open_for_compress, sys_child_open_for_uncompress):
* src/update.c (append_file, update_archive):
Use it.
* src/buffer.c (set_next_block_after): Arg is now void *,
not union block *, since it need not be a valid union block * pointer
and this can matter on unusual or debugging implementations.
Turn a loop into an if so that the code is O(1) not O(N).
2025-07-26 02:20:53 -07:00
Paul Eggert
8921131877 Pacify gcc -Wunterminated-string-initialization
This diagnostic is new to GCC 15.
* src/create.c (cachedir_file_p): Mark local as nonstring.
2025-07-14 08:17:12 -07:00
Paul Eggert
aecf7146d3 Sync bootstrap from Gnulib 2025-06-20 14:17:04 -07:00
Paul Eggert
1ad538b359 build: update gnulib and paxutils submodules to latest 2025-06-20 14:17:04 -07:00
Paul Eggert
7d96e820a5 Port short_read to UBSan
Problem reported by Kirill Furman in:
https://lists.gnu.org/r/bug-tar/2025-06/msg00002.html
* src/buffer.c (short_read): Use (char *) record_start,
instead of record_start->buffer, to avoid undefined behavior
accessing past end of buffer.  In practice the undefined
behavior is harmless unless running with -fsanitize=undefined
or a similarly-picky implementation.
2025-06-12 00:21:48 -07:00
Sergey Poznyakoff
7c4f8fb579 Bugfix
* src/names.c (all_names_found): Exempt wildcard entries from hierarchy
checking.
2025-06-02 07:35:46 +03:00
Sergey Poznyakoff
4303066730 Fix spurious "Not found in archive" errors.
* src/names.c (namelist_match_from): New function.
(namelist_match): Rewrite as a wrapper over it.
(register_match): New function.
(name_match)" Update all possible matches in the name list.

* tests/extrac29.at: New test.
* tests/Makefile.am: Add new test.
* tests/testsuite.at: Likewise.
2025-05-14 15:28:55 +03:00
Sergey Poznyakoff
9324b472b0 Minor changes 2025-05-13 17:59:15 +03:00
Sergey Poznyakoff
b009124ffd Handle directory members consistently when listing and when extracting.
* src/list.c (skim_member): Recognize directory members using
the same rules as during extraction.
* tests/skipdir.at: New testcase.
* tests/testsuite.at: Add new test.
* tests/Makefile.am: Likewise.
2025-05-12 17:20:27 +03:00
Anssi Hannula
827dde1605 Fix missing type in mknodat() mode argument
Per POSIX, the type of the file to be created should be OR'ed to the
`mode` argument of mknodat().

However, set_xattr() creates an empty file using mknodat() and does not
do that.

E.g. Linux kernel considers zero type as S_IFREG, so the code works on
most systems.

However, e.g. fakeroot, at least up to the current v1.36, does not
consider 0 as S_IFREG, instead creating an invalid file, causing tar to
enter an infinite retry loop when trying to create a file with xattrs
under fakeroot.

Since set_xattr is used only when extracting regular files, fix that
by ORing its mode argument with S_IFREG.

Copyright-paperwork-exempt: Yes
2025-05-12 13:18:21 +03:00
Tobias Stoeckmann
65228e9ba9 Fix typos
Copyright-paperwork-exempt: Yes
2025-05-12 11:23:21 +03:00
xiangjingsi
e36d3354c7 Fix restoring extended attributes from global PAX headers
Copyright-paperwork-exempt: Yes
2025-05-08 22:58:15 +03:00
Sergey Poznyakoff
d175e21b7f Upgrade paxutils. 2025-05-07 08:33:23 +03:00
Sergey Poznyakoff
c0fce47363 Fix typo 2025-05-06 22:40:02 +03:00
Sergey Poznyakoff
807e340ab2 Minor fix
* src/extract.c (set_mode): Re-stat the file if current_mode_mask
bits tell so.
2025-05-06 22:29:29 +03:00
Sergey Poznyakoff
6131dd2805 Skip file or archive member if its transformed name is empty.
* NEWS: Document changes.
* doc/tar.texi: Document changes.
* src/common.h (transform_stat_info): Change return value.
(transform_name_fp): Change signature.
(WARN_EMPTY_TRANSFORM): New constant.
* src/create.c: Check return from transform_name.  Skip file, if it
is false.
* src/list.c (transform_stat_info): Return bool.
(read_and): Skip member if transform_stat_info returns false.
* src/transform.c (_transform_name_to_obstack): Change return type.
Always allocate result in obstack.
(transform_name_fp): Change arguments.  Return true on
success (transformed string not empty).  Otherwise return false and
don't change the source string.
* src/warning.c: New warning class: empty-transform.
* tests/extrac17.at: Use --warning=empty-transform.
2025-05-06 15:32:17 +03:00
Sergey Poznyakoff
bfc3346394 Minor fix
* src/list.c (transform_stat_info): Modify argument pointer,
not the global variable.
2025-05-06 09:39:38 +03:00
Paul Eggert
b5f4948ce4 Port to recent Gnulib hash_remove
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-tar/2025-04/msg00003.html
* src/incremen.c (remove_directory): hash_delete → hash_remove.
2025-04-29 14:05:59 -07:00
Sergey Poznyakoff
cd1f6624f7 Fix restoring permissions of intermediate directories with --skip-old-files
Detailed bug report: https://savannah.gnu.org/bugs/index.php?66774

* src/extract.c (update_interdir_set_stat): New function.
(extract_dir): If the directory already exists, check if it
has been created as intermediate directory earlier.  If so,
update its delayed_set_stat data from archive.

* tests/Makefile.am: Add new testcase.
* tests/testsuite.at: Add new testcase.
* tests/extrac28.at: New file.
2025-03-14 15:07:27 +02:00
Sergey Poznyakoff
55ecb28315 documentation: remove incorrect statement
Reported in https://savannah.gnu.org/bugs/index.php?66704
2025-03-14 09:10:01 +02:00
Paul Eggert
31d84e2f67 doc: mention timestamp limits 2025-01-29 11:56:59 -08:00
Paul Eggert
2e41cdce6d Adjust to recent Gnulib module renaming
* gnulib.modules: stdbool was renamed to bool, etc.
2025-01-01 18:33:10 -08:00
Paul Eggert
ff9d7ec77b build: update gnulib and paxutils submodules to latest 2025-01-01 18:33:10 -08:00
Paul Eggert
4a9a4c16e1 doc: fix man page copyright notice
* doc/tar.1: Put copyright notice where the update procedure
will update it properly, and fix it.
2025-01-01 18:33:10 -08:00
Paul Eggert
0aa991f386 Update copyright years
UPDATE_COPYRIGHT_USE_INTERVALS=1 \
$HOME/src/gnu/gnulib/build-aux/update-copyright \
  $(git ls-files | sed -e '/^gnulib$/d
			   /^paxutils$/d
			   /^COPYING$/d
			   /\/fdl.texi$/d')
sed -i '2000,${
    /^Copyright @copyright/d
    s/^[0-9]*--\(2025 Free Software Foundation, Inc.\)/Copyright (C) \1/
  }' doc/tar.texi
2025-01-01 18:33:10 -08:00
Paul Eggert
53f7e6aa62 tests: port to test dirs where pwd != pwd -P
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-tar/2024-12/msg00003.html
* tests/incr08.at: Use pwd -P, not plain pwd.
2024-12-27 14:06:14 -08:00
Paul Eggert
c3f93039ca tests: port to testing in Linux /tmp
* tests/selnx01.at: Discard restorecon output,
as it contains "Warning no default label for ..."
when run in Linux tmpfs on Fedora 40.
2024-12-27 14:06:14 -08:00
Paul Eggert
d2b6b7b0a7 Fix bad pointer usage in xsparse.c
* scripts/xsparse.c (read_xheader): Avoid undefined behavior by
accessing via null pointer sparse_map or out of its bounds when
the input is invalid.  This means we no longer need the ‘expect’
local, so omit it for simplicity.
2024-11-06 10:18:55 -08:00
Paul Eggert
9bbcac1cf7 Port xsparse.c to AIX
* scripts/xsparse.c (emalloc): Do not report failure when malloc
(0) returns NULL, as it does on AIX.  Simply return a null
pointer; that’s good enough for xsparse.c.
2024-11-06 10:18:55 -08:00
Paul Eggert
ac06d4d104 Fix xsparse.c big heap allocation bugs
* scripts/xsparse.c (expand_sparse): Read into auto buffer, not heap.
The heap code was wrong for two reasons: it called malloc just once
in the try-again loop, and even when it succeeded it could have
left so few bytes available in the heap that later stdio calls
could fail.  Reading into the auto buffer might be a bit slower
but speed is not an issue here and it’s better to be simple.
2024-11-06 10:18:55 -08:00
Sergey Poznyakoff
a855a80d06 Remove non-ASCII comment text 2024-11-04 08:34:29 +02:00
Sergey Poznyakoff
b5bf1ccd18 Update paxutils 2024-11-04 08:31:28 +02:00
Paul Eggert
a6cf78b0fa Add LG_BLOCKSIZE to omit some *, % ops
* src/buffer.c (_flush_write, short_read, seek_archive)
(_gnu_flush_write):
* src/create.c (write_gnu_long_link, dump_regular_file)
(dump_dir0):
* src/delete.c (write_recent_bytes, flush_file)
(delete_archive_members):
* src/list.c (read_header):
* src/sparse.c (sparse_dump_region, sparse_extract_region)
(pax_dump_header_1):
* src/tar.c (parse_opt):
* src/update.c (append_file):
Prefer shifting and masking to dividing and remaindering by
BLOCKSIZE.  This reclaims some compiler optimizations lost
by our recent preference for signed integers.
* src/tar.h (LG_BLOCKSIZE): New constant, for shifting.
2024-11-02 13:43:05 -07:00
Paul Eggert
568919d77b Improve sparse I/O performance
* src/sparse.c (sparse_dump_region, sparse_extract_region):
Don’t insist on reading and writing sparse files 512
bytes at a time.  This resulted in a 4× to 6× performance
improvement on my platform.
2024-11-02 13:43:05 -07:00
Paul Eggert
c500103600 Simplify read_incr_db_01 malloc
* src/incremen.c (read_incr_db_01): Replace arg initbuf with two
args pbuf and pbufsize so that we can simplify memory allocation.
Caller changed.  Omit now-unnecessary free, xstrdup, strlen.
2024-11-02 13:43:05 -07:00
Paul Eggert
5c47fcf187 Avoid malloc in change_tape_menu
* src/buffer.c (change_tape_menu): Avoid unnecessary xstrdup.
2024-11-02 13:43:05 -07:00
Paul Eggert
005f2916b6 Improve common.h comment 2024-11-02 13:43:05 -07:00
Paul Eggert
15d35a0f61 Count short read slop when seeking
* src/buffer.c (short_read_slop): New static var.
(get_archive_status): Treat anything other than fifos and sockets
as potentially seekable; they’ll tell us if they aren’t, whereas
fifos and sockets cannot be seekable.  Check named files for
initial offset too, to deal with names like /dev/stdin.
Do not worry about start_offset’s value if !seekable_archive,
as it won’t be used.  Use short_read_slop.
(short_read, try_new_volume, simple_flush_read, _gnu_flush_read):
Set short_read_slop.
2024-11-02 13:43:05 -07:00
Paul Eggert
04b4f491a8 Prefer other types to int in xattrs.c
* src/xattrs.c (xattrs__acls_set) [HAVE_POSIX_ACLS]:
Prefer acl_type_t to int for ACL types.
(acls_get_text, xattrs_acls_get, xattrs_acls_set)
(xattrs_xattrs_get, xattrs_selinux_get, xattrs_selinux_set)
(xattrs_xattrs_set): Prefer bool for booleans.
2024-11-01 23:47:23 -07:00
Paul Eggert
e531f8c66c Prever other types to int in warning.c
* src/warning.c (set_warning_option): Prefer bool for boolean.
2024-11-01 23:47:23 -07:00
Paul Eggert
f4ac66226a Prefer other types to int in transform.c
* src/transform.c (add_char_segment, parse_xform_flags)
(parse_transform_expr): Prefer char for char.
(parse_transform_expr): Don’t assume strlen (expr) <= INT_MAX.
2024-11-01 23:47:23 -07:00
Paul Eggert
6993486ed8 Avoid unlikely verbose_option overflow
* src/tar.c (parse_opt, decode_options):
Avoid undefined behavior if verbose_option overflows.
2024-11-01 23:47:23 -07:00
Paul Eggert
04c1b85872 Prefer other types to int in system.c
* src/system.c (is_regular_file, sys_exec_setmtime_script):
Prefer bool for boolean.
(sys_exec_command): Prefer char for char.
2024-11-01 23:47:23 -07:00
Paul Eggert
ef95115f61 Prefer other types to int in sparse.c
* src/sparse.c (oldgnu_get_sparse_info, star_get_sparse_info):
Prefer char for char.
2024-11-01 23:47:23 -07:00
Paul Eggert
41143ee46f Prefer other types to int in names.c
* src/names.c (uname_to_uid, gname_to_gid, handle_option)
(make_file_name): Prefer bool for boolean.
(struct name_elt, read_name_from_file): Prefer char for char.
(handle_option): Invert sense of return value, for clarity.
All uses changed.
(merge_sort_sll, merge_sort, collect_and_sort_names):
Don’t assume list length fits in int.  Use intptr_t not idx_t,
since the bound is the size of all memory rather than one array.
2024-11-01 23:47:23 -07:00
Paul Eggert
f96aff3ce9 Prefer other types to int in misc.c
* src/misc.c (quote_copy_string, tar_savedir):
Use bool for booleans.  All uses changed.
(quote_copy_string): Use char for chars.
(unquote_string): Return void, since nobody uses return value.
(unquote_string): Check for overflow in escapes like \777.
(wdcache): Now array of idx_t not int, since in theory it
might contain values greater than INT_MAX.  All uses changed.
2024-11-01 23:47:23 -07:00
Paul Eggert
53a3691092 Prefer other types to int in map.c
* src/map.c (map_read): Prefer bool for booleans.
(owner_map_translate, group_map_translate):
Return void, not int, as nobody uses the return value.
2024-11-01 23:47:23 -07:00
Paul Eggert
91ad4ea343 Fix some uses of int in list.c
* src/list.c (decode_xform): Last arg is now int, not a void *
pointer to that int.  All uses changed.
(enforce_one_top_level): Don’t assume string length fits in int.
(transform_stat_info): Prefer char to int for typeflag.
All uses changed.
(decode_header): Prefer bool for booleans.  All uses changed.
(ugswidth): Now idx_t, not int, since in theory it could
exceed INT_MAX.  All uses changed.
(simple_print_header, print_for_mkdir): Don’t assume printf length
fits in int, and similarly for length of user or group name.
* src/transform.c (transform_name_fp): Last arg is now int, not void *.
All uses changed.
2024-11-01 23:47:23 -07:00
Paul Eggert
7eb4dbaff1 Prefer other types to int in incremen.c
* src/incremen.c (struct dumpdir_iter, dumpdir_first)
(read_incr_db_01, dumpdir_ok, list_dumpdir):
Prefer bool to int for booleans.  All uses changed.
(read_incr_db_01): Don’t assume getline returns <= INT_MAX.
(dumpdir_ok): Prefer char to int for chars.
2024-11-01 23:47:23 -07:00
Paul Eggert
112ead7931 Prefer other types to int in extract.c
* src/extract.c (fd_chmod, extract_chdir, open_output_file)
(extract_file, extract_link, extract_symlink, extract_node)
(extract_fifo, tar_extractor_t, pepare_to_extract): Prefer char to
int for typeflag, since it’s a char.  All uses changed.
(fd_chmod): Use clearer code for errno.
(extract_dir, extract_file, create_placeholder_file, extract_link)
(extract_symlink, extract_node, extract_fifo, tar_extractor_t):
Return bool true for success, false for failure.  All uses changed.
(open_output_file): Prefer bool for boolean.
(prepare_to_extract): Simplify by returning the extractor a null
pointer, rather than storing through a pointer to an extractor.
2024-11-01 23:47:23 -07:00
Paul Eggert
fd401e1d29 Prefer other types to int in delete.c
* src/delete.c (write_record): Arg is bool, not int.
All callers changed.
2024-11-01 23:47:23 -07:00
Paul Eggert
f8a679e942 Be a bit more consistent about comparing to zero
* src/buffer.c (xclose, archive_is_dev, close_archive)
(write_fatal_details, init_volume_number)
(closeout_volume_number, new_volume, try_new_volume):
* src/checkpoint.c (format_checkpoint_string):
* src/compare.c (process_rawdata, diff_file, diff_dumpdir):
* src/create.c (create_archive, restore_parent_fd, dump_file0):
* src/delete.c (delete_archive_members):
* src/exclist.c (cvs_addfn):
* src/extract.c (set_mode, mark_after_links, delay_set_stat)
(repair_delayed_set_stat, make_directories, file_newer_p)
(maybe_recoverable, apply_nonancestor_delayed_set_stat)
(extract_dir, open_output_file, find_delayed_link_source)
(create_placeholder_file, extract_symlink, extract_node)
(extract_fifo, apply_delayed_link):
* src/incremen.c (update_parent_directory, scan_directory)
(read_obstack, read_incr_db_2, write_directory_file)
(try_purge_directory):
* src/map.c (map_read):
* src/misc.c (maybe_backup_file, undo_last_backup, chdir_do)
(tar_savedir):
* src/names.c (handle_file_selection_option, add_file_id)
(handle_option, read_next_name, add_hierarchy_to_namelist)
(collect_and_sort_names):
* src/system.c (run_decompress_program, dec_to_env, time_to_env)
(oct_to_env, str_to_env, chr_to_env, sys_exec_setmtime_script):
* src/tar.c (get_date_or_file, parse_default_options)
(decode_options, main):
* src/unlink.c (flush_deferred_unlinks):
* src/update.c (append_file):
* src/xattrs.c (xattrs__acls_set, xattrs_xattrs_set):
Prefer < 0 when looking at syscalls; prefer != 0 to nothing
when testing an integer in a boolean context.
This is for style, not substance; for example, it’s easier
to read ‘if (wordsplit (...) != WRDSE_OK) ...’ than
‘if (wordsplit (...)) ...’ if you don’t already know that
wordsplit returns an enum rather than bool.
* src/names.c (add_file_id, read_next_name, regex_usage_warning):
* src/transform.c (parse_xform_flags):
Return bool not int, possibly inverting sense so that true means OK.
All callers changed.
* src/tar.c (main): Report errno info if stdopen fails.
2024-11-01 23:47:23 -07:00
Paul Eggert
3b0d006830 dumpdir_cmp signature
* src/compare.c (dumpdir_cmp): Return char, not int.
2024-11-01 23:47:23 -07:00
Paul Eggert
6e873de727 Check for checkpoint string overflow
It’s very unlikely, but would lead to undefined behavior.
* src/checkpoint.c (format_checkpoint_string): Accept and return
intmax_t, not idx_t.  All callers changed.  Check for integer
overflow by using add_printf.  If overflow occurs, don’t bother
with extending width.
2024-11-01 23:47:23 -07:00
Paul Eggert
bde3e8d663 Prefer int to idx_t for some small sizes
* src/create.c (max_octal_val, to_octal, tar_copy_str)
(tar_name_copy_str, to_base256, to_chars_subst, to_chars)
(gid_to_chars, major_to_chars, minor_to_chars, mode_to_chars)
(off_to_chars, time_to_chars, uid_to_chars, string_to_chars)
(split_long_name, write_ustar_long_name, simple_finish_header):
* src/list.c (from_header, gid_from_header, major_from_header)
(minor_from_header, mode_from_header, off_from_header)
(time_from_header, uid_from_header):
Prefer int to idx_t where either will do because the buffer sizes
are known to be small, as this can be a performance win on 32-bit
platforms.  Also, in a few cases the values were negative, whereas
idx_t is supposed to be nonnegative.
2024-11-01 23:47:23 -07:00
Paul Eggert
967f5f52f7 Pacify gcc -Wmissing-variable-declarations
* src/buffer.c (start_offset): Now static.
2024-11-01 23:47:23 -07:00
Paul Eggert
5a41310e57 Prefer other types to int in compare.c
* src/compare.c (get_stat_data, verify_volume):
Use bool for booleans.
(verify_volume): Count headers with intmax_t, not int.
2024-11-01 23:47:23 -07:00
Paul Eggert
3357683933 Prefer other types to int in checkpoint.c
* src/checkpoint.c (checkpoint_state): Now enum, not int.
(tty_cleanup): Now bool, not int.
2024-11-01 23:47:23 -07:00
Paul Eggert
a337cd35a0 Prefer other types to int in buffer.c
This increases the volume number maximum from 2**31 - 1	to 2**63 - 1.
* src/buffer.c (record_index, inhibit_map, new_volume):
Prefer bool to int for booleans.
* src/buffer.c (volno, global_volno):
* src/system.c (sys_exec_info_script):
Prefer intmax_t to int.
* src/buffer.c (increase_volume_number): Omit by-hand check for
overflow that relied on undefined behavior.
(new_volume): Check for that overflow here instead, without
relying on undefined behavior.
(print_stats): Avoid undefined behavior if printf sums overflow,
and reliably treat printf error like overflow.
* src/common.h (add_printf): New inline function.
2024-11-01 23:47:23 -07:00
Paul Eggert
5a7185ae31 Prefer other types to int in tar.c
Use types that are more specific than ‘int’, if that is easy.
* src/tar.c (after_date_option, xattrs_option, check_links_option)
(confirm, confirm_file_EOF, set_xattr_option, optloc_eq)
(get_date_or_file):
Prefer bool to int.
(tar_list_quoting_styles, tar_set_quoting_style, parse_opt):
Prefer idx_t to int.
(optloc_lookup, option_set_in_cl): Prefer enum option_class to int.
(decode_signal): Avoid some pointer reallocation.
(sort_mode_flag, hole_detection_types, set_old_files_option)
(is_subcommand_class): Prefer enum to int.
(parse_opt) [DEVICE_PREFIX]: Remove unused var.
Simplify creation of device name.
(find_argp_option_key, find_argp_option): Prefer char to int.
(enum subcommand_class): Now named.
(subcommand_class): Now char, not int.
(decode_options): Check for unlikely int overflow.
2024-11-01 23:47:23 -07:00
Paul Eggert
0aa69501d3 Remove major, minor signedness assumption
* src/common.h (uintmax): Remove; no longer used.
* src/list.c (simple_print_header): Don’t assume major and minor
agree in signedness.
2024-11-01 23:47:23 -07:00
Paul Eggert
2339c9106b Fix checkpoint_flush_actions width typo
* src/checkpoint.c (checkpoint_flush_actions): long → intmax_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
a3ba452f40 Fewer uses of uintmax_t in xheader.c
* src/tar.h (struct xheader):
* src/xheader.c (xheader_string_end):
Use idx_t, not uintmax_t, for string length.
* src/xheader.c (xheader_string_add):
Avoid duplicate calls to strlen.
(xheader_string_end): Remove by-hand check for size overflow;
it’s not possible, as this is measuring allocated storage.
2024-11-01 23:47:23 -07:00
Paul Eggert
d9da938963 Prefer intmax_t for occurrence counts
* src/common.h (struct name):
* src/tar.c (occurrence_option, parse_opt):
Use intmax_t, not uintmax_t, for occurrence counts.
2024-11-01 23:47:23 -07:00
Paul Eggert
989842ff0d Remove unnecessary casts
Some of these date back to pre-C89.
* src/buffer.c (backspace_output):
* src/create.c (to_base256, gid_to_chars, major_to_chars)
(minor_to_chars, off_to_chars, time_to_chars, uid_to_chars):
* src/list.c (from_header, tartime):
* src/map.c (owner_map_translate, group_map_translate):
* src/system.c (sys_truncate):
* src/utf8.c (utf8_init):
* src/xattrs.c (acls_one_line):
* src/xheader.c (xheader_string_end):
Remove casts.
* src/create.c (uintmax_to_chars): Remove.  All uses removed.
(simple_finish_header): Use to_octal.
2024-11-01 23:47:23 -07:00
Paul Eggert
6f5718a35f Check for setenv failures when running scripts
* src/system.c (dec_to_env): Use umaxtostr for speed,
since convenience isn’t needed here.
(sys_exec_info_script, sys_exec_checkpoint_script):
Check for setenv failure.
2024-11-01 23:47:23 -07:00
Paul Eggert
d68c37b640 Prefer off_t to uintmax_t for continued_file_*
* src/buffer.c (continued_file_size, continued_file_offset):
Now off_t, not uintmax_t.  All uses changed.
* src/common.h (UINTMAX_FROM_HEADER):
* src/list.c (uintmax_from_header):
Remove; unused.
* src/list.c (simple_print_header):
* src/xheader.c (volume_size_decoder, volume_offset_decoder):
Treat offset as off_t, not uintmax_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
c0ef66da92 Prefer idx_t to size_t in common.h
* src/common.h (struct name): Prefer idx_t to size_t.
(volume_label_count): Remove; unused.
2024-11-01 23:47:23 -07:00
Paul Eggert
c2ce0b7e13 Prefer idx_t to size_t in tar.h
* src/tar.h (struct xheader, struct tar_stat_info):
Prefer idx_t to size_t.  All uses changed.
2024-11-01 23:47:23 -07:00
Paul Eggert
7b278044a7 Prefer idx_t to size_t in xheader.c
* src/xheader.c (x_obstack_grow, x_obstack_blank)
(xheader_format_name, xheader_ghdr_name, xheader_write)
(struct xhdr_tab, locate_handler, decode_record, decx, decg)
(xheader_read, xattr_encode_keyword, xheader_print_n)
(xheader_string_end, dummy_decoder, atime_decoder, gid_decoder)
(gname_decoder, linkpath_decoder, ctime_decoder, mtime_decoder)
(path_decoder, sparse_path_decoder, size_decoder, uid_decoder)
(uname_decoder, sparse_size_decoder, sparse_numblocks_decoder)
(sparse_offset_coder, sparse_offset_decoder)
(sparse_numbytes_coder, sparse_numbytes_decoder)
(sparse_map_decoder, dumpdir_decoder, volume_label_decoder)
(volume_size_decoder, volume_offset_decoder)
(volume_filename_decoder, xattr_selinux_decoder)
(xattr_acls_a_decoder, xattr_acls_d_decoder, xattr_coder)
(xattr_decoder, sparse_major_decoder, sparse_minor_decoder):
Prefer idx_t to size_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
025f19e6bd Prefer intmax_t to size_t in xheader.c
* src/common.h (INTMAX_STRSIZE_BOUND): New constant.
(SYSINT_BUFSIZE): Use it.
* src/xheader.c (global_header_count, xheader_format_name):
Prefer intmax_t to size_t, as the values are not sizes.
2024-11-01 23:47:23 -07:00
Paul Eggert
c61a2bee73 Omit unnecessary initialization in dunlink_alloc
* src/unlink.c (dunlink_alloc): Remove unnecessary assignment
to p->next.
2024-11-01 23:47:23 -07:00
Paul Eggert
08a9174444 Remove unused static vars in unlink.c
* src/unlink.c (unlink_count, deferred_unlink_delay):
Remove.  All uses removed.
2024-11-01 23:47:23 -07:00
Paul Eggert
e0f9b0fdea Prefer idx_t to size_t in transform.c
* src/transform.c (struct replace_segm, struct transform)
(add_literal_segment, add_backref_segment, run_case_conv)
(_single_transform_name_to_obstack): Prefer idx_t to size_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
17ad155fb2 Prefer idx_t to size_t in xattrs.c
* src/xattrs.c (xattr_map_free, xattr_map_add)
(xheader_xattr_add, xattr_map_copy, struct xattrs_mask_map)
(fixup_extra_acl_fields, xattrs_acls_cleanup, acls_get_text)
(xattrs__acls_get_a, xattrs__acls_get_d, acls_one_line)
(mask_map_realloc, xattrs_xattrs_get, xattrs__fd_set)
(xattrs_matches_mask, xattrs_xattrs_set, xattrs_print_char)
(xattrs_print): Prefer idx_t to size_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
303ac16ec0 Prefer idx_t to size_t in tar.c
* src/tar.c (strip_name_components, archive_names)
(allocated_archive_names, tar_list_quoting_styles)
(expand_pax_option, parse_opt):
Prefer idx_t to size_t.
(decode_options): Use a static word rather than going
to to the bother of dynamically allocating an array.
(main): Do not preallocate array.  Do not call ‘free’
on a pointer that now might be to static storage.
2024-11-01 23:47:23 -07:00
Paul Eggert
6df7a72434 Prefer idx_t to size_t in system.c
* src/buffer.c (_flush_write): Return idx_t, not ssize_t,
to accommodate system.c changes.  All uses changed.
(_gnu_flush_write): Output correct errno value after write error.
Simplify multi-volume mode.
* src/system.c (sys_write_archive_buffer)
(sys_child_open_for_compress, sys_exec_setmtime_script):
Prefer idx_t to size_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
23582f3445 Streamline compression suffix detection
* src/suffix.c (struct compression_suffix):
Use arrays rather than pointers that need relocation.
All uses changed.
(compression_suffixes): Now const.
Omit trailing null entry; all uses changed.
(find_compression_suffix): Simplify length calculations.
No longer any need to call strlen.
2024-11-01 23:47:23 -07:00
Paul Eggert
317e4d6a3c Fewer uses of size_t in suffix.c
* src/suffix.c (struct compression_suffix)
(find_compression_suffix, set_compression_program_by_suffix)
(strip_compression_suffix): Prefer idx_t to size_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
5f4a4164b7 Fewer uses of size_t in sparse.c
* src/sparse.c (struct tar_sparse_optab, dump_zeros)
(tar_sparse_dump_region, tar_sparse_extract_region)
(zero_block_p, sparse_add_map, sparse_dump_region)
(sparse_extract_region, sparse_dump_file, sparse_extract_file)
(check_data_region, sparse_diff_file, oldgnu_get_sparse_info)
(oldgnu_store_sparse_info, oldgnu_dump_header)
(star_get_sparse_info, pax_dump_header_0):
Prefer idx_t to size_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
7c0feaefd0 Adjust better to Gnulib signed-int read changes
The 2024-08-09 Gnulib changes that caused some modules prefer
signed types to size_t means that Tar should follow suit.
* src/buffer.c (short_read):
* src/system.c (sys_child_open_for_compress)
(sys_child_open_for_uncompress):
rmtread and safe_read return ptrdiff_t not idx_t;
don’t rely on implementation defined conversion.
* src/misc.c (blocking_read): Never return a negative number.
Return idx_t, not ptrdiff_t, with the same convention for EOF
and error as the new full_read.  All callers changed.
* src/sparse.c (sparse_dump_region, check_sparse_region)
(check_data_region):
* src/update.c (append_file):
full_read no longer returns SAFE_READ_ERROR for I/O error; instead it
returns the number of bytes successfully read, and sets errno.
Adjust to this.
* src/system.c (sys_child_open_for_uncompress):
Rewrite to avoid need for goto and label.
2024-11-01 23:47:23 -07:00
Paul Eggert
e513950080 Simplify name_buffer initialization
* src/names.c (name_init): Remove no-longer-needed initialization
of name_buffer, name_buffer_length.  It was confusing anyway,
since it caused name_buffer_length to not equal the length of
name_buffer.
2024-11-01 23:47:23 -07:00
Paul Eggert
2ce5791124 Simplify add_hierarchy_to_namelist allocation
* src/names.c (add_hierarchy_to_namelist):
Use xpalloc rather than a complicated homebrew heuristic.
2024-11-01 23:47:23 -07:00
Paul Eggert
d127dac10e Remove xattrs_clear_setup
It’s never actually called.
* src/xattrs.c (clear_mask_map, xattrs_clear_setup):
Remove.  All uses removed.
2024-11-01 23:47:23 -07:00
Paul Eggert
61a978f6d4 Remove name_term
It’s never actually called.
* src/names.c (name_term): Remove.  All uses removed.
2024-11-01 23:47:23 -07:00
Paul Eggert
fae968bd2d Diagnose sys_exec_info_script failures
* src/system.c (sys_exec_info_script): Diagnose failures in
getline, fclose.  Don’t worry about freeing memory
as caller will immediately exit anyway.
2024-11-01 23:47:23 -07:00
Paul Eggert
9afbe6961c Pacify GCC in info_attach_exclist
* src/exclist.c (info_attach_exclist): Remove unnecessary test
for whether dir and ex are null.  GCC complains about the first
one in some cases.  Use C99-style decls.
2024-11-01 23:47:23 -07:00
Paul Eggert
5704e5795a Fewer uses of size_t in names.c
* src/names.c (name_buffer_length, read_name_from_file)
(copy_name, all_names_found, add_hierarchy_to_namelist)
(rebase_child_list, make_file_name, stripped_prefix_len):
Prefer idx_t to size_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
b73127edc4 Fewer uses of size_t in misc.c
* src/misc.c (assign_string_n, quote_copy_string)
(normalize_filename, replace_prefix, remove_any_file)
(blocking_read, wd_alloc, wdcache_count, chdir_arg, chdir_do)
(read_diag_details, struct namebuf, namebuf_name):
Prefer idx_t to size_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
dd71d3796d Fewer uses of size_t in list.c
* src/list.c (recent_long_name_blocks, recent_long_link_blocks)
(read_header, from_header, gid_from_header, major_from_header)
(minor_from_header, mode_from_header, off_from_header)
(time_from_header, uid_from_header, uintmax_from_header)
(tartime): Prefer idx_t to size_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
f73c927a71 Fewer uses of size_t in incremen.c
* src/incremen.c (struct dumpdir, dumpdir_create0, struct dumpdir_iter)
(dumpdir_next, dumpdir_size, make_directory)
(dirlist_replace_prefix, rebase_directory, makedumpdir)
(maketagdumpdir, append_incremental_renames, read_obstack)
(read_incr_db_2, get_gnu_dumpdir, try_purge_directory)
(list_dumpdir): Prefer idx_t to size_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
04b92eca49 Fewer uses of size_t in extract.c
* src/extract.c (struct delayed_set_stat, struct delayed_link)
(delay_set_stat, apply_nonancestor_delayed_set_stat)
(extract_file): Prefer idx_t to size_t.
(struct delayed_set_stat): Remove unused member xattr_map_size.
2024-11-01 23:47:23 -07:00
Paul Eggert
5a00343006 Fewer uses of size_t in exclist.c
* src/exclist.c (hg_addfn): Prefer idx_t to size_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
739483114d Fewer uses of size_t in delete.c
* src/delete.c (write_recent_blocks, write_recent_bytes):
Prefer idx_t to size_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
849f244a0b Fewer uses of size_t in create.c
* src/create.c (struct exclusion_tag, to_octal, tar_copy_str)
(tar_name_copy_str, to_base256, to_chars_subst, to_chars)
(gid_to_chars, major_to_chars, minor_to_chars, mode_to_chars)
(off_to_chars, time_to_chars, uid_to_chars, uintmax_to_chars)
(string_to_chars, start_private_header, write_gnu_long_link)
(split_long_name, write_ustar_long_name, simple_finish_header)
(dump_dir0, ensure_slash, create_archive):
Prefer idx_t to size_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
15dc3210cc Fewer uses of size_t in compare.c
* src/compare.c (read_and_process): Prefer idx_t to size_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
7abf1420c3 Simplify checkpoint_action allocation
* src/checkpoint.c: Include <flexmember.h>.
(struct checkpoint_action): New member commandbuf.
(checkpoint_action_tail): Now pointer to pointer,
to simplify updating.  All uses changed.
(alloc_action): New arg quoted_string, to lessen number of
separate allocations.  All uses changed.
2024-11-01 23:47:23 -07:00
Paul Eggert
0b60228081 checkpoint_total_format is now const
* src/checkpoint.c (checkpoint_total_format):
Now const, and local to format_checkpoint_string.
2024-11-01 23:47:23 -07:00
Paul Eggert
f9ed22de9b Fewer uses of size_t in checkpoint.c
* src/checkpoint.c (copy_string_unquote, getarg)
(format_checkpoint_string): Prefer idx_t to size_t.
(copy_string_unquote): Simplify by using ximemdup0.
(getarg): Avoid quadratic reallocation behavior by
using xpalloc.
2024-11-01 23:47:23 -07:00
Paul Eggert
78dd7bf0bc Fewer uses of size_t in buffer.c
* src/buffer.c (flush_write_ptr, flush_bufmap, bufmap_locate):
(struct zip_magic, available_space_after, _flush_write)
(short_read, flush_archive, try_new_volume)
(gnu_add_multi_volume_header, simple_flush_read)
(simple_flush_write, _gnu_flush_read, _gnu_flush_write)
(gnu_flush_write): Prefer idx_t to size_t when either will do, as
signed types are typically safer.  For a tiny value in memory,
just use ‘char’.
2024-11-01 23:47:23 -07:00
Sergey Poznyakoff
647cafff96 Don't assume archive read from stdin starts at offset 0
* src/buffer.c (start_offset): New variable.
(get_archive_status): If reading from seekable stdin, store the
position in the stream corresponding to record_start in start_offset.
(seek_archive): Compute current offset relative to start_offset.
2024-10-31 19:17:05 +02:00
Sergey Poznyakoff
bd06b114d9 Add missing safety check
* src/system.c (sys_exec_info_script): Check if fdopen succeded.
Fix by Matteo Croce.
2024-10-25 13:40:32 +03:00
Sergey Poznyakoff
8767b1c84a Remove useless check
* src/exclist.c (info_attach_exclist): Don't check whether dir
is NULL. It can't be.
2024-10-25 10:24:32 +03:00
Sergey Poznyakoff
e59d09db7d Bugfix
This fixes an extra argument left over in a function call by commit
0dfcfa4aa4.  Reported by Matteo Croce.

* src/buffer.c (_open_archive): Fix extra argument to paxfatal.
2024-10-25 09:50:22 +03:00
Paul Eggert
dd1bae32ce Fewer macros in xheader.c
* src/xheader.c (HEADER_TEMPLATE):
Remove.  All uses replaced with definiens.
(XHDR_PROTECTED, XHDR_GLOBAL): Now constants, not macros.
2024-08-19 09:57:13 -07:00
Paul Eggert
8b3073e1d2 Fewer macros in xattrs.c
* src/xattrs.c (XATTRS_PREFIX, XATTRS_PREFIX_LEN, USER_DOT_PFX):
Now constants, not macros.
2024-08-19 09:57:13 -07:00
Paul Eggert
7c4f884747 Fewer macros in unlink.c
* src/unlink.c (IS_CWD): Now a (lower-cased) function.
2024-08-19 09:57:13 -07:00
Paul Eggert
82ef07c9bd Fewer macros in transform.c
* src/transform.c (CASE_CTL_RESET): Remove, replacing with one
instance of code (with a goto, alas).  Still a bit clearer, I think.
2024-08-19 09:57:13 -07:00
Paul Eggert
350cc4077e Fewer macros in tar.c
* src/tar.c (FORMAT_MASK, TAR_SIZE_SUFFIXES, SUBCL_READ)
(SUBCL_WRITE, SUBCL_UPDATE, SUBCL_TEST, SUBCL_OCCUR)
(IS_SUBCOMMAND_CLASS, NS_PRECISION_FORMAT_MASK):
Now constants or (lower-cased) functions, not macros.
(subcommand_class):
Replace hopeful comments with code implementing them.
2024-08-19 09:57:13 -07:00
Paul Eggert
7f557428a4 Fewer macros in tar.h
* src/tar.h (REGTYPE, AREGTYPE, SYMTYPE, BLKTYPE, FIFOTYPE)
(XHDTYPE, XGLTYPE, TSUID, TSGID, TSVTX, TUREAD, TUWRITE, TUEXEC)
(TGREAD, TGWRITE, TGEXEC, TOREAD, TOWRITE, TOEXEC)
(SPARSES_IN_EXTRA_HEADER, SPARSES_IN_OLDGNU_HEADER)
(SPARSES_IN_SPARSE_HEADER, GNUTYPE_DUMPDIR, GNUTYPE_LONGLINK)
(GNUTYPE_LONGNAME, GNUTYPE_MULTIVOL, GNUTYPE_SPARSE)
(GNUTYPE_VOLHDR, SOLARIS_XHDTYPE, SPARSES_IN_STAR_HEADER)
(SPARSES_IN_STAR_EXT_HEADER, BLOCKSIZE):
Now constants, not macros.
2024-08-19 09:57:13 -07:00
Paul Eggert
dd0f95965d Fewer macros in system.c
* src/system.c (PREAD, PWRITE): Now constants, not macros.
2024-08-19 09:57:13 -07:00
Paul Eggert
cdcd1580c8 Fewer macros in names.c
* src/names.c (EXCLUDE_OPTIONS, INCLUDE_OPTIONS):
Now (lowercased) functions, not macros.
(SUCCESSOR): Remove, replacing uses with definiens.
2024-08-19 09:57:13 -07:00
Paul Eggert
dfb1da7253 Fewer macros in incremen.c
* src/incremen.c (DIRF_INIT, DIRF_NFS, DIRF_FOUND, DIRF_NEW)
(DIRF_RENAMED, DIR_IS_INITED, DIR_IS_NFS, DIR_IS_FOUND)
(DIR_IS_RENAMED, DIR_SET_FLAG, DIR_CLEAR_FLAG, NFS_FILE_STAT)
(PD_FORCE_CHILDREN, PD_FORCE_INIT, PD_CHILDREN)
(TAR_INCREMENTAL_VERSION, TEMP_DIR_TEMPLATE):
Now constants or (lowercased) functions, not macros.
(ST_DEV_MSB) [!HAVE_ST_FSTYPE_STRING]: Remove.
Replace only use with something simpler.
2024-08-19 09:57:13 -07:00
Paul Eggert
79cb9aaab6 Fewer macros in extract.c
* src/extract.c (ALL_MODE_BITS, RECOVER_NO, RECOVER_OK)
(RECOVER_SKIP): Now constants or inline functions, not macros.
(maybe_recoverable): Return enum recover, not int.
2024-08-19 09:57:13 -07:00
Paul Eggert
da109fae7a Fewer macros in create.c
* src/create.c (CACHEDIR_SIGNATURE, CACHEDIR_SIGNATURE_SIZE)
(MAX_VAL_WITH_DIGITS, MAX_OCTAL_VAL): Now constants or
inline functions or removed, instead of macros.
(max_octal_val): Accept size rather than type.
2024-08-19 09:57:13 -07:00
Paul Eggert
cc1352699a Fewer macros in buffer.c
* src/buffer.c (READ_ERROR_MAX, NMAGIC, VOL_SUFFIX):
Now constants rather than macros.  Rename NMAGIC to n_zip_magic.
2024-08-19 09:57:13 -07:00
Paul Eggert
4323e98683 Fewer macros in common.h
In common.h, replace macros with constants or functions when that
is easy.  This makes code a bit more reliable (functions evaluate
their args exactly once) and easier to debug (many debugging
environments cannot access macros).
* src/common.h (CHKBLANKS): Remove.  All uses removed.
(NAME_FIELD_SIZE, PREFIX_FIELD_SIZE, UNAME_FIELD_SIZE)
(GNAME_FIELD_SIZE, TAREXIT_SUCCESS, TAREXIT_DIFFERS)
(TAREXIT_FAILURE, LG_8, LG_256, DEFAULT_CHECKPOINT)
(MAX_OLD_FILES, TF_READ, TF_WRITE, TF_DELETED, XFORM_REGFILE)
(XFORM_LINK, XFORM_SYMLINK, XFORM_ALL, WARN_ALONE_ZERO_BLOCK)
(WARN_BAD_DUMPDIR, WARN_CACHEDIR, WARN_CONTIGUOUS_CAST)
(WARN_FILE_CHANGED, WARN_FILE_IGNORED, WARN_FILE_REMOVED)
(WARN_FILE_SHRANK, WARN_FILE_UNCHANGED, WARN_FILENAME_WITH_NULS)
(WARN_IGNORE_ARCHIVE, WARN_IGNORE_NEWER, WARN_NEW_DIRECTORY)
(WARN_RENAME_DIRECTORY, WARN_SYMLINK_CAST, WARN_TIMESTAMP)
(WARN_UNKNOWN_CAST, WARN_UNKNOWN_KEYWORD, WARN_XDEV)
(WARN_DECOMPRESS_PROGRAM, WARN_EXISTING_FILE, WARN_XATTR_WRITE)
(WARN_RECORD_SIZE, WARN_FAILED_READ, WARN_MISSING_ZERO_BLOCKS)
(WARN_VERBOSE_WARNINGS, WARN_ALL, EXCL_DEFAULT, EXCL_RECURSIVE)
(EXCL_NON_RECURSIVE): Now enum constants rather than macros.
(time_option_initialized, isfound, wasfound, warning_enabled):
Now functions rather than macros TIME_OPTION_INITIALIZED, ISFOUND,
WASFOUND, WARNING_ENABLED.  All uses changed.
(OLDER_STAT_TIME, OLDER_TAR_STAT_TIME, EXTRACT_OVER_PIPE)
(TAR_ARGS_INITIALIZER): Remove.  All uses replaced with their
definiens or equivalent.
2024-08-19 09:57:13 -07:00
Paul Eggert
005e345c04 Fix non-ASCII in sparse.c 2024-08-19 09:57:13 -07:00
Paul Eggert
95a5f043c5 Prefer function to COPY_BUF macro
* src/sparse.c (struct ok_n_block_ptr): New type.
(decode_num): Revamp API so that it does the work of both
the old decode_num and the old COPY_BUF.  Always read to the
next newline even if there is a lot of junk in between.
(pax_decode_header): Use the new API.
(COPY_BUF): Remove.
2024-08-19 09:57:13 -07:00
Paul Eggert
f25dd56e83 Prefer function to COPY_STRING macro
* src/sparse.c (struct block_ptr):
New type, to allow a functional style.
(dump_str_nl, floorlog10): New static functions.
(COPY_STRING): Remove.  All uses replaced by dump_str_nl.
(pax_dump_header_1): Use floorlog10 instead of creating a string.
Simplify size calculation.
2024-08-19 09:57:13 -07:00
Paul Eggert
f1e4947992 Fix string size bound calculation
* src/common.h (UINTMAX_STRSIZE_BOUND):
Fix typo that luckily didn’t break anything.
2024-08-19 09:57:13 -07:00
Paul Eggert
0dfcfa4aa4 maint: switch from ERROR to paxerror etc
Prefer functions like ‘paxerror’ to macros like ‘ERROR’.
The functions have cleaner semantics, and calls are
easier to read.
2024-08-19 09:57:13 -07:00
Paul Eggert
e9c16628f0 build: update gnulib and paxutils submodules to latest 2024-08-19 09:57:13 -07:00
Paul Eggert
a0a1243c69 Adjust to verror change for program name
* configure.ac (ENABLE_ERROR_PRINT_PROGNAME):
Adjust to match new Gnulib behavior.
2024-08-15 10:27:47 -07:00
Paul Eggert
812a49419a build: update gnulib and paxutils submodules to latest 2024-08-14 23:25:46 -07:00
Paul Eggert
541f3bc374 Fix duplicate write_error_details decl
* src/common.h (write_error_details): Remove decl
that belongs to paxutils.
2024-08-14 23:25:46 -07:00
Paul Eggert
6bc4c4bf96 Fix minor diagnostic discrepancies in incrementals
* src/incremen.c (read_directory_file, get_gnu_dumpdir):
Be more consistent about fatal errors.
2024-08-14 23:25:46 -07:00
Paul Eggert
ab7a14bd92 Add verror module
* gnulib.modules: Add verror; paxlib will need this.
2024-08-14 23:25:46 -07:00
Paul Eggert
b596676c78 Use idx_t for write_fatal_details size
* src/buffer.c (write_fatal_details): Prefer idx_t to size_t
for object size.
2024-08-14 23:25:46 -07:00
Paul Eggert
15c6010c32 Use intmax_t for read_incr_db_01 line numbers
* src/incremen.c (read_incr_db_01): Don’t assume line numbers
are less than LONG_MAX.
2024-08-14 23:25:46 -07:00
Paul Eggert
43231ae554 Avoid need for base64_init and extra table
Simplify the code by assuming C99 initializers.
* src/list.c (base_64_digits): Remove.
(base64_map): Now a constant.  Now has its (old value + 1) % 65,
as that’s the only easy portable way to do it with a static
initializer (even on platforms where CHAR_BIT != 8); all uses changed.
(base64_init): Remove; only use removed.
(from_header): Adjust to new values in base64_map.

* src/list.c (base_64_digits): Remove; no longer needed.
(base64_map): Now const, initialized statically, and with
invalid entries being 0 not 64, and with valid entries
being 1 greater than before.
2024-08-14 23:25:46 -07:00
Paul Eggert
b201a37421 Remove cast from from_header
* src/list.c (from_header): Reword to avoid a cast
to unsigned char.
2024-08-14 23:25:46 -07:00
Paul Eggert
c9a3abcbe7 Prefer signed to unsigned when decoding options
* src/tar.c (assert_format, decode_options):
Prefer signed to unsigned integers.
(optloc_save): Prefer enum to unsigned integer.
Simplify allocation.
(decode_options): No need to call ngettext for a value known
to be plenty large.
2024-08-14 23:25:46 -07:00
Paul Eggert
18dadeffc0 Don’t assume pid fits in unsigned long
* src/system.c (sys_wait_command): Convert pid_t to intmax_t,
not to unsigned long.
2024-08-14 23:25:46 -07:00
Paul Eggert
1521d3dae0 Avoid casts in tar_checksum
* src/list.c (tar_checksum, from_header):
Recode to avoid casts.
2024-08-14 23:25:46 -07:00
Paul Eggert
5ab90d6c96 Support >UINT_MAX lines in map files
* src/map.c (parse_id, map_read): Prefer intmax_t to unsigned
for line numbers.
2024-08-14 23:25:46 -07:00
Paul Eggert
e137c14285 Prefer signed integer in struct directory
* src/incremen.c (struct directory):
Prefer int to unsigned where either will do.
2024-08-14 23:25:46 -07:00
Paul Eggert
95ebde4303 Simplify make_directory via xizalloc
* src/incremen.c (make_directory): Simplify by using
xizalloc instead of explicit initialization.
2024-08-14 23:25:46 -07:00
Paul Eggert
ef290cb171 Use idx_t, not size_t, for xattr value lengths.
* src/tar.h (struct xattr_map):
* src/xattrs.c (xattr_map_add): Prefer idx_t to size_t.  All uses
changed.
2024-08-14 23:25:46 -07:00
Paul Eggert
09aec02e32 Use intmax_t, not size_t, for input line numbers
This works better on platforms where SIZE_MAX < OFF_MAX.
* src/common.h (struct common locus):
* src/names.c (struct name_elt):
Use intmax_t for line numbers.  All uses changed.
2024-08-14 23:25:46 -07:00
Paul Eggert
9b69d17e24 In short_read, use %td not %lu
* src/buffer.c (short_read): Don’t assume sizes fit
in unsigned long.
2024-08-14 23:25:46 -07:00
Paul Eggert
b3992e4ef8 Prefer signed types in blocking_read etc
* src/compare.c (process_noop, process_rawdata):
Return bool, not int.
* src/compare.c (process_noop, process_rawdata):
* src/create.c (dump_regular_file):
* src/extract.c (extract_file):
* src/misc.c (blocking_read, blocking_write):
* src/sparse.c (sparse_scan_file_raw, sparse_extract_region):
Prefer signed types like idx_t to unsigned ones like size_t.
(sparse_scan_file_raw): Diagnose read errors.
2024-08-14 23:25:46 -07:00
Paul Eggert
88c2aa1616 Fix minor integer overflow in xsparse.c
* scripts/xsparse.c (read_xheader):
Don’t assume size_t fits in unsigned.
Make the version numbers off_t, not just unsigned.
2024-08-14 23:25:46 -07:00
Paul Eggert
d1e72a536f Prefer stoint to strtoul and variants
When parsing numbers prefer using strtosysint (renamed stoint)
to using strtoul and its variants.
This is simpler and faster and likely more reliable than
relying on quirks of the system strtoul etc,
and it standardizes how tar deals with parsing integers.
Among other things, the C standard and POSIX don’t specify
what strtol does to errno when conversions cannot be performed,
and it requires strtoul to support "-" before unsigned numbers.
* gnulib.modules (strtoimax, strtol, strtoumax, xstrtoimax):
Remove.
* src/checkpoint.c (checkpoint_compile_action, getwidth)
(format_checkpoint_string):
* src/incremen.c (read_incr_db_01, read_num)
* src/map.c (parse_id):
* src/misc.c (decode_timespec):
* src/sparse.c (decode_num):
* src/tar.c (parse_owner_group, parse_opt):
* src/transform.c (parse_transform_expr):
* src/xheader.c (decode_record, decode_signed_num)
(sparse_map_decoder):
Prefer stoint to strtol etc.
Don’t rely on errno == EINVAL as the standards don’t guarantee it.
* src/checkpoint.c (getwidth, format_checkpoint_string):
Check for invalid string suffix.
* src/checkpoint.c (getwidth):
Return intmax_t, not long.  All callers changed.
* src/incremen.c (read_directory_file):
It’s just a one-digit number, so just subtract '0'.
* src/map.c (parse_id): Return bool not int.  All callers changed.
* src/misc.c (stoint): Rename from strtosysint, and add
a bool * argument for reporting overflow.  All callers changed.
(decode_timespec): Simplify by using ckd_sub rather than
checking for overflow by hand.
* src/tar.c (incremental_level): Now signed char to
emphasize that it can be only -1, 0, 1.  All uses changed.
* src/xheader.c (decode_record): Avoid giant diagnostics.
2024-08-14 23:25:46 -07:00
Paul Eggert
3ffe2eb073 Handle enormous record sizes better
Formerly the code could misbehave when the user specified a record
size greater than min (INT_MAX * 512 + 511, PTRDIFF_MAX, SSIZE_MAX).
* src/delete.c (new_blocks, delete_archive_members):
* src/system.c (sys_exec_info_script):
* src/tar.c (blocking_factor, record_size):
Don’t limit blocking factor to INT_MAX.
Prefer signed type for record_size.
Do not exceed IDX_MAX or SSIZE_MAX for record_size;
the SSIZE_MAX limit is needed so that ‘read’ and ‘write’
calls behave sensibly.
2024-08-14 23:25:46 -07:00
Paul Eggert
eb9bb9bf80 Default to GNU/Linux dev_t etc
* configure.ac (dev_t, ino_t, major_t, minor_t):
Default to GNU/Linux types.  This shouldn’t affect behavior;
it’s just a cleanup.
2024-08-14 23:25:45 -07:00
Paul Eggert
4642cd04ed Avoid strtoul
This is part of the general trend to prefer signed integer types,
to allow better runtime checking with -fsanitize=undefined etc.
* gnulib.modules: Remove strtoul.  Add xstrtoimax.
* src/checkpoint.c (checkpoint, format_checkpoint_string):
* src/system.c (sys_exec_checkpoint_script):
* src/tar.c (checkpoint_option):
Use intmax_t, not unsigned, for checkpoint numbers.
All uses changed.
* src/checkpoint.c (checkpoint_compile_action): Don’t assume
time_t == unsigned long.  Treat overflows as TYPE_MAXIMUM (time_t),
essentially infinity.
* src/tar.c (tar_sparse_major, tar_sparse_minor):
* src/tar.h (struct tar_stat_info):
Use intmax_t, not unsigned, for sparse major and minor.
All uses changed.
* src/tar.c (parse_opt):
Don’t mishandle multiple specifications of sparse major and minor.
* src/transform.c (struct transform):
Use idx_t, not unsigned, for match_number.  All uses changed.
(parse_transform_expr): Don’t mishandle large match numbers
by wrapping them around.
2024-08-14 23:25:45 -07:00
Paul Eggert
a80f364662 Avoid snprintf
* gnulib.modules: Remove snprintf.
* lib/wordsplit.c (wordsplit_pathexpand):
Do not arbitrarily truncate diagnostic.
(wordsplit_c_quote_copy): Rewrite to avoid the need to
invoke snprintf on a temporary buffer.
2024-08-04 01:41:43 -07:00
Paul Eggert
5316938142 Avoid wordsplit quadratic behavior
* lib/wordsplit.c (wsplt_assign_var):
Avoid unlikely overflow when adding wsp->ws_envidx + n.
Avoid quadratic	behavior when growing ws_envbuf.
2024-08-04 01:41:43 -07:00
Paul Eggert
83926613a4 Prefer ialloc for wordsplit
* lib/wordsplit.c (alloc_space, wsplt_assign_var, expvar)
(wordsplit_tildexpand, wordsplit_pathexpand)
(wordsplit_get_words): Use ialloc API on idx_t args.
2024-08-04 01:41:43 -07:00
Paul Eggert
9a2344b183 Omit wordsplit API that tar doesn’t need
* lib/wordsplit.c: Include <attribute.h> here, not in wordsplit.h.
(WRDSO_ESC_SET, WRDSO_ESC_TEST): Move here from wordsplit.h.
(WORDSPLIT_EXTRAS_extern): New macro.  Used by functions
that tar doesn’t need to be exposed.
(wordsplit_append, wordsplit_c_quoted_length, wsplt_quote_char)
(wordsplit_c_unquote_char, wordsplit_c_quote_char)
(wordsplit_c_quote_copy, wordsplit_get_words, wordsplit_perror):
Omit unless _WORDSPLIT_EXTRAS.
(WORDSPLIT_ENV_INIT): Move here from wordsplit.h, and
make it a constant rather than a macro.
(wordsplit_strerror): Arg is now pointer to const.
* lib/wordsplit.h: Do not include attribute.h, so that library
users need not worry about attribute.h.
(wordsplit_t): Declare only if _WORDSPLIT_EXTRAS.  Similarly for
functions that are not exported to tar.
2024-08-04 01:41:43 -07:00
Paul Eggert
5182462cf1 wordsplit_get_words need not fail
* lib/wordsplit.c (wordsplit_get_words):
Do not fail merely because realloc fails.
Return void, since failure is no longer possible.
2024-08-04 01:41:43 -07:00
Paul Eggert
0ab451a420 More wordsplit int cleanup
* lib/wordsplit.c: Include limits.h.
(_wsplt_subsplit, wordsplit_add_segm, wsnode_quoteremoval)
(wsnode_coalesce, wsnode_tail_coalesce, find_closing_paren)
(expvar, begin_var_p, node_expand, begin_cmd_p, expcmd)
(scan_qstring, scan_word, wordsplit_c_quoted_length)
(wordsplit_string_unquote_copy, wordsplit_c_quote_copy)
(exptab_matches, wordsplit_process_list):
Prefer bool to int.
(wordsplit_init, alloc_space, coalesce_segment)
(wsnode_quoteremoval, wordsplit_finish, wordsplit_append):
Use WRDSE_OK instead of 0 when the context is that of WRDSE_*.
(wsnode_flagstr, coalesce_segment, wsnode_quoteremoval)
(wordsplit_finish, node_split_prefix, wsplt_assign_var, expvar)
(expcmd, wordsplit_tildexpand, wordsplit_pathexpand)
(wsplt_unquote_char, wsplt_quote_char)
(wordsplit_string_unquote_copy):
Prefer '\0' to 0 when it is a char.
(wsnode_insert): Omit last arg, which was always 0.
All callers changed.
(wordsplit_add_segm, node_split_prefix):
Use unsigned, not int, for flag, for consistency.
(wordsplit_finish, begin_var_p, begin_cmd_p, skip_sed_expr)
(xtonum, wsplt_unquote_char, wsplt_quote_char)
(wordsplit_c_unquote_char, wordsplit_c_quote_char)
(wordsplit_c_quote_copy):
Prefer char to int for chars.
(xtonum): Don’t treat "\400" as if it were "\000".
2024-08-04 01:41:43 -07:00
Paul Eggert
dab2830e38 Diagnose argp overflow
* src/names.c (handle_option):
* src/tar.c (parse_default_options):
Report an error if wordsplitting yields more than INT_MAX words,
rather than misbehaving.  argp_parse can’t handle more than
INT_MAX, unfortunately.
2024-08-04 01:41:43 -07:00
Paul Eggert
9cef4d5495 Fix unlikely buffer overrun when checkpointing
* src/checkpoint.c (format_checkpoint_string):
Don’t overrun buffer when word splitting.
2024-08-04 01:41:43 -07:00
Paul Eggert
7cda31b1e0 Prefer idx_t to size_t in wordsplit
* gnulib.modules: Add ialloc.
* lib/wordsplit.c: Include ialloc.h.
(PRINTMAX): New constant.
(printflen, printfdots): New functions.
(wordsplit_dump_nodes, expvar, wordsplit_process_list): Use them.
(_wsplt_subsplit, wordsplit_string_unquote_copy):
Don’t limit lengths to INT_MAX.
(wordsplit_run): Remove.  All callers changed to use wordsplit_len.
(wordsplit_perror): Don’t limit lengths to ULONG_MAX.
* lib/wordsplit.c (wordsplit_init, alloc_space, struct wordsplit_node)
(wsnode_len, wordsplit_add_segm, coalesce_segment, wsnode_quoteremoval)
(wordsplit_finish, wordsplit_append, node_split_prefix)
(find_closing_paren, wordsplit_find_env, wsplt_assign_var)
(expvar, node_expand, expcmd, wordsplit_trimws)
(wordsplit_tildexpand, isglob, wordsplit_pathexpand)
(skip_sed_expr, skip_delim_internal, skip_delim)
(skip_delim_real, scan_qstring, scan_word)
(wordsplit_c_quoted_length, wordsplit_process_list)
(wordsplit_len, wordsplit_free_words, wordsplit_get_words):
* lib/wordsplit.h (struct wordsplit):
Prefer idx_t to size_t for indexes.
* lib/wordsplit.h: Include idx.h.
2024-08-04 01:41:43 -07:00
Paul Eggert
cc691f8272 Support >INT_MAX -C dirs
* src/extract.c (struct delayed_set_stat, struct delayed_link):
* src/misc.c (normalize_filename, wd_count, chdir_count)
(chdir_arg, tar_getcdpath):
* src/names.c (name_gather, addname, add_hierarchy_to_namelist):
* src/unlink.c (struct deferred_unlink, flush_deferred_unlinks):
Use idx_t, not int, for directory indexes, so as to not
limit their number to INT_MAX; this is theoretically possible
if -T is used.
* src/names.c (name_next_elt, name_next):
Use bool for boolean.
2024-08-04 01:41:43 -07:00
Paul Eggert
390950282d maint: fix some encodings and email addresses 2024-08-04 01:41:43 -07:00
Paul Eggert
f13f2d6815 Parse level options more reliably
* src/tar.c (parse_opt): Don’t mishandle out-of-range LEVEL_OPTION.
2024-08-04 01:41:43 -07:00
Paul Eggert
c26c2ea2e9 Minor utf8.c improvements
* src/utf8.c: Minor rephrases for -1.
2024-08-04 01:41:43 -07:00
Paul Eggert
51c841b927 Simplify ST_DEV_MSB
* src/incremen.c (ST_DEV_MSB):
Use TYPE_WIDTH rather than computing it by hand.
2024-08-04 01:41:43 -07:00
Paul Eggert
aca308a778 Use ckd_mul, ckd_add in to_octal, to_base256
* src/create.c (to_octal, to_base256): Simplify.
2024-08-04 01:41:43 -07:00
Paul Eggert
414f635d8b Use ckd_mul, ckd_add in from_header
* src/common.h (LG_64): Remove; no longer used.
* src/list.c (from_header):
Use ckd_mul, ckd_add rather than doing it by hand.
2024-08-04 01:41:43 -07:00
Paul Eggert
281e03ec6c Prefer < 0 to == -1 where either will do
Also, fix an unlikely read overflow in sys_exec_setmtime_script.
* src/buffer.c (open_compressed_archive):
* src/compare.c (verify_volume):
* src/exclist.c (info_attach_exclist):
* src/misc.c (xfork):
* src/sparse.c (sparse_scan_file_seek):
* src/system.c (sys_wait_for_child, sys_spawn_shell)
(wait_for_grandchild, sys_wait_command, sys_exec_info_script)
(sys_exec_checkpoint_script, sys_exec_setmtime_script):
* src/transform.c (_single_transform_name_to_obstack):
* src/xattrs.c (xattrs__acls_set, xattrs_acls_get)
(xattrs_xattrs_get, xattrs__fd_set, xattrs_selinux_get)
(xattrs_selinux_set):
* tests/checkseekhole.c (check_seek_hole, main):
Simplify failure tests by just looking at return value sign.
* src/system.c (sys_exec_setmtime_script):
Don’t assume ‘read’ result fits in int.
(sys_exec_setmtime_script): Don’t reject 1 second before Epoch.
2024-08-04 01:41:43 -07:00
Paul Eggert
9cb1293628 xsparse dry runs should not create output
* scripts/xsparse.c (expand_sparse, main): Check for syscall
failure.  Do not create output file if a dry run.
2024-08-04 01:41:43 -07:00
Paul Eggert
44196e198f Better xsparse outname guessing
* scripts/xsparse.c (guess_outname): Use simpler algorithm,
that doesn’t mishandle outnames like ‘/foo’.
2024-08-04 01:41:43 -07:00
Paul Eggert
ba332e36d0 Use xalignalloc
It ports around issues that our handwritten code does not.
* gnulib.modules: Add xalignalloc.
* src/misc.c (ptr_align, page_aligned_alloc): Remove.
All page_aligned_alloc callers changed to use xalignalloc.
2024-08-04 01:41:43 -07:00
Paul Eggert
61656ef35b Make stripped_prefix_len signed
This is part of the general guideline that signed integer types
are safer.
* src/names.c (stripped_prefix_len): Return ptrdiff_t,
not size_t.  All callers changed.
2024-08-04 01:41:43 -07:00
Paul Eggert
fbc60c2334 from_header minor width cleanup
* src/list.c (from_header): Use UINTMAX_WIDTH rather than
computing it by hand.
2024-08-04 01:41:43 -07:00
Paul Eggert
a78af4b95e Don’t assume mode_t fits in unsigned long
* src/system.c (oct_to_env): Don’t assume mode_t fits in unsigned
long.  Do not output excess leading 1 bits.  When the mode is
zero, generate "0" rather than "00".  Use sprintf instead of
snprintf, since the output won’t be truncated; in general we don’t
use snprintf unless we want output to be truncated and truncation
is typically not GNU style.
2024-08-04 01:41:43 -07:00
Paul Eggert
c26111742a Prefer C99 formats like %jd to doing it by hand
It’s now safe to assume support for C99 formats like %jd, so remove
some of the longwinded formatting code put in only to be portable to
pre-C99 platforms.
* gnulib.modules: Add intprops.
* src/buffer.c (format_total_stats, try_new_volume)
(write_volume_label):
* src/checkpoint.c (format_checkpoint_string):
* src/compare.c (verify_volume):
* src/create.c (to_chars_subst, dump_regular_file):
* src/incremen.c (read_num):
* src/list.c (read_and, from_header, simple_print_header)
(print_for_mkdir):
* src/sparse.c (sparse_dump_region):
* src/system.c (dec_to_env, sys_exec_info_script)
(sys_exec_checkpoint_script):
* src/xheader.c (out_of_range_header):
Prefer C99 formats like %jd and %ju to STRINGIFY_BIGINT.
* src/common.h: Sort includes.
Include intprops.h, verify.h.  All other includes of verify.h
removed.
(intmax, uintmax): New functions and macros.
(STRINGIFY_BIGINT): Remove; no longer used.
(TIMESPEC_STRSIZE_BOUND): Make it 1 byte bigger, for negatives.
* src/create.c (MAX_VAL_WITH_DIGITS, to_base256):
Use *_WIDTH macros rather than assuming no padding bits.
Prefer UINTMAX_MAX to (uintmax_t) -1.
* src/list.c (tartime): Use strftime result rather
than running strlen later.
* src/misc.c (timetostr): New function.  Prefer it when
printing time_t values.
2024-08-04 01:41:43 -07:00
Paul Eggert
6c91bd82e1 Fix unlikely problems with time overflow
Also, fix some rounding errors while we’re in the neighborhood.
* src/buffer.c (duration_ns, compute_duration_ns): Rename from
‘duration’ and ‘compute_duration’, and count ns rather than s, to
lessen rounding error.  All uses changed.
(compute_duration_ns): Work even if the clock moves backward
and time_t is unsigned.
(print_stats): Don’t worry about null or empty TEXT, as that
cannot happen.  Compare double to UINTMAX_MAX + 1.0, not
to UINTMAX_MAX, so that the comparison is exact.
Handle the unlikely case that numbytes >= UINTMAX_MAX.
* src/tar.c (parse_opt): Treat -L hugenumber as effectively
infinity rather than erroring out.
Prefer ckd_add to checking overflow by hand.
2024-08-04 01:41:43 -07:00
Paul Eggert
aae99e863d maint: omit space between "*" and "p" 2024-08-04 01:41:43 -07:00
Paul Eggert
39d315e8ea ptrdiff_t, not int
* src/delete.c (delete_archive_members): Use ptrdiff_t, not int,
to count memory blocks.
(write_recent_bytes): Simplify remainder calculation.
2024-08-04 01:41:43 -07:00
Paul Eggert
bf195d4ae4 ptrdiff_t, not ssize_t
* src/buffer.c (bufmap_reset, _flush_write):
Use ptrdiff_t, not ssize_t, to record pointer differences.
POSIX allows systems where size_t is 64 bits but ssize_t is only 32;
Ultrix used to do that, though no current systems do.
2024-08-04 01:41:43 -07:00
Paul Eggert
a9372cf08a Prefer stdckdint.h to intprops.h
Problem reported by Collin Funk in:
https://lists.gnu.org/r/bug-tar/2024-07/msg00000.html
though this patch is more general than Collin’s suggestion.
* src/compare.c (diff_multivol):
* src/delete.c (move_archive):
* src/sparse.c (oldgnu_add_sparse, pax_decode_header):
* src/system.c (mtioseek):
Prefer ckd_add and ckd_mul to the intprops.h equivalents,
since stdckdint.h is now standard.
2024-08-04 01:41:43 -07:00
Paul Eggert
be1aa32c6d Use ckd_add in page_aligned_alloc
* src/misc.c (page_aligned_alloc): Use ckd_add
instead of doing overflow checking by hand.
2024-08-04 01:41:43 -07:00
Paul Eggert
8a3fc52972 Simplify read_header overflow checking
* src/list.c (read_header): Use ckd_add instead of
doing overflow checking by hand.  Although the old code
was correct on all practical hosts, the new code is simpler
and works even on weird hosts where SIZE_MAX <= INT_MAX.
2024-08-04 01:41:43 -07:00
Paul Eggert
927d67855e Cleaner overflow checking in xheader_read
* src/xheader.c (xheader_read): Prefer ckd_add to
doing overflow checking by hand.
2024-08-04 01:41:43 -07:00
Paul Eggert
c6a5af16ba maint: use static_assert
* gnulib.modules: Add assert-h, for static_assert.
* src/common.h, src/list.c, src/misc.c:
Prefer static_assert to #if + #error.  This doesn’t fix any bugs; it’s
just that in general it’s better to avoid the preprocessor.
2024-08-04 01:41:43 -07:00
Paul Eggert
dcc90722ac Fix tests/ckmtime.c arithmetic
* tests/ckmtime.c (main): Don’t assume time_t is signed.
Avoid integer overflows (quite possible if time_t is 32 bit).
Do calculations precisely, without any rounding errors.
2024-08-04 01:41:43 -07:00
Paul Eggert
7557fdd4df Fix unlikely overflow in utf8_convert
* src/utf8.c (utf8_convert): Check for integer overflow.
2024-08-04 01:41:43 -07:00
Paul Eggert
91ee466c8a Fix unlikely overflow in transform.c
* src/transform.c (_single_transform_name_to_obstack):
Use xinmalloc to check for integer overflow.
2024-08-04 01:41:43 -07:00
Paul Eggert
7079fc369b Better overflow checking for blocking factor
* src/tar.c (parse_opt): Use ckd_add and ckd_mul instead of
less-obvious code that relies on implementation-defined
conversions.
2024-08-04 01:41:43 -07:00
Paul Eggert
b26e798a0f xsparse cleanup, including integer overflow
* scripts/xsparse.c: Include inttypes.h, for strtoimax.
Don’t include stdint.h, since inttypes.h includes it.
Sort include directives.
Make all extern functions and vars static, except for ‘main’.
(string_to_off): Use strtoimax instead of doing overflow
checking by hand, incorrectly (it relied on undefined behavior).
(string_to_size): New arg MAXSIZE.  All callers changed.
(get_var): Return bool not int.  Fix unlikely integer overflow.
Use strncmp instead of memcmp, to avoid unlikely pointer overflow.
(read_xheader, read_map, main): Avoid unlikely integer overflow.
Check for I/O errors more consistently.
(main): Prefer bool to int, and put vars near use.
2024-08-04 01:41:43 -07:00
Paul Eggert
f22b9fe3ce maint: fix some unlikely wordsplit overflows
* gnulib.modules: Add reallocarray.
* lib/wordsplit.c: Include stdckdint.h.
(ISDELIM, expvar, isglob, scan_word):
Defend against strchr (s, 0) always succeeding.
(alloc_space, wsplit_assign_vars):
Fix some unlikely integer overflows, partly by using reallocarray.
(alloc_space): Avoid quadratic worst-case behavior.
(isglob): Return bool, not int.  Accept size_t, not int.
(to_num): Remove; no longer used.
(xtonum): Clarify the code the bit.  Rely on portable
conversion to unsigned char rather than problematic pointer cast.
2024-08-04 01:41:42 -07:00
Paul Eggert
8f094605a8 maint: prefer C23 if available
* gnulib.modules: Add std-gnu23.
2024-07-29 00:41:34 -07:00
Paul Eggert
26d1e4ddbc Add some gnulib.modules
* gnulib.modules: Add errno, limits-h, safe-read, sys_stat.
Not sure about the relationship between gnulib.modules
and paxutils/gnulib.modules, but anyway tar itself uses
these so we should depend on them.  (Perhaps it would be
better if there was just one Gnulib module list for tar;
that would be less confusing.)
2024-07-29 00:41:34 -07:00
Paul Eggert
ec35690e91 build: update gnulib and paxutils submodules to latest 2024-07-29 00:41:34 -07:00
Paul Eggert
3fa1fd0751 Pacify gcc 14 -Wanalyzer-null-argument
* src/tar.c (optloc_eq): Add another ‘assume’.
2024-07-27 00:26:42 -07:00
Paul Eggert
fd33f25989 Pacify gcc 14 -Wanalyzer-infinite-loop
* gnulib.modules: Add stddef, for ‘unreachable’.
* src/compare.c (dumpdir_cmp): Tell GCC that the default case
is unreachable.  Make just one pass through the string,
instead of two passes (one via strcmp, another via strlen).
2024-07-27 00:26:42 -07:00
Paul Eggert
45a86d45b2 maint: make a few funcs and vars static
* src/buffer.c (last_stat_time, write_fatal_details):
* src/tar.c (name_more_files):
* src/xattrs.c (xheader_xattr_add):
Now static.
2024-07-26 23:44:03 -07:00
Paul Eggert
afd073399a maint: remove GLOBAL as per GCC 14
* src/common.h (GLOBAL): Remove this macro, and all its uses.
It collides with GCC 14 and -Wmissing-variable-declarations.
Change all uses of GLOBAL to use extern instead,
and declare the variables in their respective .c files.
Move .c file’s extern declarations here, so that they
appear only once and are checked against definitions.
* src/names.c (unconsumed_option_tail): Now static.
2024-07-26 23:44:03 -07:00
Paul Eggert
9f1c32c18b Modernize use of Gnulib, paxutils
* configure.ac: Omit stuff no longer needed now that Gnulib or
paxlib does it, or the code no longer needs the configure-time checks.
Do not use AC_SYS_LARGEFILE (Gnulib largefile does this) or check
for fcntl.h, memory.h, net/errno.h, sgtty.h, string.h,
sys/param.h, sys/device.h, sys/gentape.h, sys/inet.h,
sys/io/trioctl.h, sys/time.h, sys/tprintf.h, sys/tape.h, unistd.h,
locale.h, netdb.h; these are all now standard, or old ways of getting
at magtapes are no longer needed and we now have only sys/mtio.h.
Do not check for lstat, readlink, symlink, and check only for
waitpid’s existence rather than attempting to replace it.
Do not check for decls of getgrgid, getpwuid, or time.
Check just once for iconv.h.
* gnulib.modules: Add largefile.
* lib/.gitignore, lib/Makefile.am (noinst_HEADERS, libtar_a_SOURCES):
Remove system-ioctl.h, which is no longer in paxlib.
All includes now changed to just check HAVE_SYS_MTIO_H directly.
* lib/wordsplit.c (wordsplit_c_escape_tab, wordsplit_errstr)
(wordsplit_nerrs):
Now static or an enum, and without any leading "_" in the name.
* src/buffer.c (record_start, record_end, current_block, records_read):
* src/delete.c (records_skipped): Add extern decl to pacify GCC.
* src/compare.c, src/create.c, src/extract.c: Omit uses of
HAVE_READLINK and HAVE_SYMLINK since we now let Gnulib deal with
platforms lacking readlinkat and symlinkat.
* src/system.c: Use "#if !HAVE_WAITPID" instead of "#if MSDOS".
2024-07-26 21:56:20 -07:00
Paul Eggert
4e0deb7416 build: update gnulib and paxutils submodules to latest 2024-07-26 21:56:20 -07:00
Paul Eggert
3d2c735b7c maint: higher-precision checkpoint timestamps
* src/checkpoint.c (format_checkpoint_string):
Use current_timespec to get nanosecond resolution.
This also frees us from the necessity of including <sys/time.h>
to use gettimeofday, which is removed in POSIX.1-2024.
2024-07-24 10:04:16 -07:00
Paul Eggert
bd066ac0a5 build: update gnulib and paxutils submodules to latest 2024-07-24 10:04:16 -07:00
Paul Eggert
b96cabb1ea Sync bootstrap from Gnulib 2024-07-24 10:04:16 -07:00
Paul Eggert
42d1143dd5 Sync bootstrap from Gnulib 2024-07-15 14:59:33 -07:00
Paul Eggert
2b9e2cc947 maint: adjust to Gnulib -Wsystem-headers change
* configure.ac: Do not suppress -Wsystem-headers, as
Gnulib no longer enables it.
2024-07-15 14:59:33 -07:00
Paul Eggert
1752231f9e build: update gnulib submodule to latest 2024-07-15 14:59:33 -07:00
Sergey Poznyakoff
5f2cda027d Various formatting fixes 2024-06-07 00:05:00 +03:00
Sergey Poznyakoff
1e6ce98e3a Fix spurious diagnostic during extraction of . with --keep-newer-files
Bug reported in https://savannah.gnu.org/bugs/?65838.

Bug introduced by 79d1ac38c1.

* src/extract.c (make_directories): Restore second argument.  This
reverts the change made in 79d1ac38c1.
(maybe_recoverable, rename_directory): Update calls to make_directories.
* tests/extrac27.at: New file.
* tests/Makefile.am: Add new test.
* tests/testsuite.at: Likewise.
2024-06-05 18:19:10 +03:00
Paul Eggert
883f2e6dca tar: fix current_block confusion
Problem reported by Robert Morris in:
https://lists.gnu.org/r/bug-tar/2024-03/msg00001.html
* src/delete.c (flush_file): Simply return at EOF,
so that current_block continues to point to end of input.
2024-03-03 13:28:23 -08:00
Paul Eggert
628c49250a tar: fix unlikely overflow
* src/delete.c (flush_file): Fix arithmetic overflow if
TYPE_MAXIMUM (off_t) - BLOCKSIZE < current_stat_info.stat.st_size.
2024-03-03 13:28:23 -08:00
Paul Eggert
21318f3856 tar: improve diagnostic for truncated archive
* src/buffer.c (seek_archive): If EOF has been read, don’t attempt
to seek past it.  This replaces a bogus "rmtlseek not stopped at a
record boundary" message with a better "Unexpected EOF in archive"
when I run ‘tar tvf gtar13c.tar’ using the gtar13.tar file here:
https://lists.gnu.org/r/bug-tar/2024-03/msg00001.html
2024-03-03 13:28:23 -08:00
Sergey Poznyakoff
fac2b4c11a Avoid gcc 13 "unused parameter" warnings 2024-01-16 14:28:19 +02:00
Sergey Poznyakoff
6ba24c31c6 Recognize suffixes .z (gzip) and .tzo (lzop) 2024-01-15 22:52:27 +02:00
Sergey Poznyakoff
7b65ae35ab Fix description of the CACHEDIR.TAG file. 2024-01-15 22:30:22 +02:00
Sergey Poznyakoff
f622c07108 Fix --exclude-ignore option.
This fixes https://savannah.gnu.org/bugs/?64387.

* src/exclist.c (info_attach_exclist): Always use file->flags.
(exclude_vcs_ignores): Pass flags from struct vcs_ignore_file
to excfile_add.

* tests/exclude19.at: New test.
* tests/exclude20.at: New test.
* tests/Makefile.am: Add new tests.
* tests/testsuite.at: Add new tests.
2024-01-15 21:24:34 +02:00
Sergey Poznyakoff
d763055edd Fix missing space in the manual 2024-01-15 20:21:26 +02:00
Sergey Poznyakoff
b4d1fa77b6 When given -c -a, issue a warning if no compressor is associated with the suffix.
* src/suffix.c (find_compression_suffix): Always return stripped
archive name length in the last argument.  Return 0 if there is no
suffix.
(find_compression_program): Remove.
(set_compression_program_by_suffix): Take third argument, controlling
whether to issue a warning if no suitable compression program is found
for the suffix.
* src/common.h (set_compression_program_by_suffix): Change prototype.
* src/buffer.c, src/tar.c: All uses of set_compression_program_by_suffix
changed.
2024-01-15 00:00:02 +02:00
Paul Eggert
66eaa2f821 Port EOF detection test to macOS
* tests/delete06.at: Don’t assume the diagnostic is
“Value too large for defined data type”, as strerror
uses a different wording on macOS 12.6.
2024-01-01 19:12:10 -08:00
Paul Eggert
24a2fcfd83 Skip test on macOS 12.6
* tests/xform04.at: Skip test on macOS 12.6, which is behind the times
and doesn’t think that ⱥ (U+2C65 LATIN SMALL LETTER A WITH STROKE) is
printable.
2024-01-01 19:12:10 -08:00
Paul Eggert
835b0c7dee Port --numeric-owner basic tests to macOS
* tests/numeric.at: If chown fails, skip the test.
This is needed on macOS 12.6 if the user has group
ID 4294967295 (nogroup), which chown rejects.
2024-01-01 19:12:10 -08:00
Paul Eggert
c6f0ad5117 Update copyright years
UPDATE_COPYRIGHT_USE_INTERVALS=1 \
gnulib/build-aux/update-copyright \
  $(git ls-files | sed -e '/^gnulib$/d
			   /^paxutils$/d
			   /^COPYING$/d
			   /\/fdl.texi$/d')
sed -i '2000,${
    /^Copyright @copyright/d
    s/^[0-9]*--\(2024 Free Software Foundation, Inc.\)/Copyright (C) \1/
  }' doc/tar.texi
2024-01-01 19:08:46 -08:00
Paul Eggert
f0098df0b3 doc: fix date in example
* doc/tar.texi: Fix copyright date in example.
2024-01-01 19:08:46 -08:00
Paul Eggert
3a27df1d69 build: update gnulib submodule to latest 2024-01-01 19:08:46 -08:00
Paul Eggert
c1e277476c Support multi-byte --transform='...\L...' etc
Support upcasing and downcasing in multi-byte locales.
* gnulib.modules: Add c32rtomb, c32tolower, c32toupper,
mbrtoc32-regular.
* src/transform.c: Do not include ctype.h.  Include mcel.h.
(stk, stk_init): Move up.
(run_case_conv): Return void, not char *.  Append result to
stk directly; this avoids the need for a separate allocation.
All callers changed.  Do not assume a single-byte locale.
* tests/xform04.at: New test.
* tests/Makefile.am (TESTSUITE_AT):
* tests/testsuite.at: Add it.
2023-09-12 23:23:41 -05:00
Paul Eggert
783321ff1b Simplify wordsplit_string_unquote_copy
* lib/wordsplit.c (wordsplit_string_unquote_copy): Simplify.
2023-09-12 23:23:41 -05:00
Paul Eggert
01f986b921 Parse in a more locale-independent way
update submodules to latest
* gnulib.modules: Add c-ctype.
* lib/wordsplit.c, src/buffer.c, src/exclist.c, src/incremen.c:
* src/list.c, src/misc.c, src/names.c, src/sparse.c, src/tar.c:
* src/xheader.c:
Include c-ctype.h, and use its API rather than ctype.h’s.
This is more likely to work when oddball locales are used.
* src/transform.c: Include ctype.h, since this module still uses
tolower and toupper (this is probably wrong - should be multi-byte).
2023-09-12 23:23:41 -05:00
Paul Eggert
05fcfaafb6 Use single is_octal_digit function
* src/list.c (ISOCTAL): Remove.
(is_octal_digit): New static function.
All uses of ISOCTAL and ISODIGIT replaced with is_octal_digit.
2023-09-12 23:23:40 -05:00
Paul Eggert
e35fe3a77c maint: fix THANKS misspellings
* THANKS: Fix recently-introduced misspellings.
2023-09-11 09:32:18 -05:00
Paul Eggert
78d4ccd755 Fix pointer bug in drop_volume_label_suffix
Problem reported by Marc Espie in:
https://lists.gnu.org/r/bug-tar/2023-09/msg00003.html
* src/buffer.c (drop_volume_label_suffix):
Redo to not compute a pointer before the start of a buffer,
as this is not portable.
2023-09-11 01:17:29 -05:00
Paul Eggert
9599d193b8 quote unknown header keywords in diagnostics
* src/xheader.c (decx): Quote unknown header in warning, as it may
contain control characters.  Problem reported by Wicher Minnaard.
2023-09-11 01:17:29 -05:00
Paul Eggert
e1bba5e7dd Prefer mcel to mbuiter
Prefer the lighter-weight mcel implementation to the heavier-weight
mbuiter that GNU tar does not need.
* bootstrap.conf (avoided_gnulib_modules): Avoid mbuiter, mbuiterf.
* gnulib.modules: Add mcel-prefer.
2023-09-10 10:12:20 -07:00
Paul Eggert
f2613580c7 build: update gnulib submodule to latest 2023-09-10 10:12:20 -07:00
Markus Mayer
1cdad4cc28 .gitmodules: switch to HTTPS
HTTPS is not only encrypted but also better suited for corporate
firewalls. Let's use it to clone submodules.
Copyright-paperwork-exempt: yes
2023-09-07 14:33:37 -07:00
Sergey Poznyakoff
ecdef6677b docs: replace references to fileutils with coreutils.
GNU fileutils is decommissioned and superseded by coreutils.
This fixes Savannah bug #64495.
2023-08-22 23:55:09 +03:00
Sergey Poznyakoff
5114218025 Fix Savane bug #64581
This reverts commit 4f3824743f.
2023-08-22 18:34:20 +03:00
Paul Eggert
a9a8990fb3 Bump extrac26 timeout
* tests/extrac26.at: Increase timeout from 15 to 60 s.
On my old machine it took 15 s.
2023-08-21 13:42:14 -07:00
Paul Eggert
12b58a69aa Simplify recently-added hash code
* src/extract.c (delay_set_stat): Simplify hash lookup;
no need to initialize members other than file_name.
Avoid assignment in ‘if’ when it’s easy.
(extract_finish): Do not bother to free when we are about to exit.
2023-08-21 13:42:14 -07:00
Benjamin Woodruff
a5afb36765 Fix O(n^2) time bug in --delay-directory-restore
delayed_set_stat avoids inserting duplicate entries into
delayed_set_stat_head. It was doing this by scanning the entire
list.

Normally this list is small, but if --delay-directory-restore is
used (including automatically for incremental archives), this list
grows with the total number of directories in the archive.

The entire scan takes O(n) time. Extracting an archive with n
directories could therefore take O(n^2) time.

The included test uses AT_SKIP_LARGE_FILES, allowing it to optionally be
skipped. It may execute slowly on certain filesystems or disks, as it
creates thousands of directories.

There are still potentially problematic O(n) scans in
find_direct_ancestor and remove_delayed_set_stat, which this patch does
not attempt to fix.

* NEWS: Update.
* src/extract.c (delayed_set_stat_table): Create a table for O(1)
lookups of entries in the delayed_set_stat_head list. The list
remains, as tracking insertion order is important.
(dl_hash, dl_compare): New hash table helper functions.
(delay_set_stat): Create the hash table, replace the O(n) list scan
with a hash_lookup, insert new entries into the hash table.
(remove_delayed_set_stat): Also remove entry from hash table.
(apply_nonancestor_delayed_set_stat): Also remove entry from hash
table.
(extract_finish): Free the (empty) hash table.
* tests/extrac26.at: New file.
* tests/Makefile.am (TESTSUITE_AT): Include extrac26.at.
* tests/testsuite.at: Include extrac26.at.
2023-08-21 13:42:14 -07:00
Paul Eggert
bfee1d44a3 Pacify gcc -Wanalyzer-fd-use-without-check
* src/system.c (sys_exec_setmtime_script):
Treat fds with more care.
2023-08-21 13:42:14 -07:00
Paul Eggert
8131ca7b26 build: update gnulib submodule to latest 2023-08-21 13:42:14 -07:00
Sergey Poznyakoff
d437ecf75d Revert "Fix savannah bug #63567"
Commit e89c7a45eb broke deletion from archives. The reported number
of bytes read is rounded to the nearest record anyway, revert the
commit and document the fact.

Reported by Ed Santiago. See
https://bugzilla.redhat.com/show_bug.cgi?id=2230127

* doc/tar.texi: Document the fact that --totals rounds up the
number of bytes reads to the nearest record.
* src/buffer.c: Revert changes.
* tests/delete06.at: Fix expected status code and stderr.
2023-08-15 11:34:21 +03:00
Paul Eggert
8e5483577d Stop using alloca
* gnulib.modules: Remove alloca.
* src/create.c (dump_file0): Return address of any allocated
storage.  Caller changed to free it.  Use xmalloc instead
of alloca, to obtain this storage.
* src/list.c (from_header): Use quote_mem instead of quote,
removing the need to use alloca.
2023-08-02 09:02:33 -07:00
Sergey Poznyakoff
9a30bb2674 New option: --set-mtime-command
* NEWS: Document new option.
* src/common.h (COMMAND_MTIME): New constant.
* src/create.c (set_mtime_command)
(set_mtime_format): New globals.
(sys_exec_setmtime_script): New prototype.
* src/system.c (start_header): Handle COMMAND_MTIME.
* src/tar.c (sys_exec_setmtime_script): New function.
2023-08-01 15:45:14 +03:00
Paul Eggert
eb30aa7801 * doc/tar.texi: Fix minor reproducibility typos. 2023-07-25 09:45:46 -07:00
Paul Eggert
68636f0bcb Improve reproducibility recipe
* doc/tar.texi (Reproducibility): Improve index.
Improve and add comments to recipe.  In the recipe,
don’t worry about file names beginning with ‘-’ for simplicity;
don’t use touch -c as it exits with status 0 even when it
does not work; and set directory timestamps too.
2023-07-25 09:43:57 -07:00
Sergey Poznyakoff
8ed95e92ef * doc/tar.texi: Define reproducibility. 2023-07-25 09:43:57 -07:00
Paul Eggert
d1ca333391 New doc about reproducible archives
* doc/tar.texi (Reproducibility): New section.
Spruce some other sections related to timestamps etc.
2023-07-24 14:46:53 -07:00
Paul Eggert
71530f72d2 tests: fix LDADD
Problem reported by Christian Weisgerber <naddy@mips.inka.de> in:
https://lists.gnu.org/r/bug-tar/2023-07/msg00015.html
* tests/Makefile.am (LDADD): Add $(LIBINTL), $(LIBICONV).
2023-07-19 15:49:18 -07:00
Sam James
18f90676e4 tests: Fix xz tests by unsetting XZ_OPT, XZ_DEFAULTS
Copyright-paperwork-exempt: true
2023-07-18 09:57:24 -07:00
Sam James
7687bf4acc tests: Fix bashism in testsuite.at
&> is a bashism and causes various tests to fail with /bin/sh as non-bash
(e.g. dash). Use the same pattern the rest of the file uses instead of &>.

Copyright-paperwork-exempt: true
2023-07-18 09:47:26 -07:00
Paul Eggert
39849e9d91 tests: fix TESTSUITE_AT
Problem reported by Lukas Javorsky <ljavorsk@redhat.com> in:
https://lists.gnu.org/r/bug-tar/2023-07/msg00002.html
* tests/Makefile.am (TESTSUITE_AT): Add exclude17.at, exclude18.at.
Remove compress.m4; all uses changed.  Add a comment saying how
to rederive this.  Sort.
2023-07-18 09:31:17 -07:00
Sergey Poznyakoff
8632df398b Fix savannah bug #64441
* src/Makefile.am (tar_LDADD): Add libiconv libraries.
2023-07-18 17:02:23 +03:00
Sergey Poznyakoff
e545d446df Version 1.35 2023-07-18 09:38:30 +03:00
Sergey Poznyakoff
e7a5e12445 Use full-read instead of safe-read
This helps handle archiving on certain filesystems where read()
returns less bytes than requested when reading from a regular
file.

References:

  https://savannah.gnu.org/bugs/index.php?64426
  https://lists.gnu.org/archive/html/bug-tar/2021-07/msg00001.html

* gnulib.modules: Add full-read.
* src/common.h: Include full-read.h
* src/misc.c: Use full_read.
* src/sparse.c: Likewise.
* src/update.c: Likewise.
2023-07-17 17:07:12 +03:00
Sergey Poznyakoff
31f68bbe2a Fix typo in comments
This and the bug fixed by the previous commit were reported by
Benno Schulenberg.
2023-07-11 09:16:15 +03:00
Sergey Poznyakoff
10954cf163 Fix --update --wildcards
* src/common.h (name): New field: is_wildcard.
(name_scan): Change protoype.
* src/delete.c: Update calls to name_scan.
* src/names.c (addname, add_starting_file): Initialize is_wildcard.
(namelist_match): Take two arguments.  If second one is true, return
only exact matches.
(name_scan): Likewise.  All callers updated.
(name_from_list): Skip patterns.
* src/update.c (remove_exact_name): New function.
(update_archive): Do not remove matching name, if it is a pattern.
Instead, add a new entry with the matching file name.

* tests/update04.at: New test.
* tests/Makefile.am: Add new test.
* tests/testsuite.at: Include new test.

* NEWS: Update.
2023-07-10 21:25:30 +03:00
Benno Schulenberg
b3a71dbdb9 Various fixes in the documentation
* doc/tar.1: Add missing dots, use plural when necessary,
tweak a wording.  Remove an incorrect observation, three times.
Add some missing articles, correct some formatting,
and expand the opaque descriptions of two options.
* doc/tar.texi: Drop a stray `cd` command from an example.
Correct two cross references, correct the paragraph
about the manpage, and unbreak a URL.
* src/names.c: Correct and shorten an error message: "non-optional"
means "mandatory", but "non-option" is what was meant.  And the
phrase "in archive create or update mode" was both unneeded and
incomplete.
* tests/positional01.at: Change expected error text.
* tests/positional02.at: Likewise.
* tests/positional03.at: Likewise.
2023-07-10 12:33:34 +03:00
Paul Eggert
cf16a23945 build: update gnulib submodule to latest 2023-06-28 17:43:48 -07:00
Paul Eggert
d6a60bba76 tar: extract delayed links in order
Extract delayed links in tar file order, rather than
in hash table order with modifications.
This is simpler and more likely to use the kernel’s
cached filesystem data, assuming related delayed links
are nearby in the tar file.
* src/extract.c (struct delayed_link.has_predecessor):
Remove.  All uses removed.
(delayed_link_head, delayed_link_tail): New static vars.
This resurrects delayed_link_head’s old function
except that the linked list is now in forward order, not reverse.
(find_delayed_link_source): Now simply returns bool,
since the callers no longer need the pointer.
(create_placeholder_file):
Put the delayed link at the end of the linked list.
Omit no-longer-needed last arg.  All callers changed.
(apply_delayed_links): Simplify now that we can just iterate
through the delayed_link_head list.
2023-06-25 14:28:36 -07:00
Paul Eggert
2ccd643d01 tar: make safe for -Wunused-parameter
This also ports to C23 [[maybe_unused]].
* configure.ac (WARN_CFLAGS): Do not add -Wno-unused-parameter.
Add MAYBE_UNUSED where needed in source code.
Also, put it at the front where C23 requires it.
2023-06-25 14:28:36 -07:00
Paul Eggert
fdff045d4b * po/.gitignore: Omit redundant *~ entries. 2023-06-25 14:28:36 -07:00
Paul Eggert
90cceec4bb tar: omit unnecessary freeing
* src/tar.c (main): Omit unnecessary freeing.
2023-06-25 14:28:36 -07:00
Sergey Poznyakoff
826c5eb64e Make sure each delayed link entry is visited once
* src/extract.c (create_placeholder_file): Use FLEXNSIZEOF (overlooked
by c542d3d0c8)
(apply_delayed_links): Don't follow the "next" chain after its entries
have been applied.
2023-06-18 09:20:28 +03:00
Paul Eggert
2096772fbe Omit unnecessary freeing
* src/extract.c (apply_delayed_link): Don’t bother to
free memory, as we’re about to exit.
2023-06-17 00:37:43 -07:00
Paul Eggert
c542d3d0c8 Port to strict C99 struct hack
Portability bug caught by GCC 13 -fstrict-flex-arrays.
* gnulib.modules: Add flexmember.
* src/create.c (struct link):
* src/exclist.c (struct excfile):
* src/extract.c (struct delayed_link, struct string_list):
Include <flexmember.h>.  Use FLEXIBLE_ARRAY_MEMBER, for
portability to strict C99 or later.  All storage
allocations changed to use FLEXNSIZEOF.
2023-06-16 17:12:40 -07:00
Paul Eggert
4c7a3798d8 Use Gnulib ‘dup2’ module
This simplifies code that would otherwise use dup and close.
* gnulib.modules: Add dup2.
* src/system.c: Add #pragma to pacify GCC 13.
(xdup2): Simplify by using dup2.
2023-06-16 17:12:40 -07:00
Paul Eggert
5d6736e394 Use Gnulib ‘free-posix’ module
Paxutils uses it so we should too.
* gnulib.modules: Add ‘free-posix’.
* src/misc.c (remove_any_file): Assume ‘free’ keeps errno.
2023-06-16 17:12:39 -07:00
Paul Eggert
9ee30c9804 * buffer.c: work around GCC bug 109856 2023-06-16 17:12:39 -07:00
Paul Eggert
4695adfd59 Recommend Y2038 safety 2023-06-16 17:12:39 -07:00
Paul Eggert
a484178a18 build: update gnulib and paxutils submodules to latest 2023-06-16 17:12:39 -07:00
Paul Eggert
e39b93d822 * .gitignore: Add slash, as bootstrap does this now. 2023-06-16 17:12:39 -07:00
Paul Eggert
8ccfc4e416 Sync bootstrap from Gnulib 2023-06-16 17:12:39 -07:00
Pavel Raiskup
e7987b72c6 Comment a bit on the xattr extraction logic
* src/extract.c (extract_file): Document why we pre-create with S_IWUSR.
(set_xattr): Drop the INVERT_PERMISSIONS doc leftover.
2023-06-06 12:37:06 +03:00
Pavel Raiskup
06805b9281 Fix --xattr-include='*' documentation
* doc/tar.texi (Extended File Attributes): The default extraction
pattern consists of just 'user.*' namespace only.  While on it, try
to explain the reasons for this default behavior.
2023-06-06 12:34:08 +03:00
Sergey Poznyakoff
5461025569 Honor --numeric-owner when storing ACL entries
Based on patch from Fabian Grünbichler <f.gruenbichler@proxmox.com>

* src/xattrs.c (acls_get_text): New function.  If given --numeric-owner,
use acl_to_any_text to convert ACL to textual representation.  Print
warning if that function is not available.
(xattrs__acls_get_a, xattrs__acls_get_d): Use acls_get_text.
2023-05-18 13:35:50 +03:00
Sergey Poznyakoff
3f2b847ddd Upgrade paxutils to d50ea31268
This fixes two bugs related to remote archives:

1. Access from unprivileged user accounts.
2. Malfunctioning seek (L) command.
2023-05-18 11:44:50 +03:00
Sergey Poznyakoff
6af0596726 Don't copy DISTFILES during bootstrapping
DISTFILES are necessary only during bootstrapping and should not be
distributed.

This partially reverts commit 9f0e54ab2.
2023-05-18 08:43:04 +03:00
Benno Schulenberg
204b414d11 Add missing option to manpage and remove duplicate operation
* doc/tar.1: Add needed option -f after operation -A, sort operation -t
  alphabetically, add --file after --concatenate, consistently use long
  option --file in the GNU-style section, and delete duplicate --update.
* doc/tar.texi: Add small missing word, and lowercase a letter.
2023-05-01 20:31:47 +03:00
Sergey Poznyakoff
6a1581240b Change some wording in doc/intern.texi 2023-04-18 11:15:44 +03:00
Anton Makrushin
4f814e0e4c Exclude VCS directory with writing from an archive
See https://savannah.gnu.org/bugs/?62859
2023-04-18 10:50:57 +03:00
Sergey Poznyakoff
4177c98bcc Detect EOF when deleting from archive.
See https://savannah.gnu.org/bugs/?63823

* src/delete.c (flush_file): Break the loop on EOF.
* tests/delete06.at: New test.
* tests/Makefile.am: Add new test.
* tests/testsuite.at: Likewise.
2023-02-21 14:00:32 +02:00
Sergey Poznyakoff
5e8a915b16 Changes in extended header decoder
* src/xheader.c (decode_time): Fix error detection.
(raw_path_decoder): Ignore empty paths.
2023-02-11 14:21:05 +02:00
Sergey Poznyakoff
edf38d13a4 Prevent dead loop in extract_file
* src/extract.c (maybe_recoverable): If make_directories indicates
success, suppose some intermediate directories have been made, even
if in fact they have not.  That's necessary to avoid dead loops when
maybe_recoverable is called with the same arguments again.
2023-02-11 13:03:23 +02:00
Sergey Poznyakoff
3da78400ea Fix boundary checking in base-256 decoder
* src/list.c (from_header): Base-256 encoding is at least 2 bytes
long.
2023-02-11 11:59:52 +02:00
Paul Eggert
02402920f8 Adjust to Gnulib macro renaming
* src/Makefile.am, tests/Makefile.am (LDADD):
Gnulib renamed LIB_HAS_ACL to FILE_HAS_ACL_LIB.
2023-01-06 12:50:36 -08:00
Paul Eggert
021845e54d build: update gnulib, paxutils submodules to latest 2023-01-06 12:50:36 -08:00
Paul Eggert
0f289d7238 Go back to single-file bootstrap
Gnulib now supports a single-file bootstrap with --pull
and --gen options, in place of the three files
autopull.sh, autogen.sh, bootstrap-funclib.sh.
This keeps the top level a bit cleaner.
* bootstrap: Sync from Gnulib build-aux/bootstrap
instead of from top/bootstrap.
* autopull.sh, autogen.sh, bootstrap-funclib.sh: Remove.
2023-01-06 12:50:36 -08:00
Paul Eggert
71d1619abd Fix ‘assume’ include
* src/tar.c: Include verify.h, needed for ‘assume’.
2023-01-06 12:50:36 -08:00
Paul Eggert
719d3b44b7 Update copyright years
UPDATE_COPYRIGHT_USE_INTERVALS=1 \
gnulib/build-aux/update-copyright \
  $(git ls-files | sed -e '/^gnulib$/d
                           /^paxutils$/d
			   /^COPYING$/d
			   /\/fdl.texi$/d')
2023-01-06 12:50:36 -08:00
Sergey Poznyakoff
a65f01ac35 Optionally warn about missing zero blocks at the end of the archive
(In response to savannah bug #63574)

* doc/intern.texi: Document actual tar behaviour in regard to
missing end-of-file marker.
* doc/tar.texi: Rewrite the "warnings" section.  Document
--warning=missing-zero-blocks
* src/common.h (WARN_MISSING_ZERO_BLOCKS): New constant.
(WARN_ALL): Include all warning bits.
* src/list.c (read_and): If EOF is reached without seeing end-of-file
blocks and the "missing-zero-blocks" warning is requested, warn about
the fact.
* src/warning.c: New warnings: "missing-zero-blocks", "verbose".
(warning_option): Change definition to reflect changes in common.h
2022-12-29 17:42:04 +02:00
Sergey Poznyakoff
2cde05fa10 Fix example use of find command in documentation 2022-12-27 13:02:05 +02:00
Sergey Poznyakoff
e89c7a45eb Fix savannah bug #63567
* src/buffer.c (short_read): Increase records_read only if a full
record has been read.
2022-12-26 23:46:15 +02:00
Paul Eggert
24c8306965 Fix -Af F bug when F is not a regular file
Problem reported by Boris Gjenero in:
https://lists.gnu.org/r/bug-tar/2022-11/msg00001.html
* src/update.c (append_file): Don’t assume that FILE_NAME is a
regular file whose size can be determined before reading.
Instead, simply read from the file until its end is reached.
2022-11-03 23:07:38 -07:00
Paul Eggert
ba26ec86e2 Fix README-* files
README-alpha is for alpha releases, which are not from Git or CVS, so
omit mention of that.  I'm not sure we'll ever do alpha releases, but
if we do, README-alpha assumes the tarballs are already bit.

Update README-hacking with info that was mistakenly put into
README-alpha.  Also mention Bison, needed for parse-date.y.
2022-11-03 22:58:27 -07:00
Paul Eggert
de64229632 Fix undefined behavior on bad extended header
* src/xheader.c (locate_handler): Avoid undefined behavior
if strlen(keyword) < kwlen.
2022-10-27 13:20:38 -07:00
Sergey Poznyakoff
17debecd73 Fix savannah bug #63123
The bug was introduced by commit 79d1ac38c1, which didn't take into
account all the consequences of returning RECOVER_OK on EEXIST, in
particular interactions with the delayed_set_stat logic.

The commit 79d1ac38c1 is reverted (the bug it was intended to fix
was actually fixed by 79a442d7b0).  Instead:

* src/extract.c (maybe_recoverable): Don't call maybe_recoverable
if EEXIST is reported when UNLINK_FIRST_OLD_FILES option is set.
2022-10-22 19:59:04 +03:00
Sergey Poznyakoff
02f9af1b8d Fix savannah bug #63250
* src/buffer.c (magic): Add signature of LZMA files produced by xz.
2022-10-22 11:14:53 +03:00
Paul Eggert
87f9e42108 Mention previous bug fix 2022-10-07 15:55:44 -07:00
Paul Eggert
0f0722df45 tests: check for recently-fixed bug
* tests/exclude17.at: New file.
* tests/testsuite.at (AT_CHECK_TIMESTAMP): Add it.
2022-10-07 15:25:36 -07:00
Aurélien Martin
7324326b1d tar: fix --exclude-vcs-ignores memory
The function frees the patterns' wordsplit structure without asking
add_exclude to reallocate the strings.  In many cases, this leads to
each file name in the directory being checked against the memory
location where it just got reallocated.
* src/exclist.c: Use EXCLUDE_ALLOC.
Copyright-paperwork-exempt: Yes
2022-10-07 15:25:36 -07:00
Paul Eggert
705bb09317 build: update submodules to latest
* src/common.h: Include <inttostr.h> since paxutils no longer does.
(STRINGIFY_BIGINT): New macro, copied from older paxutils.
(UINTMAX_STRSIZE_BOUND): New constant, also from older paxutils.
2022-09-10 18:54:21 -05:00
Paul Eggert
4ba281eca3 Fix bootstrap.conf when no paxutils
* bootstrap.conf: Don’t assume the paxutils subdirectory already
exists, when bootstrapping.
2022-09-10 18:54:21 -05:00
Paul Eggert
bc277c7069 Fix data loss when acting as filter
This bug was introduced by the recent lseek-related changes.
* src/delete.c (delete_archive_members):
* src/update.c (update_archive):
Copy the member if acting as a filter, rather than lseeking over
it, which is possible if stdin is a regular file.
* src/list.c (skim_file, skim_member):
* src/sparse.c (sparse_skim_file):
New functions, for copying when a filter.
* src/list.c (skip_file): Remove; replaced with skim_file.
All callers changed.
(skip_member): Reimplement in terms of skim_member.
* src/sparse.c (sparse_skip_file):
Remove; replaced with sparse_skim_file.  All callers changed.
* src/update.c (acting_as_filter): New static var.
(update_archive): Set it; this is like delete.c.
* tests/delete01.at (deleting a member after a big one):
* tests/delete02.at (deleting a member from stdin archive):
Also test filter case.
2022-09-03 18:23:11 -05:00
Paul Eggert
f8e14746d2 Fix --delete bug with short reads
* gnulib.modules: Add idx.
* src/common.h: Include idx.h.
* src/delete.c (move_archive): Don’t botch short reads.
2022-09-02 16:33:47 -05:00
Paul Eggert
35d9845d5d Do not diagnose same xattr file twice
* src/extract.c (set_xattr): Simplify, by having it do only
the mknodat and xattrs_xattrs_set, rather than also
trying to recover from failure.  Caller simplified too.
* tests/xattr07.at (xattrs: xattrs and --skip-old-files):
Adjust test to match fixed behavior.
2022-08-26 16:39:16 -05:00
Paul Eggert
0b74885e81 Fix bug with -x --xattr read-only files
Problem reported by Kevin Raymond in:
https://bugzilla.redhat.com/show_bug.cgi?id=1886540
* src/extract.c (open_output_file): If we already created the
empty file, do not open with O_EXCL, or with O_CREAT or O_TRUNC
for that matter.  Instead, use only O_NOFOLLOW to avoid some
races.  When estimating current mode, use openflag & O_EXCL rather
than overwriting_old_files.
(extract_file): Also invert S_IWUSR if it’s not set.
* tests/xattr08.at: New test.
* tests/Makefile.am, tests/testsuite.at: Add it.
2022-08-26 16:39:16 -05:00
Paul Eggert
258d1c44e5 Avoid quadratic behavior with delayed links
Do this by searching a hash table instead of a linked list.
Problem reported by Martin Dørum in https://mort.coffee/home/tar/
via Gavin Smith in:
https://lists.gnu.org/r/bug-tar/2022-07/msg00003.html
* src/extract.c: Include hash.h.
Improve performance a bit on non-birthtime hosts
(struct delayed_link.has_predecessor): New member.
(delayed_link_head): Remove, replacing with ...
(delayed_link_table): ... this new variable.  All uses
of linked list replaced with hash table.
(dl_hash, dl_compare): New functions for hash table.
(create_placeholder_file): Initialize has_predecessor.
(apply_delayed_link): New function, with body taken from
most of the old apply_delayed_link.
(apply_delayed_links): Use it.  Respect has_predecessor.
Don’t bother freeing as we are about to exit.
2022-08-15 00:07:39 -07:00
Paul Eggert
e49537dcdf Improve performance a bit on non-birthtime hosts
* src/extract.c (HAVE_BIRTHTIME, BIRTHTIME_EQ): New macros.
(struct delayed_link, create_placeholder_file, extract_link)
(apply_delayed_links): Avoid unnecessary work on platforms
like GNU/Linux that lack birthtime.
2022-08-15 00:07:39 -07:00
Paul Eggert
66be5a789e Avoid excess lseek etc.
* src/buffer.c, src/delete.c: Do not include system-ioctl.h.
* src/buffer.c (guess_seekable_archive): Remove.  This is now done
by get_archive_status, in a different way.
(get_archive_status): New function that gets archive_stat
unless remote, and sets seekable_archive etc.
(_open_archive): Prefer bool for boolean.
(_open_archive, new_volume): Get archive status consistently
by calling get_archive_status in both places.
* src/buffer.c (backspace_output):
* src/compare.c (verify_volume):
* src/delete.c (move_archive):
Let mtioseek worry about mtio.
* src/common.h (archive_stat): New global, replacing ar_dev and
ar_ino.  All uses changed.
* src/delete.c (move_archive): Check for integer overflow.
Also report overflow if the archive position would go negative.
* src/system.c: Include system-ioctl.h, for MTIOCTOP etc.
(mtioseek): New function, which also checks for integer overflow.
(sys_save_archive_dev_ino): Remove.
(archive_stat): Now
(sys_get_archive_stat): Also initialize mtioseekable_archive.
(sys_file_is_archive): Don’t return true if the archive is /dev/null
since it’s not a problem in that case.
(sys_detect_dev_null_output): Cache dev_null_stat.

doc: omit MS-DOS mentions in doc
It’s really FAT32 we’re worried about now, not MS-DOS.
And doschk is no longer a GNU program.
2022-08-15 00:07:39 -07:00
Paul Eggert
badd509078 Omit MS-DOS mentions in doc
It’s really FAT32 we’re worried about now, not MS-DOS.
And doschk is no longer a GNU program.
2022-08-15 00:07:39 -07:00
Paul Eggert
4e9e55fbf9 Work around GCC bug 106436
* src/tar.c (optloc_eq): Use ‘assume’ to pacify GCC bug.
2022-07-25 09:44:00 -07:00
Paul Eggert
fffc6149fd Avoid unlikely crash when xasprintf returns 0
Problem caught by GCC 12.
* src/tar.c (easprintf): New static function, which never returns
a null pointer.  All uses of xasprintf replaced by uses of this
function.
2022-07-25 09:44:00 -07:00
Paul Eggert
8ed180b03c Update .gitignore
* .gitignore: Redo for current sources.
2022-07-25 09:44:00 -07:00
Paul Eggert
131ceea7a5 Fix minor type confusion
* src/tar.c (decode_options): Don’t assign ‘false’ to a pointer.
2022-07-25 09:44:00 -07:00
Paul Eggert
4986147986 Work around GCC bug 106428
* src/names.c (read_next_name): Reword and clarify
to avoid GCC bug 106428.
2022-07-25 09:44:00 -07:00
Paul Eggert
e5aac38c80 Work around GCC bug 106427
* lib/wordsplit.c (coalesce_segment): Reword to avoid
GCC bug 106427.
2022-07-25 09:44:00 -07:00
Paul Eggert
5c4f8cadbd Adjust to Gnulib bootstrap revamp
* autogen.sh, autopull.sh, bootstrap-funclib.sh:
New files, copied from gnulib/top.
* bootstrap: Copy from gnulib/top/bootstrap (as opposed
to copying from gnulib/build-aux/bootstrap, as we used to).
* bootstrap.conf (bootstrap_post_pull_hook)
(bootstrap_post_import_hook): New functions.
Move commands into these functions as needed.
2022-07-24 11:46:56 -07:00
Paul Eggert
496cf61638 * doc/tar.1: Fix --xattrs-exclude typo. 2022-07-11 10:35:30 -05:00
Paul Eggert
d935dc7d1c Avoid EOVERFLOW problems in some symlink tests
* src/extract.c (is_directory_link): New arg ST.  Caller changed.
(is_directory_link, open_output_file):
Use readlinkat, not fstatat, to determine whether a string
names a symlink.  This avoids EOVERFLOW issues.
(extract_dir): Avoid duplicate calls to fstatat when
keep_directory_symlink_option && fstatat_flags == 0
and the file is a symlink to an existing file.
2022-06-13 17:03:49 -07:00
Paul Eggert
9f0e54ab2f Fix ‘make dist-xz’ bug
Problem reported by Pavel Raiskup in:
https://lists.gnu.org/r/bug-tar/2022-06/msg00014.html
* bootstrap.conf (copy_files): Also copy DISTFILES.
2022-06-13 16:50:11 -07:00
Paul Eggert
c7b69f05bc Fix commentary in new test case 2022-06-13 14:56:45 -07:00
Paul Eggert
4eb9d052b2 Fix doc -c typo
https://lists.gnu.org/r/bug-tar/2022-06/msg00006.html
* doc/tar.texi (Extended File Attributes): Fix typo.
2022-06-12 20:33:27 -07:00
Paul Eggert
5209d1dfe0 Update to current Autoconf & Gettext
* acinclude.m4, configure.ac:
Use AS_HELP_STRING, not AC_HELP_STRING.
* bootstrap: Sync from Gnulib.
* configure.ac: Require Autoconf 2.71 and Gettext 0.21.
Use AC_PROG_CC, not AC_PROG_CC_STDC.
Prefer AC_COMPILE_IFELSE to AC_TRY_COMPILE.
Use AC_CONFIG_FILES.
* gnulib.modules: Use gettext-h, not gettext.
2022-06-12 18:19:46 -07:00
Paul Eggert
b2ed3caefe build: update gnulib and paxutils submodules to latest 2022-06-12 18:19:46 -07:00
James Abbatiello
79d1ac38c1 tar: fix race condition
Problem reported in:
https://lists.gnu.org/r/bug-tar/2022-03/msg00000.html
* src/extract.c (make_directories): Retry the file creation as
long as the directory exists, regardless of whether tar itself
created the directory.
Copyright-paperwork-exempt: Yes
2022-06-10 18:26:37 -07:00
Paul Eggert
79a442d7b0 tar: fix race condition
Problem reported by James Abbatiello in:
https://lists.gnu.org/r/bug-tar/2022-03/msg00000.html
* src/extract.c (make_directories): Do not assume that when
mkdirat fails with errno == EEXIST that there is an existing file
that can be statted.  It could be a dangling symlink.  Instead,
wait until the end and stat it.
2022-06-10 18:26:37 -07:00
Paul Eggert
7a37621e5b test: new test extrac25.at
* tests/Makefile.am (TESTSUITE_AT): Add extrac25.at.
* tests/extrac25.at: New file.
* tests/testsuite.at: Include it.
2022-06-10 18:26:37 -07:00
Paul Eggert
c1027eb5ae Warn “file changed as we read it” less often
* src/create.c (dump_file0): Remove an fstatat call that is
unnecessary because the file wasn’t read so we can treat the first
fstatat as atomic.  Warn “file changed” when the file’s size,
mtime, user ID, group ID, or mode changes, instead of when the
file’s size or ctime changes.  Also, when such a change happens,
do not change exit status if --ignore-failed-read.  Finally, don’t
attempt to change atime back if it didn’t change.
2022-06-09 15:50:42 -07:00
Paul Eggert
bc7e758b27 Modernize NEWS hook to current Emacs 2022-06-09 15:50:42 -07:00
Paul Eggert
de72aa0cd6 doc: fix abrupt sentence in HTML
Typo reported by Jackson Dougherty in:
https://lists.gnu.org/r/bug-tar/2022-05/msg00000.html
* doc/tar.texi: Don’t assume that tex and info are the only two
formats.
2022-05-03 15:26:23 -07:00
Paul Eggert
eeda008a59 tar: revamp "file is the archive" diagnostic
* src/create.c (dump_file0): For clarity, change diagnostic
wording from "file is the archive; not dumped" to "archive cannot
contain itself; not dumped".  All test cases and documentation changed.
2022-02-15 17:42:51 -08:00
Sergey Poznyakoff
5c713540e3 Update copyright years 2022-01-02 10:25:29 +02:00
Paul Eggert
88ccec5d6c Copy COPYING and fdl.texi from upstream 2021-12-13 18:47:21 -08:00
Paul Eggert
399c08b3bf Format ` and ' more nicely in doc
Use @documentencoding and set txicodequoteundirected and
txicodequotebacktick to get nicer-looking quoting in the manual.
2021-12-13 18:47:21 -08:00
Paul Eggert
7f8fe36040 Don’t recommend delete=mtime
That stops working after the year 2242.
2021-12-13 18:47:21 -08:00
Paul Eggert
b846956c60 More reproducible tarball doc
* doc/tar.texi (PAX keywords): Improve discussion of how
to generate reproducible tarballs.
2021-12-13 12:43:58 -08:00
Sergey Poznyakoff
ac119c80e4 Raise version number 2021-12-13 16:14:26 +02:00
Paul Eggert
d43adc97d6 .gitignore maintenance (some automated) 2021-12-13 00:44:57 -08:00
Paul Eggert
1f73735ba0 bootstrap: copy from Gnulib 2021-12-13 00:44:57 -08:00
Paul Eggert
39cd8c6586 build: update gnulib and paxutils submodules to latest 2021-12-13 00:44:57 -08:00
Paul Eggert
84a08f530d Add NEWS items for changes since 1.34 2021-12-13 00:44:57 -08:00
Paul Eggert
c366383852 Omit unnecessary devmajor and devminor setting
* src/create.c (dump_file0): Omit redundant setting of devmajor
and devminor; start_header already does this.
2021-12-13 00:44:57 -08:00
Paul Eggert
738de9ecde Omit devmajor and devminor for non-special files
* src/create.c (start_header): Leave the devmajor and devminor
fields empty for files that are not character and block special
devices, even when the archive format is pax, ustar or v7.
This avoids generating irrelevant differences which helps with
reproducible builds, and is more compatible with what Solaris 10
tar does.
2021-12-13 00:44:57 -08:00
Paul Eggert
771ca7b686 Use ‘bool’ in create.c
* src/create.c: Prefer ‘bool’, ‘true’, ‘false’ for booleans.
2021-12-13 00:44:57 -08:00
Paul Eggert
8184adddab * gnulib.modules: Add year2038. 2021-10-13 14:46:10 -07:00
Paul Eggert
7868054c03 build: improve build-from-git for older GCCs
configure.ac: Bump GCC version from 4.6 to 11.2 when deciding whether
to default to enabling GCC warnings when --enable-gcc-warnings is not
specified, as older GCCs can generate too many false alarms.  From
a suggestion by Christian Schoenebeck.
2021-09-20 13:11:36 -07:00
Paul Eggert
4f3824743f Simplify wordsplit code a bit
These changes pacify gcc -Wanalyzer-null-dereference on x86-64 gcc
11.2.1 20210728 (Red Hat 11.2.1-1).
* lib/wordsplit.c (wsnode_tail): Remove unnecessary test.
(coalesce_segment): Coalesce calls to wsnode_len.
2021-09-19 07:36:36 -07:00
Paul Eggert
c5b86d7672 build: document WERROR_CFLAGS
* README-hacking: Mention 'make WERROR_CFLAGS='.
2021-09-18 08:16:04 -07:00
Paul Eggert
c0bf6a723b build: update paxutils submodule to latest 2021-09-17 12:57:14 -07:00
Paul Eggert
b44c612f5d build: update gnulib submodule to latest
* src/common.h (get_directory_entries):
Add _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE.
Problem found by gcc -Wsuggest-attribute=malloc and
current Gnulib.
2021-09-17 12:57:14 -07:00
Paul Eggert
066f7729e0 Pacify gcc -Warray-parameter
* src/common.h (code_timespec): Declare sbuf arg to be an array,
to be consistent with definition.
2021-09-17 12:57:14 -07:00
Paul Eggert
7958eb97e6 Fix null rereference if low-memory
* src/incremen.c (read_incr_db_01): Use xstrdup not strdup.
Problem found by gcc -Wanalyzer-possible-null-argument.
2021-09-17 12:57:14 -07:00
Sergey Poznyakoff
66262c10d1 Provide functions for manipulating arrays of extended attributes
* src/common.h (xheader_xattr_free,xheader_xattr_copy): Remove protos.
(xattr_map_init,xattr_map_copy)
(xattr_map_add,xattr_map_free): New protos.
* src/tar.h (xattr_map): New struct.
(tar_stat_info): Replace xattr_map_size and xattr_map with one
field: xattr_map.
* src/xattrs.c (XATTRS_PREFIX,XATTRS_PREFIX_LEN): New defines.
(xheader_xattr_init,xattr_map_init)
(xattr_map_free,xattr_map_add)
(xheader_xattr_add,xattr_map_copy): New functions.
All uses changed.
* src/create.c (start_header): Update to use struct xattr_map.
* src/extract.c: Update to use struct xattr_map.
* src/tar.c: Likewise.
* src/xheader.c (xheader_xattr_init,xheader_xattr_free)
(xheader_xattr_add,xheader_xattr_copy): Remove.
(xattr_coder,xattr_decoder): Use xattr_map_ functions.
2021-09-02 21:01:58 +03:00
Sergey Poznyakoff
a339f05cd2 Fix handling of extended header prefixes
* src/xheader.c (locate_handler): Recognize prefix keywords only
when followed by a dot.
(xattr_decoder): Use xmalloc/xstrdup instead of alloc
2021-08-28 17:40:57 +03:00
Sergey Poznyakoff
cc8f5f78b2 Handle invalid sparse entries in pax header
* src/sparse.c (pax_decode_header): Check if sp.offset+sp.numbytes
falls within the reported file size.  Check for possible integer
overflow.
2021-08-28 14:15:25 +03:00
Sergey Poznyakoff
193eb8f81d transform: fix replacement of particular pattern instance
This fixes handling of expressions like 's/s/@/2'

Fix suggested by Anthony Heading.

* src/transform.c (_single_transform_name_to_obstack): Avoid duplicating
initial prefix if replace is not needed.
2021-08-28 09:57:26 +03:00
Samanta Navarro
93082d6eb8 Fix crash on invalid command line argument
The copy_string_unquote function does not handle arguments which only
consist of a single quote. A string is only quoted if two quoting
characters exist.

How to reproduce:

tar --checkpoint-action exec=\"
2021-07-01 09:52:42 +03:00
Sergey Poznyakoff
e5bc23efcc Fix the use of options with trailing slash in files-from list
* src/names.c (read_name_from_file): Do not remove trailing slash
here, since name_buffer might contain an option (e.g. -C /).
(read_next_name): Remove trailing slash when we're sure we're dealing
with a file name.
See 163e96a0.
2021-07-01 09:38:35 +03:00
Sergey Poznyakoff
12d67f44de Minor fix
* scripts/backup-specs: Set standard paths for rsh (patch#9275).
2021-06-01 19:02:42 +03:00
Samanta Navarro
3730dddb3f Fix typos
Typos found with codespell
2021-06-01 18:54:07 +03:00
Samanta Navarro
8e82f367d4 Minor changes.
* src/xheader.c (decode_record): Fix format specification.
(xattr_encode_keyword): Allocate space for terminating \0.
2021-06-01 18:49:28 +03:00
Sergey Poznyakoff
66b59fccb1 Fix gendocs_template 2021-03-24 20:56:54 +02:00
Paul Eggert
91c031678d Tune for single-threaded tar
This takes advantage of recent optimizations in Gnulib
for single-threaded programs.
* configure.ac (GNULIB_EXCLUDE_SINGLE_THREAD)
(GNULIB_MBRTOWC_SINGLE_THREAD, GNULIB_REGEX_SINGLE_THREAD)
(GNULIB_WCHAR_SINGLE_LOCALE): Define.
2021-03-07 18:30:08 -08:00
Paul Eggert
5227d66b3c Port linking to AIX 7.1
* src/Makefile.am (LDADD): Remove, folding into tar_LDADD.
* src/Makefile.am (tar_LDADD), tests/Makefile.am (LDADD):
Add the libraries gnulib-tool currently recommends: LIB_ACL,
LIB_CLOCK_GETTIME, LIB_GETRANDOM, LIB_HARD_LOCALE, LIB_HAS_ACL,
LIB_MBRTOWC, LIB_SETLOCALE_NULL.  Otherwise, tar won’t link on AIX
7.1 with xlc because the -lpthread option is missing.
2021-03-07 18:30:08 -08:00
Paul Eggert
f51461d8be Port xattr-at.h to AIX 7.1
* lib/xattr-at.h: Include <errno.h> before testing whether
ENOATTR is defined.
2021-03-07 18:30:08 -08:00
Paul Eggert
6efa8de409 build: update gnulib submodule to latest 2021-03-07 18:30:08 -08:00
Sergey Poznyakoff
c67d223854 Fix building the online version of the manual.
* doc/Makefile.am (GENDOCS): Use the version from the tar repository.
(manual): Set the DISTRIN rendition.
(manual-rebuild): New goal.
* doc/README.manual: New file. Instructions for maintainers on how to
update web documentation.
* doc/gendocs.sh: A version from gnulib fixed as per
https://lists.gnu.org/archive/html/bug-gnulib/2021-03/msg00002.html.
* doc/gendocs_template: Updated version from gnulib.
* doc/intern.texi: Fix the use of UNREVISED.
* doc/tar.texi: Fix the use of GNUTAR.
2021-03-01 20:44:31 +02:00
Paul Eggert
55f2a0772e Fix unlikely uninitalized var bug with sparse file
* src/sparse.c (sparse_extract_file): Set *SIZE to
stat.st_size so that the caller does not use *SIZE
when uninitalized.  Problem found with GCC 10 and
--enable-gcc-warnings CFLAGS='-O2 -flto -fanalyzer'.
2021-03-01 00:18:44 -08:00
Paul Eggert
daf634c44e Pacify --enable-gcc-warnings -flto -fanalyzer
With GCC 10.2.1, ‘./configure --enable-gcc-warnings CFLAGS='-O2
-flto -fanalyzer' issued a false alarm about uninitialized
variable use.  Pacify GCC by using a variant of the code.
* src/buffer.c (zip_program): Omit last placeholder entry.
(n_zip_programs): New constant.
(find_zip_program): Use it instead of placeholder.
(first_decompress_program): Set *PSTATE to maximum value
if skipping the table.  This avoids confusing gcc -flto
into thinking *PSTATE is used uninitialized.
(next_decompress_program): Simplify now that *PSTATE is maximal
when skipping.
2021-03-01 00:18:44 -08:00
Paul Eggert
5f8f129415 Pacify clang for unreachable ‘return’
* src/sparse.c (sparse_scan_file_seek): Omit unreachable statement.
2021-03-01 00:18:44 -08:00
Paul Eggert
dc101747e8 Pacify clang char conversion
* src/create.c (to_chars): Pacify ‘clang’ about assigning
128 to ‘char’.
2021-03-01 00:18:44 -08:00
Paul Eggert
7fb1b6877f Omit most uses of ‘inline’
With today’s compilers ‘inline’ is typically not needed for
performance (at least the way GNU Tar uses it) and it gets in the
way of portability.
* configure.ac: Omit AC_C_INLINE; no longer needed here.
* lib/attr-xattr.in.h (setxattr, lsetxattr, fsetxattr, getxattr)
(lgetxattr, fgetxattr, listxattr, llistxattr, flistxattr):
* lib/wordsplit.c (skip_delim_internal, skip_delim)
(skip_delim_real, exptab_matches):
* src/delete.c (flush_file):
* src/extract.c (safe_dir_mode):
* src/misc.c (ptr_align):
Now just static, not static inline.
* lib/wordsplit.h (wordsplit_getwords): Remove; no longer used.
* src/common.h (name_more_files): Now COMMON_INLINE, not
extern inline - which is not portable according to C99,
the way we were using it.
2021-03-01 00:18:44 -08:00
Paul Eggert
f4e2411bf5 maint: port better to non-GCC compilers
This can be helpful in porting to compilers like Oracle Developer
Studio that support some but not all GCC attributes.
* lib/wordsplit.c (FALLTHROUGH): Remove; now done by attribute.h.
* lib/wordsplit.h (__WORDSPLIT_ATTRIBUTE_FORMAT): Remove;
all uses replaced by ATTRIBUTE_FORMAT.
* lib/wordsplit.h, src/buffer.c, src/common.h, src/compare.c:
* src/sparse.c, src/system.c, src/xheader.c:
Prefer ATTRIBUTE_FORMAT, MAYBE_UNUSED, _Noreturn, etc. to
__attribute__.
2021-03-01 00:18:44 -08:00
Paul Eggert
ace146f6a4 Update paxutils from upstream 2021-03-01 00:18:43 -08:00
Paul Eggert
df6de51574 maint: 1.34 announcement update
Hand-install 1.34 changes into master.
Evidently these changes were not pushed to savannah,
before I installed further changes today.
2021-02-27 18:40:49 -08:00
Paul Eggert
8378991cba maint: port to Fedora 33
Fedora 33 uses GCC 10.2.1, which is a bit pickier.
* configure.ac: Do not use -Wsystem-headers, as this
runs afoul of netdb.h on Fedora 33.
* gnulib.modules: Add ‘attribute’.
* lib/wordsplit.c (wsnode_new): Return the newly allocated
pointer instead of a boolean, to pacify GCC 10.2.1 which otherwise
complains about use of possibly-null pointers.  All uses changed.
* src/buffer.c (try_new_volume): Don’t assume find_next_block succeeds.
(_write_volume_label): Pacify GCC 10.2.1 with an ‘assume’, since
LABEL must be nonnull here.
* src/common.h (FALLTHROUGH): Remove; now in attribute.h.
Include attribute.h, for ATTRIBUTE_NONNULL.
* src/misc.c (assign_string_or_null): New function,
taking over the old role of assign_string.
(assign_string): Assume VALUE is non-null.
(assign_null): New function, taking over the old
role of assign_string when its VALUE was nonnull.
All callers of assign_string changed to use these functions.
(assign_string_n): Clear *STRING if VALUE is null,
to fix a potential double-free.
2021-02-27 16:42:49 -08:00
Paul Eggert
fa6d317bc7 Update gnulib and paxutils from upstream 2021-02-27 16:42:49 -08:00
Pavel Raiskup
beeb19f927 xattrs: fix capabilities root test
Related discussion in the Fedora pull-request:
https://src.fedoraproject.org/rpms/tar/pull-request/8

* tests/capabs_raw01.at: Newer systems (currently e.g. Fedora 34)
print getcap output in format CAP=VAL, not CAP+VAL.
2021-02-08 17:50:31 +02:00
Sergey Poznyakoff
553210d5ad Gracefully handle duplicate symlinks when extracting
If the archive being extracted contains multiple copies
of the same symlink, extract only the first of them and
skip the rest.  The use case is described in

https://lists.gnu.org/archive/html/bug-tar/2021-01/msg00026.html

The bug was introduced by 2d3396c3ea.

* src/extract.c (create_placeholder_file): If placeholder already
exists and is registered in the delayed_link list, return immediately.
2021-02-08 16:15:22 +02:00
Sergey Poznyakoff
ee2ec5ff19 Fix savannah bug #60002
Bug was introduced by commit 34d15af1.

* src/extract.c (prepare_to_extract): When extracting over pipe,
process only regular files.
* tests/extrac24.at: New test case.
* tests/Makefile.am: Add new test case.
* tests/testsuite.at: Likewise.
2021-02-04 16:51:38 +02:00
Sergey Poznyakoff
d9d4435692 Fix memory leak in read_header
Bug reported in https://savannah.gnu.org/bugs/?59897

* src/list.c (read_header): Don't return directly from the loop.
Instead set the status and break.  Return the status.  Free
next_long_name and next_long_link before returning.
2021-01-17 20:41:11 +02:00
Sergey Poznyakoff
2251317e3f Fix improper argument reference.
(bug introduced by 1ff0b63f)

* src/tar.c (parse_default_options): Pass args as is to the argp_parse.
2021-01-17 19:02:47 +02:00
Sergey Poznyakoff
972bebf07e Fix regression itroduced by 66162927.
* src/misc.c (chdir_arg): Initialize the abspath field to NULL.
(tar_getcdpath): Actually initialize the abspath field here.
2021-01-16 14:38:28 +02:00
Sergey Poznyakoff
8e2898ab11 Fixes in the delete_archive_members function
* src/delete.c (delete_archive_members): Clean-up the code. Avoid
entering the loop from the middle.  Free the memory allocated for
current_stat_info.
2021-01-14 09:00:12 +02:00
Sergey Poznyakoff
0b43ea2906 Use stdopen from gnulib
* gnulib.modules: Request stdopen
* lib/Makefile.am: Remove stdopen.c and stdopen.h
* lib/stdopen.c: Remove.
* lib/stdopen.h: Remove.
* src/tar.c: stdopen returns 0 on success.
2021-01-08 18:50:57 +02:00
Sergey Poznyakoff
e4d1edadef Actually prefer /dev/full over /dev/null as a replacement for stdin
* lib/stdopen.c (stdopen): Fix improper condition.
Avoid leaking extra file descriptor.
* src/tar.c (main): Set name of the stdout for diagnostics.
Bail out if stdopen fails.
2021-01-08 17:46:32 +02:00
Sergey Poznyakoff
0836a51147 Version 1.33
* NEWS: Update.
* configure.ac: Raise version number. Require automake 1.15 and
autoconf 2.64.
* gnulib: pull v0.1-4333-g30820c2
* src/names.c: Use hash_remove instead of the deprecated hash_delete.
2021-01-07 16:33:49 +02:00
Sergey Poznyakoff
afa743ac23 Update copyright years 2021-01-06 17:55:16 +02:00
Sergey Poznyakoff
01dd89c121 Fix typo in the manpage
* doc/tar.1: Fix description of the --newer option
2020-07-13 09:01:29 +03:00
Pavel Raiskup
1263f9bc1d Bugfix --sparse --diff mode
Originally reported in:
https://bugzilla.redhat.com/show_bug.cgi?id=1853469

* src/sparse.c (check_data_region): Only compare the part of buffer
really fed by safe_read(), not whole rdsize.
2020-07-10 09:06:42 +03:00
Sergey Poznyakoff
1ff0b63f48 Accept only position-sensitive (file-selection) options in file list files.
Using such options as -f, -z, etc. is senseless in the file list file
and bypasses the option consistency checks in decode_options.  Therefore,
only options related to file selection (a.k.a position-sensitive options)
are allowed in files.

* doc/tar.texi: Document changes.
* src/common.h (tar_args): Move from tar.c
(TAR_ARGS_INITIALIZER): New macro.
* src/names.c: Declare option group identifiers as an enum.
(names_parse_opt): Special handling for ARGP_KEY_ERROR.
(names_argp): Remove static qualifier.
(names_argp_children): Remove.
* src/tar.c: Declare option group identifiers as an enum.
(parse_opt): Special handling for ARGP_KEY_INIT.
(argp_children): New static variable.
(args): Remove static variable.
(more_options): Allow only options from names_argp.
(parse_default_options): Take a pointer to struct tar_args as argument.
Replace the loc member during the call to argp_parse and restore it
afterwards.
(decode_options): Use automatic variable for args.
2020-06-24 16:43:26 +03:00
Sergey Poznyakoff
34d15af170 Fix the logic of prepare_to_extract.
* src/extract.c (prepare_to_extract): Return true to proceed with
the extraction, and false to skip the current member.  If extracting
over a pipe, skip unlinking logic.
(extract_archive): Update accordingly.
2020-06-22 22:17:46 +03:00
Sergey Poznyakoff
63712973c7 Make sure link counting works for file names supplied with -T
* src/common.h (name_count): Remove extern.
(files_count): New enum.
(filename_args): New extern.
* src/names.c (name_count): Remove.
(files_count): New variable.
(name_add_name,name_add_file): Update filename_args.
* src/create.c (create_archive): Set trivial_link_count depending on
the filename_args.
2020-06-15 21:10:46 +03:00
Alfred M. Szmidt
d9ec6f04e2 Remove freemanuals.texi
* doc/Makefile.am (tar_TEXINFOS): Remove freemanuals.texi.
* doc/freemanuals.texi: Delete file.
* doc/tar.texi (Free Software Needs Free Documentation): Remove
appendix.
2020-06-10 21:56:54 +03:00
Sergey Poznyakoff
b5418cd393 Fix typo in docs 2020-06-03 10:55:51 +03:00
Sergey Poznyakoff
615732a804 Bugfix
* src/sparse.c (sparse_diff_file): Fix return value.
2020-06-03 09:31:41 +03:00
Paul Eggert
dd1a6bd37a tar: avoid read overrun
Problem reported by Timotej Kapus in:
https://lists.gnu.org/r/bug-tar/2020-05/msg00001.html
* src/transform.c (parse_transform_expr):
Diagnose ‘--transform='s'’ instead of continuing past '\0'.
2020-05-19 11:52:26 -07:00
Sergey Poznyakoff
41654f91f0 Fix handling of linked rename chains in incremental backups
* src/incremen.c: Change the meaning of the DIRF_RENAMED flag.  Now it
marks a directory which is the last one in a chain of renames.
Regular renamed directories are recognized by their orig member being
non-NULL.  Directories marked with DIRF_RENAMED start encoding of renames.
(procdir): Clear DIRF_RENAMED flag on directories which are origins for
renames.
(makedumpdir): Use the orig member to check if the directory is a
result of a rename.
(store_rename): Move the check for DIR_IS_RENAMED to the caller. Don't
clear the DIRF_RENAMED, it is not needed any more.

* tests/rename06.at: New test.
* tests/Makefile.am: Add rename06.at
* tests/testsuite.at: Likewise.
2020-02-15 11:09:18 +02:00
Sergey Poznyakoff
8d90723d30 Update copyright years 2020-02-08 13:21:13 +02:00
Sergey Poznyakoff
14d8fc718f Fix the --no-overwrite-dir option
Given this option, tar failed to preserve permissions of empty directories
and to create files under directories owned by the current user that did
not have the S_IWUSR bit set.

* src/extract.c (fd_chmod): Rename to fd_i_chmod.
(fd_chmod): New function.
(safe_dir_mode): New function.
(extract_dir): Special handling for existing directories in
--no-overwrite-dir mode.
* tests/extrac23.at: New file.
* tests/Makefile.am: Add new test case.
* tests/testsuite.at: Likewise.
2020-02-08 13:08:20 +02:00
Sergey Poznyakoff
883cc555df Wildcards in exclude-vcs-ignore mode should not match slash
* src/exclist.c (info_attach_exclist): Use the FNM_FILE_NAME flag.
2019-12-03 09:55:02 +02:00
Sergey Poznyakoff
e1005b385d Version 1.32.90 2019-11-27 18:51:58 +02:00
Sergey Poznyakoff
14f00a2c7a Testsuite fixes
* tests/sparse06.at: Skip the test if genfile is unable to create
sparse files.
* tests/sptrcreat.at: Likewise.
* tests/sptrdiff00.at: Likewise.
* tests/sptrdiff01.at: Likewise.
2019-11-25 08:01:04 +02:00
Sergey Poznyakoff
f122fc94a7 Another testsuite fix.
* tests/extrac11.at: Skip test if ulimit fails.
2019-11-14 07:58:17 +02:00
Sergey Poznyakoff
b31afe7cf0 Testsuite fix.
* tests/remfiles10.at: Don't expect EINVAL when trying to remove
CWD.
2019-11-13 08:37:41 +02:00
Sergey Poznyakoff
ea6f84dd40 Consistently use x2realloc for buffer reallocation
* src/create.c (create_archive): Use x2realloc
* src/names.c (copy_name)
(add_hierarchy_to_namelist): Use x2realloc
2019-08-25 14:41:17 +03:00
Sergey Poznyakoff
2d3396c3ea Fix extraction of symbolic links hardlinked to another symbolic links
* src/extract.c (create_placeholder_file): Take additional argument:
the delayed_link entry after which to the newly created one.
(extract_link): Create a placeholder file if the target link name
exists in the delayed_link list.
2019-08-18 23:40:54 +03:00
Sergey Poznyakoff
d70b8b3b39 Fix --delay-directory-restore on archives with reversed member ordering.
* src/extract.c (find_direct_ancestor): Remove useless test.
(delay_set_stat): If the file name being added is already in
the list, update stored data instead of creating a new entry.
This works for archives with reversed order of members.
* tests/extrac22.at: New testcase.
* tests/Makefile.am: Add new testcase.
* tests/testsuite.at: Include new testcase.
2019-04-11 13:45:32 +03:00
Sergey Poznyakoff
c445d99d4f Minor change
* scripts/backup.in: Fix typo
2019-03-28 14:01:58 +02:00
Sergey Poznyakoff
2c9730357f Typesetting fixes in the manpage
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2019-03-28 13:58:44 +02:00
Zachary Vance
ef0f882382 POSIX extended format headers do not include PID by default
The intent is to make binary-equivalent PAX archives easy to create.  If
POSIXLY_CORRECT is set, the POSIX standard default is used, which embeds
the pid.

* src/common.h (posixly_correct): New global.
* src/tar.c (decode_options): Detect the POSIXLY_CORRECT environment
variable.
* src/buffer.c (add_chunk_header): Change filenames of multipart files to
omit the pid.
* src/xheader.c (HEADER_TEMPLATE): New macro.
(xheader_xhdr_name, xheader_ghdr_name): Use HEADER_TEMPLATE to select
the template for the POSIX extended header name.
* doc/tar.texi: Document the change.

Signed-off-by: Zachary Vance <za3k@za3k.com>
2019-03-28 13:37:07 +02:00
Sergey Poznyakoff
66162927eb Check return value from xgetcwd
* src/misc.c (chdir_arg,tar_getcdpath): Check for non-NULL
return from xgetcwd. The function returns NULL for any
error originating from getcwd.
2019-03-03 09:02:20 +02:00
Sergey Poznyakoff
44cfdfb8b6 Version 1.32 2019-02-23 14:54:53 +02:00
Sergey Poznyakoff
97d8951536 Minor fixes in docs.
* doc/tar.1: Remove description of the --preserve option
Document verbosity levels.
* doc/tar.texi: Fix description of the -o option.
2019-02-04 21:30:00 +02:00
Daniel Le
bf5d66109c Fix typos in the documentation
Short option "t" was mistranslated to "--test" instead of "--list" in commit
67cad0792b.
2019-01-15 15:29:03 +02:00
Sergey Poznyakoff
bd1b0fc97c Fix build on AIX
* src/unlink.c (flush_deferred_unlinks): Avoid possible duplicate case
(if ENOTEMPTY==EEXIST)
2019-01-15 15:21:03 +02:00
Sergey Poznyakoff
a7289daf5c Version 1.31.90 2019-01-15 14:38:02 +02:00
Sergey Poznyakoff
72506bddee Ensure gnu format when running checkpoint tests 2019-01-14 23:32:15 +02:00
Sergey Poznyakoff
a311b908c0 Fix compression tests
Existing compression tests used tar with compiled-in defaults. However,
some of the defaults are sure to create archives that are not byte-to-byte
reproducible (e.g. DEFAULT_ARCHIVE_FORMAT=POSIX, because the name field
in posix extended headers uses PID of the creating process by default).
Moreover, some compressors (e.g. gzip) store current timestamp in
the file header when compressing from stdin, so that using cmp on the
two created archives as the tests did is error-prone. Another problem
is that the tests implicitly assumed that tar uses archive suffix to
recognize its format when extracting, which isn't the case. Finally,
there's hardly any reason in using sed to create m4 sources, when
everything can be achieved by m4 itself.

* tests/Makefile.am: Remove generation of compress-*.at files.
* tests/compress.at.in: Remove.
* tests/compress.m4: New file.
* tests/testsuite.at: Include compress.m4, use TAR_CHECK_COMPRESS to
check compression options.
2019-01-14 18:55:43 +02:00
Sergey Poznyakoff
cb07844454 Fix possible NULL dereference (savannah bug #55369)
* src/sparse.c (pax_decode_header): Check return from find_next_block.
2019-01-14 15:22:09 +02:00
Sergey Poznyakoff
2f5a57be4b Fix compilation without iconv. 2019-01-14 14:46:43 +02:00
Sergey Poznyakoff
3da8c2850d Fix iconv usage.
Patch by Christian Weisgerber.

* src/utf8.c (utf8_convert): non-zero return from iconv means failure.
2019-01-14 13:59:39 +02:00
Pavel Raiskup
c697d62598 tests: fix numeric.at for BSD
While creating file, BSD kernels inherit the group ownership from
parent directory.
http://lists.gnu.org/archive/html/bug-tar/2016-06/msg00000.html

* tests/numeric.at: Attempt to 'chown' the newly created directory
to proper group (at least on affected machines that command is
expected to succeed).
2019-01-14 12:54:29 +02:00
Sergey Poznyakoff
b0930da045 Fix typo in manpage. 2019-01-14 12:48:16 +02:00
Sergey Poznyakoff
f86722c34c Fix expected output in dirrem tests.
In both tests, the "file changed as we read it" warning might be
produced for dir/sub, depending on the ctime resolution and timing.
The problem was fixed by 64b43fdf70, but regressed
after e7cd377f78, which removed 1 second
delays between each pair of checkpoints. Since the presense or absense
of this warning is irrelevant for the test, it is now suppressed.

* tests/dirrem01.at: Suppress the file-changed warning.
* tests/dirrem02.at: Likewise.
2019-01-14 12:26:59 +02:00
Sergey Poznyakoff
aa0684ce90 Fix the use of --checkpoint without explicit --checkpoint-action
* src/checkpoint.c (checkpoint_finish_compile): Set default action,
if necessary.
* tests/checkpoint/defaults.at: New testcase.
* tests/checkpoint/dot-compat.at: New testcase.
* tests/checkpoint/dot-int.at: New testcase.
* tests/checkpoint/dot.at: New testcase.
* tests/checkpoint/interval.at: New testcase.
* tests/Makefile.am: Add new testcases.
* tests/testsuite.at Include new testcases.
2019-01-12 10:24:47 +02:00
Sergey Poznyakoff
85c005ee13 Remove erroneous abort() call
The call was introduced by commit ccef8581. It caused tar to abort
on perfectly normal operations, like untarring archives containing
./ with the -U option,

See http://lists.gnu.org/archive/html/bug-tar/2019-01/msg00019.html
for details.

* src/extract.c (maybe_recoverable): Remove misplaced call to abort().
2019-01-10 18:18:49 +02:00
Sergey Poznyakoff
2684c88a49 Version 1.31 2019-01-02 20:20:28 +02:00
Sergey Poznyakoff
1ed62596cf Fix the difflink test
Hardlinking a symlink produces hardlink on BSD and symlink
on GNU/Linux. Avoid the ambiguity.

* tests/difflink.at: Create hard link from a regular file.
2018-12-28 17:53:35 +02:00
Sergey Poznyakoff
9d1993f651 Work over a bug in gnulib error()
The error() function from glibc correctly prefixes each message it
prints with program_name as set by set_program_name. However, its
replacement from gnulib, which is linked in on systems where this
function is not available, prints the name returned by getprogname()
instead. Due to this messages output by tar subprocess (which sets its
program name to 'tar (child)') become indiscernible from those printed
by the main process. In particular, this breaks the remfiles01.at and
remfiles02.at test cases.

* configure.ac: Define ENABLE_ERROR_PRINT_PROGNAME if using
gnulib error().
* src/tar.c [ENABLE_ERROR_PRINT_PROGNAME] (tar_print_progname): New function.
(main) [ENABLE_ERROR_PRINT_PROGNAME]: Set error_print_progname.
2018-12-28 17:49:08 +02:00
Sergey Poznyakoff
e7cd377f78 Implement the "wait" checkpoint action.
This action instructs tar to pause until given signal is delivered.
The newer genfile tool uses this action for communication between
genfile and tar in exec mode. This eliminates race conitions and
speeds up the tests based on exec mode.

* doc/tar.texi: Document changes.
* paxutils: Upgrade.
* src/checkpoint.c: Implement the wait action.
* src/common.h (decode_signal): New proto.
* src/tar.c (decode_signal): New function.
(set_stat_signal): Rewrite.
* tests/dirrem01.at: Adjust genfile and tar command line arguments
to use the new feature.
* tests/dirrem02.at: Likewise.
* tests/filerem01.at: Likewise.
* tests/filerem02.at: Likewise.
* tests/grow.at: Likewise.
* tests/sptrcreat.at: Likewise.
* tests/sptrdiff00.at: Likewise.
* tests/sptrdiff01.at: Likewise.
* tests/truncate.at: Likewise.
2018-12-28 13:27:02 +02:00
Sergey Poznyakoff
c15c42ccd1 Fix CVE-2018-20482
* NEWS: Update.
* src/sparse.c (sparse_dump_region): Handle short read condition.
(sparse_extract_region,check_data_region): Fix dumped_size calculation.
Handle short read condition.
(pax_decode_header): Fix dumped_size calculation.
* tests/Makefile.am: Add new testcases.
* tests/testsuite.at: Likewise.

* tests/sptrcreat.at: New file.
* tests/sptrdiff00.at: New file.
* tests/sptrdiff01.at: New file.
2018-12-27 17:53:38 +02:00
Sergey Poznyakoff
3c2a2cd94d Disallow modifications to the global pax extended header in update mode.
Updating global headers in update mode is not possible, because:

1) If the original archive was not in PAX format, writing the
global header would overwrite first member header (and eventually
data blocks) in the archive.
2) Otherwise, using the --pax-option can make the updated header
occupy more blocks than the original one, which would lead to the
same effect as in 1.

This also fixes
  http://lists.gnu.org/archive/html/bug-tar/2018-12/msg00007.html

* src/xheader.c (xheader_forbid_global): New function.
* src/common.h (xheader_forbid_global): New prototype.
* src/update.c (update_archive): Use xheader_forbid_global, instead
of trying to write global extended header record.
2018-12-21 14:39:49 +02:00
Sergey Poznyakoff
ea3aea06f1 Bugfix
Bug reported in
  http://lists.gnu.org/archive/html/bug-tar/2018-12/msg00014.html

* src/names.c (collect_and_sort_names): Fix iteration over namelist.
2018-12-21 13:54:12 +02:00
Sergey Poznyakoff
983a82a376 Fix semantics of -K used together with explicit member names.
This also fixes the bug reported in
  http://lists.gnu.org/archive/html/bug-tar/2018-12/msg00012.html

* src/common.h (starting_file_option): Describe the variable.
* src/names.c (add_starting_file): New function.
(name_match): Ignore everything before the member indicated by the
--starting-file option
* src/tar.c: Use add_starting_file to handle the -K option.
2018-12-21 13:54:11 +02:00
Sergey Poznyakoff
916fe62ae9 Fix error handling when reading incremental snapshots
Bug reported in
  http://lists.gnu.org/archive/html/bug-tar/2018-12/msg00008.html

* incremen.c (read_incr_db_01): Don't try to continue after errors.
2018-12-21 13:54:11 +02:00
Sergey Poznyakoff
99d415e190 Reject pax options starting with equals sign
Bug reported in
  http://lists.gnu.org/archive/html/bug-tar/2018-12/msg00010.html

* xheader.c (xheader_set_keyword_equal): Bail out if the keyword starts
with =
2018-12-21 13:54:11 +02:00
Sergey Poznyakoff
c7c59b57fa Fix buffer overflow
Bug reported in
  http://lists.gnu.org/archive/html/bug-tar/2018-12/msg00011.html

* src/xheader.c (xheader_format_name): fix length calculation
2018-12-21 13:54:11 +02:00
Sergey Poznyakoff
eae48289c0 Fix improper memory access
Bug reported in
  http://lists.gnu.org/archive/html/bug-tar/2018-12/msg00009.html

* src/transform.c (parse_transform_expr): Check if re is not empty
before accessing its last byte.
2018-12-21 13:54:11 +02:00
Sergey Poznyakoff
62c0c3a780 Fix parsing of ACLs
Text returned by acl_to_text can contain comments (introduced by #).
Strip comments and horizontal tabs prior to storing ACLs in PAX
headers.

* src/xattrs.c (xattrs_acls_cleanup): New function.
(xattrs__acls_get_a,xattrs__acls_get_d): Use xattrs_acls_cleanup.
2018-11-24 22:10:53 +02:00
Sergey Poznyakoff
ba472050da Don't try to read past the end of header string fields
* src/common.h (assign_string_n): New proto.
(ASSIGN_STRING_N): New macro.
* src/misc.c (assign_string_n): New function.
* gnulib.modules: Add strnlen.
* src/buffer.c: Use assign_string_n where appropriate.
* src/list.c: Likewise.
2018-11-24 17:57:32 +02:00
Sergey Poznyakoff
f6e2860e8a Fix verbose ACL listing
* src/xattrs.c (acls_one_line): Advance pos.
(xattrs_print): Insert a comma between ACL and default ACL if both
are non-empty.
2018-11-12 09:17:25 +02:00
Paul Eggert
2777a2bfd9 tar: fix numbered backup bug
* src/misc.c (maybe_backup_file): Pass chdir_fd, not AT_FDCWD,
to find_backup_file_name.  This fixes a bug whereby the wrong
backup file name was chosen for numbered backups.
2018-10-28 16:24:05 -07:00
Paul Eggert
9fc1cb40f9 * src/tar.c (expand_pax_option): Pacify recent GCC. 2018-10-28 16:08:59 -07:00
Paul Eggert
6238296458 build: update gnulib submodule to latest
* src/misc.c (maybe_backup_file): Adjust to Gnulib change.
2018-10-28 16:08:59 -07:00
Sergey Poznyakoff
9042dfc4b1 Minor fixes in wordsplit.c 2018-08-02 16:36:48 +03:00
Paul Eggert
016d6d27d1 build: update gnulib submodule to latest 2018-08-02 00:12:46 -07:00
Sergey Poznyakoff
e54741745c Silence gcc warnings in wordsplit 2018-07-31 16:05:28 +03:00
Sergey Poznyakoff
110e3bd7a6 Fix double-free introduced by 577dc345
* src/utf8.c (utf8_convert): Don't store freed value in *output
2018-07-31 15:57:11 +03:00
Pavel Raiskup
c1b569d9d6 Report race on systems without O_DIRECTORY
* src/names.c (collect_and_sort_names): Report ENOTDIR after
successful fstat() but !S_ISDIR.
2018-07-31 12:13:48 +03:00
Pavel Raiskup
577dc34565 Avoid some resource leaks
* src/incremen.c (store_rename): Free temp_name, leaked before for
each renamed directory with --listed-incremental.
* src/transform.c (add_literal_segment): Tighten arguments by
const.
(parse_transform_expr): Free 'str', leaked storage for each
--transform option before.
* src/utf8.c (utf8_convert): Deallocate buffer for failed iconv()
call so callers don't have to.
2018-07-31 12:06:09 +03:00
Sergey Poznyakoff
c7b3f0217f Sync wordsplit and paxutils with the most recent versions 2018-07-31 11:56:44 +03:00
Paul Eggert
e81c89ddd6 * doc/tar.1: Fix font typo noted by esr. 2018-06-13 15:07:32 -07:00
Paul Eggert
07b0026e5d * doc/tar.1: Don't refer to nonexistent tar(5). 2018-05-16 09:03:47 -07:00
Jim Meyering
b531801d6f --one-top-level: avoid a heap-buffer-overflow
* NEWS: Mention this.
* src/suffix.c (strip_compression_suffix): Fix string comparison guard.
Without this change, some ASAN-enabled test runs would fail with the
following.  Also, strip an additional .tar suffix only if the just-
stripped suffix did not match /^\.t/".

==30815==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000002ed at pc 0x00000049d1f4 bp 0x7ffeb5906d50 sp 0x7ffeb5906500
READ of size 1 at 0x6020000002ed thread T0
SCARINESS: 12 (1-byte-read-heap-buffer-overflow)
    #0 0x49d1f3 in __interceptor_strncmp /j/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:407
    #1 0x5670f3 in strip_compression_suffix /j/tar/src/suffix.c:107
    #2 0x575788 in decode_options /j/tar/src/tar.c:2545
    #3 0x5760c0 in main /j/tar/src/tar.c:2708
    #4 0x7f105090df29 in __libc_start_main ../csu/libc-start.c:308
    #5 0x408629 in _start (/j/tar/src/tar+0x408629)

0x6020000002ed is located 3 bytes to the left of 6-byte region [0x6020000002f0,0x6020000002f6)
allocated by thread T0 here:
    #0 0x4d0710 in __interceptor_malloc /j/gcc/libsanitizer/asan/asan_malloc_linux.cc:86
    #1 0x4908ad in __interceptor_strndup /j/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:326
    #2 0x5cbcbd in xstrndup /j/tar/gnu/xstrndup.c:32
    #3 0x5a325b in base_name /j/tar/gnu/basename.c:57
    #4 0x575772 in decode_options /j/tar/src/tar.c:2544
    #5 0x5760c0 in main /j/tar/src/tar.c:2708
    #6 0x7f105090df29 in __libc_start_main ../csu/libc-start.c:308
2018-04-13 11:05:01 +03:00
Andrew Hounsell
f563b896cc Tiny fix
* doc/snapshot.texi: Fix a typo
* scripts/tar-snapshot-edit: Fix a typo
2018-04-07 11:07:57 +03:00
Jim Meyering
c90c6fee01 tests: avoid test failure with non-ancient autoconf
Running "make check" would fail with this:
  T-nonl.at:30: error: m4_divert_push: cannot change diversion
  to `GROW' inside m4_expand
* tests/T-nonl.at: Use printf in place of AS_ECHO_N.
These days, printf should work for everyone.
2018-04-07 10:58:00 +03:00
Jim Meyering
0a0242582f maint: avoid -Wstringop-truncation warnings from upcoming GCC8
* src/create.c (start_private_header, start_header): Convert
trivial uses of strncpy to memcpy, to avoid warnings like this:
In function 'strncpy',
    inlined from 'start_private_header' at create.c:522:3:
/usr/include/bits/string_fortified.h:106:10: warning: \
  '__builtin_strncpy' output truncated before terminating nul \
  copying 2 bytes from a string of the same length \
  [-Wstringop-truncation]
2018-04-07 10:38:31 +03:00
Jim Meyering
2baa531ce5 maint: avoid -Wstringop-truncation warnings upcoming GCC8
* src/buffer.c (gnu_add_multi_volume_header): Convert a use of
strncpy to memcpy, to avoid this warning:
In function 'strncpy',
    inlined from 'gnu_add_multi_volume_header' at buffer.c:1782:3,
    ...
/usr/include/bits/string_fortified.h:106:10: error: '__builtin_strncpy'\
   specified bound 100 equals destination size \
   [-Werror=stringop-truncation]
2018-04-07 10:37:16 +03:00
Jim Meyering
ccef8581b8 maint: avoid warnings from upcoming GCC8
* src/transform.c (_single_transform_name_to_obstack): Mark with
FALLTHROUGH statement rather than /* FALL THROUGH */ comment.
Only the former works with gcc-8.
* src/extract.c (maybe_recoverable): Call abort to tell gcc-8 that
this code is unreachable.
2018-04-07 10:36:23 +03:00
Sergey Poznyakoff
2d00d8b321 Rewrite struct tm formatting
* src/list.c (tartime): Use strftime instead of manually formatting
fields of the struct tm. This should also suppress some gcc warnings.
2018-04-07 10:33:27 +03:00
Jim Meyering
e8c3f4860d tests: add coverage for new --zstd and all other compression tools
* tests/compress.at.in: New file: template from which each
per-compression-tool test is derived.
* tests/Makefile.am (TESTSUITE_AT): Add it.
(EXTRA_DIST): Add compress.at.in.
(compress-*.at): New rules to generate a file/tests for each compression tool.
* tests/testsuite.at (Compression): Add each of these generated
files in a new section.
* tests/.gitignore: Ignore the new generated files.
2018-04-07 10:32:38 +03:00
Aaron Schrab
00f03498a9 Fix typo 2018-03-18 12:06:36 +02:00
Sergey Poznyakoff
688924d2a8 Version 1.30.90
* NEWS: Update.
* configure.ac: Update.
* THANKS: Add Adam Borowski.
2018-03-18 10:38:16 +02:00
Adam Borowski
3d45373d3b Add support for zstd compression
* configure.ac (zstd): Register compression program.
* doc/tar.1: Mention --zstd.
* doc/tar.texi: Document zstd support.
* src/buffer.c: Register zstd compression.
* src/suffix.c: Add suffixes zst and tzst.
* src/tar.c: New compression option --zstd.
2018-03-18 10:24:13 +02:00
Pavel Raiskup
64b43fdf70 tests: fix race in dirrem01 and dirrem02
Previously the '--checkpoint-action=echo' was triggered after
'--checkpoint-action=sleep=1' - so the order of events *usually*
was (for --format='gnu'):

  ...
  1. checkpoint handler before write of 'dir/sub' member
  2. one-second delay
  3. stderr write: 'tar: Write checkpoint 3'
  4. write the member 'dir/sub' into the archive
  5. check that the member's ctime has not been changed
  6. genfile's detecting 'Write checkpoint', doing unlink
  ...

But sometimes, the genfile was fast enough to win the race and
unlinked the directory before the member was written into the
archive (IOW, the order was 1-2-3-6-4-5).  This led to the
occasional warning 'tar: dir/sub: file changed as we read it'.

Swap the order of 'sleep=1' and 'echo' actions so the genfile
utility has (hopefully) enough time to do the unlink before
writing the file into the archive (enforce 1-2-3-6-4-5 order).

* tests/dirrem01.at: Swap 'sleep=1' and 'echo' actions.
* tests/dirrem02.at: Likewise.
2018-03-18 08:33:03 +02:00
Sergey Poznyakoff
7b8efcc7cb Fix typos in the docs 2018-03-13 22:20:53 +02:00
Sergey Poznyakoff
c13401c0a7 Provide a way to skip tests that create very large files
Define environment variable TARTEST_SKIP_LARGE_FILES=1 in order
to skip tests that require lots of disk space.

* tests/testsuite.at (AT_SKIP_LARGE_FILES): New macro.
* tests/sparse03.at: Mark test with AT_SKIP_LARGE_FILES.
* tests/sparse05.at: Likewise.
* tests/star/pax-big-10g.at: Likewise.
* tests/star/ustar-big-2g.at: Likewise.
* tests/star/ustar-big-8g.at: Likewise.
2018-03-13 21:58:37 +02:00
Sergey Poznyakoff
847a36f064 Testsuite bugfix
* tests/difflink.at: Define order of files within tested archive.
2018-03-13 09:59:11 +02:00
Sergey Poznyakoff
2b7fc4aee9 testsuite: account for absolute file names starting with double slash
* tests/incr08.at: Absolute file names can start with //
* tests/xform03.at: Likewise.
2018-03-13 08:08:44 +02:00
Sergey Poznyakoff
f8459cf838 Version 1.30
* configure.ac: Set version 1.30
* NEWS: Update.
2017-12-17 12:28:30 +02:00
Paul Eggert
22b5645879 Fix "concatenating" typo.
Problem reported by Rodrigo Queiro in:
https://lists.gnu.org/r/bug-tar/2017-11/msg00021.html
* doc/intern.texi (Extensions): Fix typo.
2017-11-20 11:10:25 -08:00
Paul Eggert
d44d592013 Port to gcc -Wimplicit-fallthrough=5
* src/common.h (FALLTHROUGH): New macro, for use with gcc
-Wimplicit-fallthrough=5, which is now the default when used with
Gnulib after commit 2017-05-16T16:23:52!eggert@cs.ucla.edu
and with --enable-gcc-warnings
2017-11-18 08:42:23 -08:00
Paul Eggert
0c8e7bad3e Port to Texinfo 6.4
* doc/tar.texi (Sparse Recovery): Omit ‘.’ from anchor name,
as ‘makeinfo’ now complains about it.  All uses changed.
2017-11-18 08:42:23 -08:00
Paul Eggert
37d7ce16c5 Document base-256 representation in GNU format
Problem reported by Rodrigo Queiro in:
https://lists.gnu.org/r/bug-tar/2017-11/msg00018.html
* doc/intern.texi (Standard, Extensions):
Document base-256 representations.
2017-11-18 08:42:23 -08:00
Paul Eggert
9ed0a6ba35 build: update gnulib submodule to latest 2017-11-18 08:42:23 -08:00
Paul Eggert
35008b75e4 Fix typo caught by GCC 7.2.1
* lib/wordsplit.c (wordsplit_perror): Add missing "break;".
2017-11-18 08:42:23 -08:00
Sergey Poznyakoff
9855bc011e Update docs
* doc/Makefile.am: Add recipes.texi
* doc/recipes.texi: New file.
* doc/tar.texi: New appendix "Recipes"
2017-11-16 18:12:36 +02:00
Pavel Raiskup
22093ad2b6 tests: more deterministic xattr07
* tests/xattr07.at: Define order of files within tested archive.
2017-11-16 14:45:01 +02:00
Sergey Poznyakoff
ee0508f01c Minor improvements in the docs. 2017-11-16 14:31:53 +02:00
Sergey Poznyakoff
32e51de2af New option --warning=failed-read
* NEWS: Document the --warning=failed-read option.
* doc/tar.texi: Likewise.
* doc/tar.1: Likewise.
* src/common.h (WARN_FAILED_READ): New constant.
(WARNING_ENABLED): New macro.
* src/misc.c (close_diag, open_diag)
(read_diag_details, readlink_diag)
(savedir_diag, seek_diag_details)
(stat_diag): Suppress warnings if WARN_FAILED_READ is set.
* src/warning.c (failed-read): New keyword.
2017-11-16 14:22:48 +02:00
Sergey Poznyakoff
560f67c9f0 Fix docs
* doc/tar.texi: Fix description of the argument to --xattrs-exclude
and --xattrs-include option. It is a globbing pattern, not a regex.

Fix a typo (LZOP)
2017-11-16 12:24:45 +02:00
Sergey Poznyakoff
3ae075a51a Fix the --delay-directory-restore option
* src/extract.c (find_direct_ancestor): New function.
(create_placeholder_file): Set after_links member on delayed_set_stat
entries starting from the direct ancestor of the placeholder file.

* tests/extrac21.at: New testcase.
* tests/testsuite.at: Add extrac21
* tests/Makefile.am: Likewise.

* NEWS: Update.
2017-11-16 11:34:13 +02:00
Sergey Poznyakoff
1bf590ab2d Fix reporting of hardlink mismatch during compare
* src/common.h (quote_n_colon): New prototype.
* src/misc.c (quote_n_colon): New function.
* src/compare.c (report_difference, diff_link): Use quote_n_colon.

* tests/difflink.at: New file.
* tests/Makefile.am: Add difflink.at
* tests/testsuite.at: Likewise.
2017-11-09 09:55:43 +02:00
Sergey Poznyakoff
dee7e3f16e Fix --verbatim-files-from
* src/names.c (read_next_name): Don't unquote name read from the
file, if --verbatim-files-from option is in effect.
(names_options): improve description of --verbatim-files-from
* tests/T-null2.at: Test the change.
2017-11-09 09:06:26 +02:00
Sergey Poznyakoff
13edc746f6 Fix typo
* doc/tar.texi
2017-11-09 09:06:18 +02:00
Sergey Poznyakoff
1e6d2c0488 Fix the effect of --transform over hard link targets without the --absolute-names
* src/create.c (file_count_links): Apply safer_name_suffix to the
hard link name prior to transforming it.
* tests/xform03.at: New test case.
* tests/Makefile.am: Add xform03.at
* tests/testsuite.at: Likewise.
2017-09-30 10:26:56 +03:00
Sergey Poznyakoff
228d83ed24 Bugfix
* src/tar.c (tar_help_filter): Add missing break statement
2017-08-24 22:18:39 +03:00
Troels Thomsen
ede0d1b42d Fix typo 2017-06-29 14:23:15 +03:00
Pavel Raiskup
1e8b786e65 Fix non-deterministic archive type detection
Due to analysis of partly uninitialized read-ahead buffer
(short_read call), we sometimes mistakenly classified very small
compressed archives as non-compressed; which in turn caused
extraction failure.

* src/buffer.c (check_compressed_archive): Don't assume that
archives smaller than BLOCKSIZE could be non-compressed, as tar
header always has at least one block.
2017-05-29 16:12:48 +03:00
Jonas Julino
8b9026f3ae Fix handling of directories removed during incremental tar run
Co-authored-by: Sergey Poznyakoff <gray@gnu.org.ua>
* paxutils: Upgrade
* src/create.c (create_archive): Use file_removed_diag
instead of calling the corresponding *_diag function
directly.
* tests/dirrem01.at: New testcase.
* tests/dirrem02.at: New testcase.
* tests/Makefile.am: Add new tests.
* tests/testsuite.at: Likewise.
2017-05-29 15:59:53 +03:00
Sergey Poznyakoff
795877532e Fix a bug in multi-volume archive creation.
When creating multivolume archives, the bufmap code in buffer.c
implicitly assumed that the members are stored in the archive
contiguously, ignoring the member (and eventual extended) headers
between them.  This worked until the member header happened to be
at the very beginning of the volume, in which case its length was
included in the calculation of the stored size and size left to
store.  Due to this, the GNUFileParts extended header contained
invalid GNU.volume.offset value, and the resulting archive failed
to extract properly.

This patch also eliminates improper listing of file part headers
as regular files, when creating multivolume posix archives with -v.

* src/buffer.c (bufmap): New member nblocks.  Counts number of blocks
of file data written since reset.
(bufmap_reset): Reset nblocks to 0.
(_flush_write): Update nblocks.  When computing offset difference for
bufmap_reset, count only data blocks, not headers.
(close_archive): Flush archive until all blocks are written.
(add_chunk_header): Use simple_finish_header instead of finish_header
to avoid listing chunk header as regular file in verbose mode.
* tests/multiv10.at: New test case.
* tests/Makefile.am: Add new test.
* tests/testsuite.at: Add new test.
2017-05-29 11:31:12 +03:00
Paul Eggert
da8d0659a6 --numeric-owner now affects private headers too
Problem reported by Daniel Peebles in:
http://lists.gnu.org/archive/html/bug-tar/2017-04/msg00004.html
* NEWS: Document this.
* src/create.c (write_gnu_long_link): If --numeric-owner,
leave the user and group empty in a private header.  Cache the
names for 0.
2017-04-06 18:18:12 -07:00
Pavel Raiskup
d06126f814 Test and document --keep-directory-symlink
* doc/tar.1: Document the option.
* tests/extrac20.at: New testcase.
* tests/Makefile.am: Mention extrac20.
* tests/testsuite.at: Likewise.
2017-02-28 12:59:17 +02:00
Paul Eggert
2be02a7c9a Fix incompatibility with PGI 16.10
* src/tar.c (options): Fix incompatibility with the C standard,
which says that arguments to macro calls cannot contain # directives.
2017-02-14 08:55:28 -08:00
Sergey Poznyakoff
30fe67226a Update copyright years 2017-01-02 14:49:55 +02:00
Sergey Poznyakoff
2bfacfe3d0 Fix description of the "escape" quoting style 2016-11-12 12:49:10 +02:00
Sergey Poznyakoff
76dad6d1fb Better error checking in the backup script.
* scripts/backup.in: Check exit code of MT_BEGIN
* scripts/backup.sh.in (backup_host): Return meaningful code
in case of remote execution.  See the comment, though.
2016-11-12 12:31:24 +02:00
Sergey Poznyakoff
a2fd82f622 Minor documentation fix
* doc/tar.texi: Fix example about use of --no-recursion with -T
2016-11-12 11:46:43 +02:00
Sergey Poznyakoff
3a283cfe9f Fix the --add-file option.
* src/common.h (name_more_files): New proto.
(files_from_option): Remove.
* src/names.c (name_more_files): New file.
(names_options): Fix declaration of the
add-file option.
(names_parse_opt): Handle --add-file.
* src/tar.c (struct tar_args): Remove the input_files member.
Change all uses: use name_more_files() instead.
* tests/Makefile.am: Add new test.
* tests/add-file.at: New testcase.
* tests/testsuite.at: Add new test.
2016-11-12 11:27:08 +02:00
Sergey Poznyakoff
ca9399d4ee Add missing files 2016-11-11 13:29:55 +02:00
Pavel Raiskup
597b0ae509 don't set xattrs when --skip-old-files is used
* src/extract.c (set_xattr): Properly handle maybe_recoverable()
output.  Throw warnings to not complicate caller.
(extract_file): Don't handle set_xattr's error.
* tests/xattr07.at: New testcase.
* tests/Makefile.am: Mention new testcase.
* tests/testsuite.at: Likewise.
* THANKS: Dawid.
2016-11-11 12:31:40 +02:00
Sergey Poznyakoff
21c1c29592 Minor fix
* src/tar.h (tar_stat_info): Change type of real_size_set to bool
2016-11-11 12:22:03 +02:00
Pavel Raiskup
00f928642f sparse: fix pax extraction for unicode filenames
Make sure that 'GNU.sparse.name' header has higher priority than
(for sparse-purposes artificially modified) 'path' pax header.

Historically, the 'GNU.sparse.name' header comes before 'path';
this caused that modified 'path' header won and that is not what
we want in sparse "capable" tar implementation.

* src/tar.h (tar_stat_info): New argument sparse_name_done.
* src/xheader.c (raw_path_decoder): Move here the unconditional
code from path_decoder.
(path_decoder): Apply raw_path_decoder only if sparse_path_decoder
was not yet called.
(sparse_path_decoder): New wrapper around raw_path_decoder.
* tests/sparse07.at: New testcase.
* tests/testsuite.at: Mention new testcase.
* tests/Makefile.am: Likewise.
2016-11-11 11:18:32 +02:00
Pavel Raiskup
c81a0853bb * tests/xattr06.at: Test include/exclude during archive/exctract. 2016-11-10 10:02:44 +02:00
Ian McLeod
bb6ddd8e04 Bugfix - fix xattr exclude/include for archive create
This makes archive create behavior consistent with the
documentation.  Without this change xattr include/exclude options
are accepted when creating an archive but are silently ignored.

* src/xattrs.c (xattrs_xattrs_get): Apply exclude/include mask
when fetching extended attributes
* tests/Makefile.am: Add new test case.
* tests/testsuite.at: Likewise.
2016-11-10 10:02:31 +02:00
Paul Eggert
7340f67b98 When extracting, skip ".." members
* NEWS: Document this.
* src/extract.c (extract_archive): Skip members whose names
contain "..".
2016-10-29 21:05:35 -07:00
Sergey Poznyakoff
1d2674bacc Mark all tests related to -C option with the "chdir" keyword 2016-09-26 14:00:12 +03:00
Sergey Poznyakoff
e1b7e40ff0 Fix interaction of -u with -C
* src/update.c (update_archive): Pass correct change_dir
value for addname
* tests/update03.at: New file.
* tests/Makefile.am: Add update03.at
* tests/testsuite.at: Include update03.at
2016-09-26 13:53:50 +03:00
Sergey Poznyakoff
c2886473a8 Fix passing string values via TAR_OPTIONS
* src/tar.c (parse_default_options): Don't free parsed words.
* tests/options03.at: New testcase.
* tests/Makefile.am: Add options03.at
* tests/testsuite.at: Include options03.at
2016-09-21 08:58:10 +03:00
Sergey Poznyakoff
ac065c57fd Tiny bugfix 2016-05-28 01:05:07 +03:00
Sergey Poznyakoff
9a33077a7b Report positional options that were used but had no effect during archive creation
* src/names.c (file_selection_option)
(file_selection_option_name): New functions.
(unconsumed_option_push, unconsumed_option_free)
(unconsumed_option_report): New functions.
(name_list_advance): Maintain a list
of eventually unconsumed options during archive creation.
Report unconsumed options, if any.

* tests/positional01.at: New test case.
* tests/positional02.at: New test case.
* tests/positional03.at: New test case.
* tests/Makefile.am: Add new test cases.
* tests/testsuite.at: Likewise.

* NEWS: Document the changes.
* configure.ac: Version 1.29.90
* doc/tar.texi: Document the changes.
2016-05-27 11:50:19 +03:00
Sergey Poznyakoff
20b55f0679 Version 1.29 2016-05-16 11:51:12 +03:00
Sergey Poznyakoff
35b292ac4b Minor fix
* src/names.c (new_name): rename to make_file_name. All uses changed.
2016-05-16 11:50:19 +03:00
Sergey Poznyakoff
61cd3fd268 Fix argument handling when running external commands.
* src/system.c (xexec): Use sh -c to run the command.  This fixed
bug introduced by 7b5e80396 (tar 1.27)
* doc/tar.texi: Fix checkpoint examples: (1) $TAR_FILENAME
is not available when creating archive and (2) --checkpoint
can't be used as abbreviation of --checkpoint-action
2016-04-14 11:51:38 +03:00
Sergey Poznyakoff
3010818f36 Remove iotty test
The auxiliary utility ttyemu proved to be unreliable.  Given existing
differences between pty implementations and termios ioctls on various
platforms, writing it in a portable way requires effort disproportional
to its actual purpose.

* configure.ac: Remove check for grantpt
* gnulib.modules: Remove posix_openpt, ptsname, and unlockpt
* tests/Makefile.am (TESTSUITE_AT): Remove iotty.at
(check_PROGRAMS): Remove ttyemu.
* tests/testsuite.at: Remove iotty.at
* tests/iotty.at: Remove.
* tests/ttyemu.c: Remove.
2016-04-06 08:34:55 +03:00
Pavel Raiskup
733e2741b1 xattrs: fix build on Darwin
Be careful to define HAVE_XATTRS when not all needed xattr-related
functions are properly defined either in libc or libattr.

Reported independently by Denis Excoffier and Dominyk Tille.

* acinclude.m4 (TAR_HEADERS_ATTR_XATTR_H): Check for each xattr
function separately.  Don't AC_CHECK_LIB (LIBS is filled by
AC_SEARCH_LIBS when necessary).
* src/Makefile.am: The LDADD -lattr was redundant.
2016-04-05 17:55:19 +03:00
Sergey Poznyakoff
195a25316c Remove --preserve option
* src/tar.c: Remove --preserve option
* NEWS: Update.
* doc/tar.texi: Update.
2016-03-24 08:39:52 +02:00
Sergey Poznyakoff
74e3b497c4 Fix testcase
* tests/time02.at: Sort tar -d output
2016-03-24 08:38:38 +02:00
Sergey Poznyakoff
29f652871e Update THANKS file 2016-03-24 07:30:16 +02:00
Jeremy Bobbio
13d04fe6ae New option --clamp-mtime
The new `--clamp-mtime` option will change the behavior of `--mtime` to only
use the time specified if the file mtime is newer than the given time.
The `--clamp-mtime` option can only be used together with `--mtime`.

Typical use case is to make builds reproducible: to loose less
information, it's better to keep the original date of an archive, except for
files modified during the build process. In that case, using a reference
(and thus reproducible) timestamps for the latter is good enough. See
<https://wiki.debian.org/ReproducibleBuilds> for more information.

Patch submitted by Jeremy Bobbio and
Daniel Kahn Gillmor <dkg@fifthhorseman.net>

* doc/tar.1: Document --clamp-mtime
* doc/tar.texi: Likewise.

* src/common.h (set_mtime_option_mode): New enum
(set_mtime_option): Change type to enum set_mtime_option_mode.
(NEWER_OPTION_INITIALIZED): Rename to NEWER_OPTION_INITIALIZED.
* src/create.c (start_header): Set mtime depending on set_mtime_option.
* src/tar.c (options,parse_opt): New option --clamp-mtime
(decode_options): Initialize mtime_option

* tests/time02.at: New testcase.
* tests/Makefile.am: Add new testcase
* tests/testsuite.at: Likewise.
2016-03-24 07:26:27 +02:00
Sergey Poznyakoff
8d31493c99 Acknowledgments
* THANKS: Add Dagobert Michelsen
2016-03-21 20:46:19 +02:00
Sergey Poznyakoff
752b447f3e Fix the testsuite
* tests/sparse06.at: Don't use timeout: depending on the filesystem
mounted, current LA and lots of other factors, creation of archive can
take much more time than the expected 2 seconds.
2016-03-21 20:33:26 +02:00
Sergey Poznyakoff
a3aa7003ea Fix ckmtime
* gnulib.modules: Use timespec-sub
* tests/ckmtime.c: Use second resolution.
2016-03-21 13:35:32 +02:00
Sergey Poznyakoff
143dc63ffa Fix the testsuite
* tests/sparse05.at: Use autom4te magic to generate mapfile,
instead of the shell command seq, which is not always available.
* tests/listed03.at: Skip the test if xgetcwd fails.
* tests/ckmtime.c: New file.
* tests/Makefile.am: Build ckmtime
* tests/testsuite.at (AT_CHECK_TIMESTAMP): Check whether newly created
files have timestamps consistent with the creation time.  Skip the test
if not.
* tests/incr01.at: Use AT_CHECK_TIMESTAMP
* tests/incr02.at: Likewise.
* tests/incr03.at: Likewise.
* tests/incr04.at: Likewise.
* tests/incr05.at: Likewise.
* tests/incr06.at: Likewise.
* tests/incr07.at: Likewise.
* tests/incr08.at: Likewise.
* tests/incr09.at: Likewise.
* tests/incr10.at: Likewise.
* tests/incr11.at: Likewise.
* tests/incremental.at: Likewise.
* tests/listed01.at: Likewise.
* tests/listed02.at: Likewise.
* tests/listed04.at: Likewise.
* tests/listed05.at: Likewise.
2016-03-20 23:11:27 +02:00
Sergey Poznyakoff
c0fb0740fa Testsuite fixes.
* paxutils: Update.
* src/unlink.c (flush_deferred_unlinks): OpenSolaris sets EEXIST
instead of ENOTEMPTY if trying to remove a non-empty directory.
* tests/numeric.at: Avoid using awk -v: some older awks don't support
that option.  Also fix environment variable usage.
* tests/onetop05.at: Skip test if unable to set initial directory
mode bits.
* tests/sparse06.at: Use --quiet option.
2016-03-18 22:18:58 +02:00
Sergey Poznyakoff
6ac0dd1d73 Revise docs 2016-03-18 14:27:27 +02:00
Sergey Poznyakoff
160fb9abd2 Fix build with --enable-gcc-warnings
* configure.ac: Disable stack-protector warnings
2016-03-18 13:08:39 +02:00
Sergey Poznyakoff
f6ad0e4af2 Improve testsuite
* tests/iotty.at: Skip test if ttyemu can't do its job
2016-03-17 14:22:35 +02:00
Sergey Poznyakoff
e4b246c14a Document xattrs, ACL and SELinux-related options.
* doc/tar.1: Document all options.
* doc/tar.texi: Likewise.
2016-03-16 20:08:00 +02:00
Sergey Poznyakoff
2a7c84b4a9 Fix appending to archive with changed blocking factor.
* src/buffer.c (flush_archive): If previous reading attempt resulted
in short read, correctly use the remaining record space.
(backspace_output): Fix position calculation (still has to be
improved).

* tests/append05.at: New test case.
* tests/Makefile.am: Add new test.
* tests/testsuite.at: Likewise.
2016-03-15 00:02:40 +02:00
Sergey Poznyakoff
da7845c656 Fix coredump on parsing invalid traditional option
* src/tar.c (find_argp_option): Fix loop termination condition.
2016-03-14 13:13:04 +02:00
Sergey Poznyakoff
8980ecd62d Update copyright years 2016-01-20 11:29:17 +02:00
Sergey Poznyakoff
63f2e969dd Allow escaped delimiters in transform expressions.
Patch provided by Charles McGarvey and Flavio Poletti.

* src/transform.c (parse_transform_expr): Allow escaped delimiters
in transform expressions.
* tests/xform02.at: New test case.
* tests/Makefile.am: Add xform02.at
* tests/testsuite.at: Include xform02.at
* THANKS: Update.
2016-01-20 11:16:02 +02:00
Sergey Poznyakoff
445293654d Fix eventual dereference of uninitialized pointer.
* src/exclist.c (hg_initfn): Initialize hgopt.
2015-12-17 16:04:40 +02:00
Pavel Raiskup
b5f581e637 sparse: fix use of indeterminate value
* src/xheader.c (sparse_map_decoder): Move 'e' up from loop-block.
2015-12-17 16:01:18 +02:00
Sergey Poznyakoff
0f26331b17 fix a typo
* doc/tar.texi (Incremental Dumps): Add missing --file to the
'--list' example.
2015-12-11 15:21:04 +02:00
Sergey Poznyakoff
196fef9b40 Minor fixes.
* doc/tar.texi: Document position-sensitive options in a
separate subsection.
* src/names.c (names_argp,names_argp_children): Explicitly initialize
all members.
2015-12-11 14:19:44 +02:00
Sergey Poznyakoff
68dd249987 Minor fix 2015-12-11 01:10:43 +02:00
Sergey Poznyakoff
4cf2af4500 Fix handling of filename-selection options.
Filename-selection options are --wildcards, --recursive, etc. (see
names.c for a complete list).  These options are position-sensitive,
i.e. each such option affects all filenames and filename-selection
options that appear after it until eventually cancelled by a
corresponding counterpart option.

These options can appear in "file-from" file lists, which means that
they cannot be handled right away, but instead should be put on
the "name_elt" list and processed sequentionally, as file name arguments
are.

* src/common.h (warn_regex_usage): Remove.
(name_add_name): Change signature.
(name_add_dir, name_add_file): Remove prototypes.
* src/names.c (name_add_option, name_add_dir)
(name_add_file): Static functions.
(names_options, is_file_selection_option, names_parse_opt): Static functions.
(names_argp_children): New variable.
(NELT_NAME, NELT_CHDIR)
(NELT_FILE, NELT_NOOP): Redefine as enum nelt_type.
(NELT_FMASK): Remove.
(NELT_OPTION): New constant.
(name_elt) <type>: Change type.
<v.opt>: New member.
(name_elt_alloc_matflags): Remove.
(name_add_name): Take one argument.
(name_add_option): New static function.
(name_add_file): Take one argument.
(read_next_name): Use filename_terminator and
verbatim_files_from_option to initialize file.term and file.verbatim.
* src/tar.c: Move handling of filename-selection options to names.c

* tests/T-dir00.at: Fix typo.
* tests/T-recurse.at: Remove expected failure.
2015-12-11 00:50:23 +02:00
Pavel Raiskup
cadc43ace5 better test --{,no-}recursion options
* tests/recurs02.at: Also test --list mode.
* tests/T-recurse.at: New test case.  Test that -T option works
correctly together with --{,no-}recursion.
* tests/Makefile.am: Mention new test T-recurse.at.
* tests/testsuite.at: Likewise.
2015-12-10 14:55:34 +02:00
Pavel Raiskup
239441b5df Bugfix
* src/buffer.c (try_new_volume): Warn if user supplied malformed
tar archive.
Consistently use WARN (instead of ERROR) when reporting.
2015-12-06 22:14:23 +02:00
Sergey Poznyakoff
0a93c16c62 Fix segfault when extracting from a multi-volume archive.
Fix suggested by Pavel Raiskup.

* src/buffer.c (try_new_volume): Fix dereferencing NULL pointer.
* tests/multiv09.at: New testcase.
* tests/Makefile.am: Add new testcase.
* tests/testsuite.at: Likewise.
2015-12-06 22:02:16 +02:00
Sergey Poznyakoff
5dd490e7f1 Fix NEWS 2015-12-06 21:20:48 +02:00
Pavel Raiskup
68e9ab4966 numeric-owner: print big UID/GID correctly
* src/list.c (simple_print_header): Do not parse ustar header
for UID/GID again (tar_stat_info has already been correctly
filled with respect to possible uid/gid extended headers).
* tests/numeric.at: New testcase for --numeric-owner option.
* tests/Makefile.am: Add new testcase.
* tests/testsuite.at: Likewise.
2015-12-06 21:18:51 +02:00
Sergey Poznyakoff
b684326e69 Use SEEK_HOLE for hole detection
Based on patch by Pavel Raiskup.

Use SEEK_HOLE/SEEK_DATA feature of lseek on systems that support
it.  This can make archiving of sparse files much faster.

Implement the --hole-detection option to allow users to select
hole-detection method.

* src/common.h (hole_detection_method): New enum.
(hole_detection): New global.
* src/sparse.c  (sparse_scan_file_wholesparse): New function as a
method for detecting sparse files without any data.
(sparse_scan_file_raw): Rename from sparse_scan_file; with edits.
(sparse_scan_file_seek): New function.
(sparse_scan_file): Reimplement function.
* src/tar.c: New option --hole-detection

* tests/checkseekhole.c: New file.
* tests/.gitignore: Mention two test binaries.
* tests/Makefile.am: Add new tests.
* tests/testsuite.at (AT_SEEKHOLE_PREREQ): New macro.
Include sparse06.at.
* tests/sparse06.at: New test case.
* tests/sparse02.at: Force raw hole-detection method.
* tests/sparsemv.at: Likewise.
* tests/sparsemvp.at: Likewise.

* doc/tar.1: Document --hole-detection option.
* doc/tar.texi: Document hole-detection algorithms and
command-line options.
* NEWS: Document hole-detection.
2015-12-06 00:14:55 +02:00
Sergey Poznyakoff
589ba77faf Catch compressor execution errors.
* src/misc.c (write_fatal_details): Move to buffer.c
* src/buffer.c (write_fatal_details): Close the archive and wait for
the compressor program to terminate in order to catch eventual execution
errors.
* src/system.c (sys_child_open_for_compress): Ignore SIGPIPE so tar will
not silently terminate when unable to write to the compressor.
* tests/comperr.at: New file.
* tests/Makefile.am: Add comperr.at
* tests/testsuite.at: Include comperr.at
2015-12-05 16:54:26 +02:00
Sergey Poznyakoff
6ea9e62bb3 Upgrade paxutils 2015-12-05 08:48:03 +02:00
Sergey Poznyakoff
d02c81df15 Fix extraction from concatenated incremental archives with renamed directories.
Complements 15c02c2b.

* src/extract.c (delayed_set_stat): Change type of file_name.
(delay_set_stat): Allocate file_name member.
(free_delayed_set_stat): Free file_name.
(fixup_delayed_set_stat): New function.
(rename_directory): Call fixup_delayed_set_stat on success.

* tests/incr11.at: New testcase.
* tests/incr10.at: Improve description.
* tests/Makefile.am: Add incr11.at
* tests/testsuite.at: Add incr11.at
2015-11-29 21:11:08 +02:00
Sergey Poznyakoff
e426787454 Fix bug in the inplementation of --one-top-level.
When extracting an archive that contains './' with the --one-top-level option,
the mode and ownership of '.' would be incorrectly applied to the current
working directory, instead of the requested top-level directory.

* src/list.c (enforce_one_top_level): Map '.' to the top-level
directory.
* tests/Makefile.am: Add onetop05.at
* tests/testsuite.at: Include onetop05.at.
* tests/onetop05.at: New file.
* tests/onetop01.at: Fix keywords.
* tests/onetop02.at: Likewise.
* tests/onetop03.at: Likewise.
* tests/onetop04.at: Likewise.
2015-11-21 21:56:49 +02:00
Sergey Poznyakoff
e6fcc73efa Work around unlinkat bug on FreeBSD and GNU/Hurd
* src/unlink.c (dunlink_insert): New function.
(flush_deferred_unlinks): Skip cwds and nonempty directories
at the first pass.  If force is requested, run a second pass
removing them.
(queue_deferred_unlink): Make sure current working directory
entries are sorted in descending order by the value of dir_idx.
This makes sure they will be removed in right order, which works
around unlinkat bug on FreeBSD and GNU/Hurd.
* tests/remfiles08b.at: Remove expected failure.
* tests/remfiles09b.at: Likewise.
2015-11-11 13:01:45 +02:00
Sergey Poznyakoff
6167c23e22 Fix coredump on FreeBSD when TAR_OPTIONS is set
* src/tar.c (parse_default_options): Use program_name instead of
program_invocation_short_name.  On some systems the latter is NULL when
the function is called, which causes coredumps.
(tar_set_quoting_style): Likewise.
* src/names.c: Likewise.
2015-11-10 18:25:47 +02:00
Sergey Poznyakoff
5e2a1d5b38 Use sort in T-dir tests. 2015-11-02 13:54:26 +02:00
Sergey Poznyakoff
4aebc943bb Fix distclean in tests/
* tests/Makefile.am: Remove "download"
2015-11-02 13:19:36 +02:00
Sergey Poznyakoff
1a615a41f5 New options: --owner-map and --group-map.
* NEWS: Update.
* doc/tar.1: Document --owner-map and --group-map
* doc/tar.texi: Likewise.

* src/map.c: New file.
* src/Makefile.am: Add map.c
* src/common.h (owner_map_read, owner_map_translate)
(group_map_read, group_map_translate): New protos.
* src/create.c (start_header): Use owner_map_translate
and group_map_translate to optionally translate user/group names/ids.
* src/tar.c: New options --owner-map and --group-map.

* tests/map.at: New file.
* tests/Makefile.am: Add map.at
* tests/testsuite.at: Include map.at.
2015-11-02 13:00:39 +02:00
Kir Kolyshkin
cdf41c383f doc: fix font and spelling typos
* doc/tar.1: Fix font and spelling typos in man page.
Copyright-paperwork-exempt: yes
2015-09-24 09:22:51 -07:00
Paul Eggert
a65086c71c Fix problems caught by static checking
Most of these can be caught by configuring with --enable-gcc-warnings.
Problem reported by Pavel Raiskup in:
http://lists.gnu.org/archive/html/bug-tar/2015-09/msg00001.html
* src/buffer.c (format_total_stats):
Prefer pointer to const when it’s OK to use const.
(default_total_format): Now const.
* src/buffer.c (default_total_format):
* src/exclist.c (excfile_head, excfile_tail, vcs_ignore_files):
* src/misc.c (namebuf_add_dir, namebuf_finish):
* src/tar.c (verbatim_files_from_option, option_set_in_cl)
(optloc_eq, set_old_files_option):
Now static.
* src/common.h: Adjust to match the other changes described here.
* src/exclist.c (info_cleanup_exclist):
* src/tar.c (argp_program_version, argp_program_bug_address):
Remove; unused.
(parse_default_options): Define via prototype instead of old style.
(parse_default_options, decode_options):
Fill out incomplete initializers.
2015-09-24 08:32:15 -07:00
Sergey Poznyakoff
ae23a57d70 Improve option sanity checking
Any two conflicting options are reported only if they both occur in
the command line.  Otherwise, options defined in the command line
silently override those set in the TAR_OPTIONS environment variable.

* src/common.h (option_source): New enum.
(option_locus): New struct.
* src/names.c (name_elt): New member: line.
(name_add_file): Initialize line.
(read_name_from_file): Keep track of input line number for diagnostic
purposes.
(handle_option): Take a pointer to struct name_elt as 2nd parameter;
pass locus info to more_options().
* src/tar.c (tar_args): New member: loc.
(option_class): New enum.
(optloc_save,optloc_lookup)
(option_set_in_cl,optloc_eq): New functions.
(set_use_compress_program_option): Take into account option location.
(set_old_files_option): New function.
(parse_opt): Keep track of option locations.
(more_options): Improve error reporting.
(parse_default_options): New function.
(decode_options): Parse TAR_OPTION and command line separately.
Options from the latter silently override those from the former.

* lib/prepargs.c: Remove.
* lib/prepargs.h: Remove.
* lib/Makefile.am: Update.
2015-08-31 08:37:46 +03:00
Sergey Poznyakoff
c440a92627 Improve check-full
* tests/atlocal.in: Download external archives to $abs_builddir/download.
(tarball_prereq): Create destination directory if necessary.
* tests/.gitignore: Add download
2015-08-24 13:05:52 +03:00
Sergey Poznyakoff
aa9676dcad Fix check-full
* tests/atlocal.in (TAR_DATA_URL): Berlios is dead.  Get
test archives from gnu.org.ua
2015-08-24 12:50:49 +03:00
Sergey Poznyakoff
6cb94e37a9 Include gnulib and paxutils as submodules.
* .gitmodules: New file.
* README-alpha: Update.
* README-hacking: Update.
* bootstrap: Install slightly modified version from the gnulib repo.
* bootstrap.conf: Add paxutils-related stuff.
* .gitignore: Update.
* doc/.gitignore: Update.
* po/.gitignore: Update.
* gnu/Makefile.am
2015-08-24 11:52:14 +03:00
Sergey Poznyakoff
232a7258c3 Update docs.
* doc/tar.1: Document --verbatim-files-from option.
2015-08-24 09:29:04 +03:00
Sergey Poznyakoff
429bd311b7 Add missing VCS files to --exclude-vcs list
* src/tar.c (vcs_file_table): Add .gitmodules and .gitattributes
* doc/tar.texi: Update.
2015-08-20 17:52:20 +03:00
Sergey Poznyakoff
eb621c67cf Options to control option handling in file lists.
The --verbatim-files-from option disables option handling in
file lists.  The --no-verbatim-files-from reverts its effect.

The --null option implies --verbatim-files-from.  This restores
the documented behavior, broken by 26538c9b.

* src/common.h (verbatim_files_from_option): New global.
* src/names.c (name_elt): New member: file.verbatim
(name_add_file): Take 'verbatim' state as its third parameter.
(read_next_name): Don't call handle_option if file.verbatim
is set.
* src/tar.c: New options --verbatim-files-from and
--no-verbatim-files-from.

* doc/tar.texi: Document --verbatim-files-from and
--no-verbatim-files-from options.
* NEWS: Update.
* configure.ac: Version 1.28.90

* tests/T-null2.at: New testcase.
* tests/Makefile.am: Update.
* tests/testsuite.at: Update.
2015-08-03 16:47:22 +03:00
Anders Jonsson
21f86195b7 Fix typos (preceeded etc.)
Copyright-paperwork-exempt: yes
2015-07-25 08:47:25 -07:00
Paul Eggert
fe3b106cb3 tar: fix symlink race and symlink transform bug
Problem reported by Tobias Stoeckmann in:
http://lists.gnu.org/archive/html/bug-tar/2015-07/msg00004.html
* gnulib.modules: Add areadlinkat-with-size.
* src/create.c: Include areadlink.h.
(dump_file0): Use areadlinkat_with_size, rather than trying to do
it by hand, incorrectly.  This also avoids assumption that
the symlink contents fit on the stack.  Also, use the transformed
link name, not the original link name, when deciding whether the
name is long enough to require writing a long link.
2015-07-13 09:53:56 -07:00
Paul Eggert
3828942550 tar: port -d to longer symlinks
* src/compare.c (diff_symlink):
Don't use alloca on symlink length; it might be too big for the stack.
Don't assume that readlinkat's return value fits in 'int'.
Prefer memcmp to strncmp where either will do.
2015-07-13 09:53:56 -07:00
Paul Eggert
d95457e007 tar: port to recent gnulib
* gnulib.modules: Remove 'acl' and add 'file-has-acl'.
2015-07-13 09:53:56 -07:00
Paul Eggert
da06935f6e tar: pacify GCC 5.1 -Wformat-signedness
* lib/wordsplit.c (struct wordsplit_node.flags):
Now unsigned, so that 'printf ("%x", p->flags)' doesn't provoke GCC.
* src/incremen.c (read_num, dumpdir_ok):
Don't printf an int with %x or %o.
2015-07-13 09:53:55 -07:00
Sergey Poznyakoff
15c02c2b9d Fix extraction from concatenated incremental archives.
* src/common.h (remove_delayed_set_stat): New proto.
* src/extract.c (free_delayed_set_stat)
(remove_delayed_set_stat): New function.
(apply_nonancestor_delayed_set_stat): Use free_delayed_set_stat.
* src/misc.c (safer_rmdir): Remove delayed_set_stat entry
corresponding to the removed directory.
* tests/incr10.at: New test case.
* tests/Makefile.am: Add new test.
* tests/testsuite.at: Likewise.
2015-04-16 13:02:10 +03:00
Sergey Poznyakoff
0c4aa85e6c Fix make installcheck
Make installcheck would fail unless make check had been run before it.
Reported by Erik Brangs <erik.brangs@gmx.de>

* tests/Makefile.am (installcheck-local): Depend on $(check_PROGRAMS)
2015-04-10 11:35:44 +03:00
Paul Eggert
731b7b07de tar: don't assume GZIP
* Makefile.am (dist-hook): Port to gzip implementations that
warn about nontrivial settings in the GZIP environment var.
2015-03-17 22:56:01 -07:00
Paul Eggert
4eb1484dce tar: don't suggest GZIP
* doc/tar.texi (gzip): Don't suggest using the GZIP environment
variable, as it will be deprecated in the next gzip release.
2015-03-17 10:46:51 -07:00
Sergey Poznyakoff
1847ec67ce Improve compression format recognition
Some comressed archives can pass the checksum test, which makes tar
treat them as uncompressed archives.

* src/buffer.c (check_compressed_archive): Test the checksum only
if the block we read looks like a valid tar header (i.e. has
a magic string).
2015-02-19 17:00:58 +02:00
Paul Eggert
9c2b57232e tar: port xattr-at.c to Solaris 10
* lib/xattr-at.c (setxattrat, lsetxattrat, getxattrat, lgetxattrat)
(listxattrat, llistxattrat): Compile only if HAVE_XATTRS, so that
the code doesn't call functions that are not declared.
2015-01-05 20:24:42 -08:00
Paul Eggert
55fb2fc38f tar: port wordsplit attribute to Sun C
Reported by Ted Carr in:
http://lists.gnu.org/archive/html/bug-tar/2015-01/msg00002.html
* lib/wordsplit.h (__WORDSPLIT_ATTRIBUTE_FORMAT):
New macro, taken from Gnulib.
(struct wordsplit): Use it.
* lib/wordsplit.c (_wsplt_error): Use it.
2015-01-05 20:09:09 -08:00
Sergey Poznyakoff
5a9ac8312e Silent a cc warning
* src/xheader.c (xheader_string_end): Make sure pointer
arithmetics applies on char*.
2014-12-17 08:37:14 +02:00
Paul Eggert
7bf812579c tar: port ISFOUND, WASFOUND to C89
Problem reported by Romano Maspero in:
http://lists.gnu.org/archive/html/bug-tar/2014-12/msg00010.html
* src/common.h (ISFOUND, WASFOUND): Port to C89.
2014-12-11 19:02:43 -08:00
Sergey Poznyakoff
1209e0ebff Fix tar -c -l file file
When the same file is added several times to the archive, count
correctly the number of hard links.  See also 37ddfb0b.

* src/create.c (dump_hard_link): Don't decrease nlink if it is 0.
* tests/link04.at: Test -cl options.
2014-12-10 04:34:02 +02:00
Sergey Poznyakoff
e7b6f8e3ae Honor the pax-option overrides when creating archive.
Changes proposed by Denis Excoffier.

* NEWS: Fix typos.
* doc/tar.texi: Fix typos.  Improve recipe for creation of binary
equivalent archives.
* src/create.c (write_extended): Use the value of the
--mtime option (if specified) as the default for exthdr.mtime.
* src/xheader.c (xheader_store): Create the header if at least
one override is supplied in --pax-option.
2014-11-07 13:15:54 +02:00
Sergey Poznyakoff
586a6263e9 Add testcase for the previous commit.
* tests/sparse05.at: New file.
* tests/Makefile.am: Add sparse05.at
* tests/testsuite.at: Include sparse05.at
2014-11-07 11:47:44 +02:00
Pavel Raiskup
ec94fbdf45 Fix bug in sparse file listing
List posix archives containing sparse files >8GB correctly and do not fail.
This fixes also bug in format of listing for sparse files >8GB - now the
real size is printed instead of the effective one (this is not strictly
posix format related).

* src/list.c: Remove redundant assignment.
* src/tar.h: Add new 'real_size' and 'real_size_set' fields in
  tar_stat_info struct.
* src/xheader.c: Correctly handle (especially sparse) file sizes directly in
  xheader_decode().
2014-11-07 10:21:41 +02:00
Sergey Poznyakoff
c48f4e8f6c Fix a typo 2014-10-15 14:20:07 +03:00
Sergey Poznyakoff
e7c99a4dd1 Fix README
Remove the reference to PORTS
2014-10-01 23:19:02 +03:00
Sergey Poznyakoff
e9ddc08da0 Bugfixes.
* doc/tar.1: Fix typo in font spec.
* src/tar.c (sort_mode_arg, sort_mode_flag): Protect "inode"
(SAVEDIR_SORT_INODE) with D_INO_IN_DIRENT
2014-09-25 00:22:16 +03:00
Sergey Poznyakoff
163e96a0e6 Bugfix: entries read from the -T file did not get proper matching_flag.
* src/common.h (name_add_file): Change signature.
* src/names.c (name_elt_alloc_matflags): New function.
(name_add_name): Use name_elt_alloc_matflags.
(name_add_file): Take matching flags as third argument.
(read_next_name): Remove trailing slashes.
* src/tar.c (parse_opt): Pass matching_flags to name_add_file.

* tests/T-dir00.at: New file.
* tests/T-dir01.at: New file.
* tests/Makefile.am: Add new testcases.
* tests/testsuite.at: Likewise.
2014-09-18 23:01:22 +03:00
Sergey Poznyakoff
0e0a852e91 Improve documentation.
* doc/tar.1: Document --skip-old-files and --warning=existing-file
* doc/tar.texi: Document --warning=existing-file
2014-08-16 09:42:25 +03:00
Sergey Poznyakoff
b500277de7 Version 1.28 2014-07-27 23:45:19 +03:00
Nathan Stratton Treadway
002bf86821 Minor change in docstrings.
nor ch#
2014-07-27 23:31:26 +03:00
Nathan Stratton Treadway
fcde08534b Restructure the remfiles testsuite. 2014-07-27 23:27:28 +03:00
Sergey Poznyakoff
a5db4ba5cb Don't build ttyemu and run tty I/O test if grantpt is not available.
* configure.ac (TAR_COND_GRANTPT): Define conditional depending
on whether grantpt is available.
* gnulib.modules: Remove grantpt. It relies upon a helper binary
pt_chown which it installs and which is useless in the testsuite.
* tests/Makefile.am [TAR_COND_GRANTPT]: Build ttyemu
* tests/iotty.at: Skip test if ttyemu is not build.
* tests/ttyemu.c (noecho): Fix error message
(main): Use TIOCSCTTY if it is defined.
2014-07-22 04:29:25 +03:00
Benno Schulenberg
20ab569dc3 Fix a typo and some wordings in the documentation.
* doc/tar.texi: Fix some missing articles, and make it clearer
that "any" does not mean "anything" but "either of the two".
2014-07-22 03:37:41 +03:00
Nathan Stratton Treadway
f86e0605d0 Fix the testsuite
* tests/incr07.at: Don't assume case-sensitive filesystem.
2014-07-22 03:34:20 +03:00
Paul Eggert
4423e1743e tar: minor fixups related to recent checkpoint.c change
* src/checkpoint.c (getwidth, format_checkpoint_string):
Use long and strtol, not int, to avoid overflow issues.
(getwidth): Don't assume termios.h defines TIOCGWINSZ,
as it doesn't on some older hosts.
2014-07-10 22:35:05 -07:00
Sergey Poznyakoff
8d087fbb0b Bugfixes
* gnulib.modules: Add faccessat
* src/checkpoint.c: Include termios.h
2014-07-11 08:09:30 +03:00
Nathan Stratton Treadway
dc72f4d114 tar: document xgetcwd test case better
* src/misc.c (normalize_filename): Add commentary for clarity.
* tests/extrac09.at: Retitle test case and add comments for clarity.
2014-06-28 23:57:58 -07:00
Sergey Poznyakoff
576e99a21c Fix typos in ChangeLog
* ChangeLog.CVS: Fix typos.
* ChangeLog.amend: New file.
* Makefile.am: Define changelog_amend_file.
2014-06-24 11:53:35 +03:00
Paul Eggert
fc58a8bd98 tar: do not dereference NULL pointer with '--remove-files .'
Problem reported by Thorsten Hirsch in:
http://lists.gnu.org/archive/html/bug-tar/2014-04/msg00011.html
* src/unlink.c (flush_deferred_unlinks):
Do not attempt to find the parent of "." when "." is
at the top level.
* tests/remfiles10.at: New file.
* tests/Makefile.am (TESTSUITE_AT):
* tests/testsuite.at: Add it.
2014-04-29 14:22:59 -07:00
Sergey Poznyakoff
7808b6981b Refuse to write archive contents to a tty.
* NEWS: Update.
* src/buffer.c (_open_archive): Refuse to write to a tty.
* tests/iotty.at: Test output to a tty.
2014-03-27 07:06:02 +02:00
Vitezslav Cizek
852895847f fix an eternal loop in handle_option
* src/names.c (handle_option): increment loop counter
2014-03-26 23:01:22 +02:00
Sergey Poznyakoff
b0902369e7 Fail if archive comes from a terminal.
Based on patch from Pavel Raiskup <praiskup@redhat.com>.

* gnulib.modules: Add new modules.
* src/buffer.c (_open_archive): Refuse to read archive from a tty.
* tests/Makefile.am (TESTSUITE_AT): Add iotty.at
(check_PROGRAMS): New program ttyemu
* tests/testsuite.at: Include iotty.at
* tests/iotty.at: New file.
* tests/ttyemu.c: New file.
2014-03-20 19:46:30 +02:00
Paul Eggert
da546e69af tar: port to Solaris 9
Problem reported by Jesse C in:
http://lists.gnu.org/archive/html/bug-tar/2014-03/msg00034.html
* gnulib.modules: Add strtoimax and strtoumax, since tar invokes
these functions directly and they don't exist on Solaris 9.
2014-03-12 21:02:06 -07:00
Sergey Poznyakoff
f24b30ec8c Test the --[no-]recursive options (see commit 2bd9c153_.
* tests/recurs02.at: New test case.
* tests/Makefile.am: Add new file.
* tests/testsuite.at: Add new file.
2014-02-25 10:38:06 +02:00
Sergey Poznyakoff
93906c238d Support exclusion patterns from various VCS ignore lists.
* src/Makefile.am (tar_SOURCES): Add exclist.c
* src/common.h (EXCL_DEFAULT, EXCL_RECURSIVE)
(EXCL_NON_RECURSIVE): New flags.
(excfile_add, info_attach_exclist)
(info_cleanup_exclist,info_free_exclist)
(exclude_vcs_ignores): New prototypes.
* src/create.c (dump_dir0): Call info_attach_exclist.
* src/exclist.c: New file.
* src/incremen.c (scan_directory): Call info_attach_exclist.
* src/names.c (excluded_name): Moved to exclist.c. Change signature.
All uses updated.
* src/tar.c: New options: --exclude-ignore, --exclude-ignore-recursive
and --exclude-vcs-ignores.
(tar_stat_destroy): Free exclist.
* src/tar.h (tar_stat_info): New member exclude_list.

* NEWS: Document new exclusion options.
* doc/tar.texi: Likewise.
* doc/tar.1: Likewise.
2014-02-22 08:13:30 +02:00
Sergey Poznyakoff
9df17e6005 Fix in testsuite
* acls03.at: Fix improper invocation of setfacl.
2014-02-14 13:03:58 +02:00
Pavel Raiskup
efbf4cce0b testsuite: add test for buggy default ACLs
* tests/Makefile.am: Mention acls03.at.
* tests/testsuite.at: Likewise.
* tests/acls03.at: New testcase.
2014-02-14 12:38:25 +02:00
Pavel Raiskup
7fe7adcbb9 acls: bugfix for default ACLs extraction
When --acls option is on (regardless of tarball contents or
tarball format), we should explicitly set OR delete default ACLs
for extracted directories.  Prior to this update, we always
created arbitrary default ACLs based standard file permissions.

* configure.ac (with_posix_acls): Check also for acl_free and
acl_delete_def_file to mark IEEE 1003.1e ACLs as supported.
* src/xattrs.c (acl_delete_def_file_at): New function.
(xattrs__acls_set): Do not treat acls_option at all;  Delete
default ACLs if appropriate.

References:
http://www.mail-archive.com/bug-tar@gnu.org/msg04355.html
Thanks: Juan J. Martínez and Mark Steinborn
2014-02-14 12:38:20 +02:00
Pavel Raiskup
8e10d93d01 tar: imply --xattrs when --xattrs-{inc,exc}lude used
Options --xattrs-include=MASK and --xattrs-exclude=MASK now turn
on the --xattrs option.

Fix also bug in printing in xattrs.c - don't print when option is
negative.

* src/tar.c (set_xattr_option): New static function.
(parse_opt): Call new function when --xatrrs, --xattrs-include or
--xattrs-exclude option is used.
* src/xattrs.c (xattrs_print, xattrs_print_char): Expect positive
values in options.
2014-02-14 12:32:34 +02:00
Sergey Poznyakoff
3cb4693c65 THANKS: Add Anthony G. Basile. 2014-02-14 11:02:40 +02:00
Sergey Poznyakoff
48a546b02c Use correct headers/libraries when providing xattr support
See https://savannah.gnu.org/patch/index.php?8252. Patch provided
by Anthony G. Basile.

* acinclude.m4 (TAR_HEADERS_ATTR_XATTR_H): Look for <sys/xattr.h>
first and then for <attr/xattr.h>.  Link against libattr.so if
needed.
* lib/xattr-at.h: Include sys/xattr.h or attr/xattr.h, depending
on which one is detected.
* src/Makefile.am [TAR_LIB_ATTR] (tar_LDADD): Link against -lattr.
2014-02-14 10:55:26 +02:00
Sergey Poznyakoff
46da9968df Minor change
* src/tar.c (decode_options): Silently ignore --one-top-level
if used with a non-reading command.
2014-02-14 10:44:19 +02:00
Sergey Poznyakoff
29a6964af3 New option --sort=ORDER
This option makes tar sort the entries of directories that will be
added to an archive according to ORDER (none, name, or order).

Based on proposition by Dick Streefland (https://savannah.gnu.org/patch/?7892).

* src/common.h (savedir_sort_order): New global.
* src/create.c: Pass savedir_sort_order to streamsavedir.
* src/misc.c: Likewise.
* src/tar.c: New option --sort.

* NEWS: Update.
* doc/tar.texi: Document the --sort option.
* doc/tar.1: Likewise.
2014-02-14 00:26:49 +02:00
Sergey Poznyakoff
62497f0e26 Fix the testsuite
* tests/opcomp01.at: Update expected error messages.
* tests/opcomp03.at: Likewise.
2014-02-13 23:58:35 +02:00
Sergey Poznyakoff
c86b0c2149 Fix --one-top-level used together with --list.
* src/extract.c: Move one_top_level stuff to tar.c (decode_options).
* src/tar.c (option_conflict_error): New function.
(decode_options): Use option_conflict_error to complain about
conflicting options in a uniform manner.
Process one_top_level options here.
(request_stdin): Fix error message.
* tests/onetop04.at: New testcase: check --one-top-level with --list.
* tests/Makefile.am: Add new testcase.
* tests/testsuite.at: Add new testcase.
2014-02-13 19:17:27 +02:00
Sergey Poznyakoff
8b6a1a5990 Fix NEWS
* NEWS: Remove duplicate description of the --one-top-level option.
2014-02-13 10:29:19 +02:00
Sergey Poznyakoff
8cfcbfddd4 configure.ac: look for host-prefixed ar
See https://savannah.gnu.org/patch/?8183
2014-02-12 15:07:13 +02:00
Sergey Poznyakoff
e9e94531f0 Bugfix
* src/suffix.c (find_compression_suffix): Fix eventual coredump.
2014-02-10 19:51:55 +02:00
Sergey Poznyakoff
288dd472e3 Fix docs. 2014-02-10 18:46:24 +02:00
Sergey Poznyakoff
8706301479 Update docs.
* NEWS: Document --one-top-level
* THANKS: Mention Connor Behan
2014-02-10 18:29:39 +02:00
Sergey Poznyakoff
45ccda1193 Update copyright years. 2014-01-30 13:54:15 +02:00
Sergey Poznyakoff
1689ed4388 Improve one-top-level functionality
Make sure the changes become visible with --show-transformed-names.

* src/common.h (strip_compression_suffix): New function.
(one_top_level): Rename to one_top_level_dir. All uses changed.
* src/extract.c (extr_init): Use strip_compression_suffix.
Bail out if unable to determine top-level directory.
(maybe_prepend_name): Remove. All uses removed.
* src/tar.c (options): --one-top-level takes optional argument.
(parse_opt): Handle it.
* src/list.c (enforce_one_top_level): New function.
(transform_stat_info): Call enforce_one_top_level if required.
* src/suffix.c (compression_suffixes): List "tar" (no compression);
terminate with NULL entry.
(find_compression_suffix): New static.
(strip_compression_suffix): New function.

* doc/tar.1: Update.
* doc/tar.texi: Update.

* tests/onetop01.at: New testcase.
* tests/onetop02.at: New testcase.
* tests/onetop03.at: New testcase.
* tests/Makefile.am: Add new testcases.
* tests/testsuite.at: Likewise.
2014-01-28 12:35:39 +02:00
Connor Behan
2af87fa277 Detect tarbombs while extracting
* src/common.h (one_top_level_option): New global.
(one_top_level): New global.
* src/extract.c (extr_init): If one_top_level_option is set, determine
the name one_top_level that might have to be prepended.
(extract_archive): If one_top_level_option is set, prepend one_top_level
to all names that don't already start with it.
* src/tar.c (ONE_TOP_LEVEL_OPTION): New contant.
(options): New option --one-top-level.
(parse_opt): Handle this option.
(decode_options): Make it conflict with --absolute-names.
2014-01-27 14:42:09 +02:00
Sergey Poznyakoff
95a51b93d0 Don't install rmt.8 if rmt is not built.
* doc/Makefile.am [PU_RMT_COND]: Define RMT_8
(dist_man_MANS): use RMT_8 instead of the hardcoded rmt.8
2014-01-27 14:32:46 +02:00
Sergey Poznyakoff
f504821589 Provide tar(1) and rmt(8) manpages.
* NEWS: Update.
* doc/Makefile.am: Add manpages.
* doc/tar.1: New file.

* src/tar.c (tar_help_filter): Handle LZOP_OPTION.
2014-01-27 13:20:11 +02:00
Sergey Poznyakoff
a09e840507 Make sure transformed file names retain trailing slash in listing.
* src/list.c (simple_print_header): Print trailing slash
if using the transformed name.
Use had_trailing_slash instead of analyzing last byte if temp_name
2014-01-23 18:04:36 +02:00
Sergey Poznyakoff
eb7e2aa933 checkpoint actions: further improvements.
* NEWS: Update.
* doc/tar.texi: Update.
* src/buffer.c (print_stats): Avoid use of additional string buffer.
Allow for text to be NULL.
Call gettext if it is not.
(format_total_stats): Don't use gettext when calling print_stats.
* src/checkpoint.c (def_format): Change default format.
(format_checkpoint_string): Implement optional arguments for
T conversion.
(finish_checkpoint_actions): Rename to checkpoint_flush_actions,
make extern.  All uses changed.
* src/common.h (checkpoint_flush_actions): New proto.
* src/tar.c (main): Set error_hook
2014-01-22 17:35:43 +02:00
Sergey Poznyakoff
717a07e208 Improve checkpoint interface.
* src/buffer.c (format_total_stats): The format arg is const
All uses updated.
(default_total_format): const
* src/checkpoint.c (tty, tty_cleanup): New static.
(format_checkpoint_string): New "canned" format %c
(checkpoint_finish): New function.
* src/common.h (checkpoint_finish): New proto.
* src/tar.c (main): Call checkpoint_finish.`
2014-01-22 07:28:02 +02:00
Sergey Poznyakoff
f0a1f78196 Implement statistics display in checkpoint actions.
* NEWS: Update.
* configure.ac: Version 1.27.90
* gnulib.modules: Add fprintftime.
* doc/tar.texi: Document the "totals" action and new format specifiers
for echo and ttyout checkpoint actions.
* src/buffer.c (compute_duration): Return computed value.
(print_stats): Don't print trailing newline.  Return number of
characters output.
(format_total_stats): New function.
(print_total_stats): Rewrite via format_total_stats.
* src/checkpoint.c (checkpoint_opcode) <cop_totals>: New opcode.
(checkpoint_compile_action): Handle cop_totals.
(expand_checkpoint_string): Remove.
(format_checkpoint_string): New function to be used instead of
expand_checkpoint_string.  All callers updated.
* src/common.h (TF_READ,TF_WRITE)
(TF_DELETED): New constants.
(format_total_stats,print_total_stats): New protos.
2014-01-21 17:57:46 +02:00
Sergey Poznyakoff
7f21a4d3f5 Remove shar archives from distribution.
These are going to phase out in automake 2.0
2014-01-10 11:37:50 +02:00
Sergey Poznyakoff
2bd9c15391 Fix the use of --no-recursion and --recursion options.
Each option remains in effect until cancelled by the next ocurrence
of its counterpart, as stated in the documentation.

* src/names.c (name_next_elt): Restore recursion_option from the
value of matching_flags.
2014-01-10 00:14:53 +02:00
Sergey Poznyakoff
481572c63f Minor bugfixes
* src/compare.c (diff_dumpdir): Close descriptor if fstat failed.
(diff_multivol): Make sure the descriptor is closed and eventual
errors reported if lseek fails.
Both reported by Jiri Kukacka.
2014-01-09 17:24:21 +02:00
Paul Eggert
47da28892e tar: work aruond IBM XL C bug
* src/incremen.c (show_snapshot_field_ranges)
(write_directory_file_entry): Use simpler array size expression,
one that evaluates to the same value.  This works around a compiler
bug with IBM XL C.  Problem reported by Yannick Bergeron in
<http://lists.gnu.org/archive/html/bug-tar/2014-01/msg00009.html>.
2014-01-07 11:16:23 -08:00
Paul Eggert
5c5f62e0dc tar: update ancient configure cruft
* configure.ac: Use AC_PROG_CC_STDC, not just AC_PROG_CC.
Remove obsolete macros AC_ISC_POSIX, AC_HEADER_SYS_WAIT,
AC_HEADER_DIRENT, AC_HEADER_STAT, AC_HEADER_STDC, AC_TYPE_SIGNAL,
AC_TYPE_SIZE_T.
* lib/prepargs.c (IN_CTYPE_DOMAIN): Remove.  All uses removed.
* src/list.c (from_header): Use isspace, not ISSPACE.
* src/system.c (pipe_handler, sys_exec_info_script):
* src/tar.c (sigstat):
Use void, not RETSIGTYPE.
2014-01-03 11:48:57 -08:00
Sergey Poznyakoff
49f3145092 Version 1.27.1 2013-11-17 18:37:50 +02:00
Sergey Poznyakoff
ca8cb48d02 Fix star compatibility (sparse headers)
* src/sparse.c (star_get_sparse_info): Update file->dumped_size
2013-11-17 17:35:01 +02:00
Sergey Poznyakoff
b4afdd0e28 Fix GNU long link header.
* src/create.c (write_gnu_long_link): Set timestamp to
0 for backward compatibility.  Bug reported by David Barri.
* THANKS: Update.
2013-11-17 17:31:41 +02:00
Sergey Poznyakoff
6e8bca8b56 Fix unquoting of input file names.
* src/names.c (read_next_name): Unquote file names coming from the
-T argument.  Bug reported by Nicolas Dudebout.
* THANKS: Update.
2013-11-17 17:27:53 +02:00
Paul Eggert
00054440c7 build: fix bug where 'configure --with-posix-acls' disables ACLs
Reported by Lars Wendler in
<http://lists.gnu.org/archive/html/bug-tar/2013-10/msg00022.html>.
* configure.ac (with_posix_acls): Fix typo.
2013-10-23 18:38:56 -07:00
Paul Eggert
a2e0cd0c05 Fix core dump on Solaris 10 when "." isn't readable.
Reported by Peter Kruse in
<http://lists.gnu.org/archive/html/bug-tar/2013-10/msg00017.html>.
This doesn't fix all the Solaris 10 test failures, just the core dump.
* src/common.h, src/misc.c (tar_getcdpath): Now static.
* src/misc.c (normalize_filename): Report a fatal error
if cdpath is null, since we don't know the absolute name
of the working directory in that case.  FIXME: there should
be no need to know absolute file names.
(chdir_arg): Simplify wd allocation.
Don't assume that xgetcwd returns non-null.
2013-10-22 19:17:23 -07:00
Sergey Poznyakoff
f6c25db5fe Version 1.27
* NEWS: Update.
* configure.ac: Update.
2013-10-06 00:02:17 +03:00
Sergey Poznyakoff
6d5cfeb757 Minor fixes.
* src/names.c: Include argp.h
* tests/testsuite.at (AT_XATTRS_UTILS_PREREQ)
(AT_SELINUX_UTILS_PREREQ,AT_ACLS_UTILS_PREREQ)
(AT_CAPABILITIES_UTILS_PREREQ)
(AT_XATTRS_PREREQ,AT_SELINUX_PREREQ)
(AT_ACLS_PREREQ): Use POSIX-compatible syntax for
mktemp.
* tests/incr08.at: Fix find usage.
2013-10-06 00:01:32 +03:00
Sergey Poznyakoff
3de5db2a15 Xfail the remfiles09b test.
* tests/remfiles09b.at: Turn into expected failure.
2013-10-05 09:29:55 +03:00
Nathan Stratton Treadway
db9b81eb6b Tiny change
* scripts/tar-snapshot-edit: Mention --show-snapshot-field-ranges option
2013-10-05 09:28:52 +03:00
Pavel Raiskup
f3c8bc7c3f Tiny change
* configure.ac (RSH): Define as AC_ARG_VAR.
2013-10-05 09:26:52 +03:00
Sergey Poznyakoff
576e1fcd6a Fix namespace contamination in testsuite.
* tests/append01.at: Use m4_pushdef/m4_popdef to define local macros.
* tests/delete03.at: Likewise.
* tests/exclude06.at: Likewise.
* tests/incr04.at: Likewise.
* tests/link03.at: Likewise.
* tests/long01.at: Likewise.
* tests/longv7.at: Likewise.
* tests/lustar01.at: Likewise.
* tests/lustar02.at: Likewise.
* tests/lustar03.at: Likewise.
* tests/multiv05.at: Likewise.
* tests/sparse04.at: Likewise.
2013-10-05 09:10:35 +03:00
Nathan Stratton Treadway
3125d311e1 Provide comprehensive testcases for various file removal modes.
* tests/Makefile.am: Add new testcases.
* tests/testsuite.at: Likewise.
* tests/incr09.at: Add description.
* tests/remfiles04a.at: New file.
* tests/remfiles05.at: Rename to ...
* tests/remfiles04b.at: ... this.
* tests/remfiles04.at: Rename to ...
* tests/remfiles04c.at: ... this.
* tests/remfiles05a.at: New file.
* tests/remfiles05b.at: New file.
* tests/remfiles06.at: Rename to ...
* tests/remfiles05c.at: ... this.
* tests/remfiles06a.at: New file.
* tests/remfiles06b.at: New file.
* tests/remfiles06c.at: New file.
* tests/remfiles07a.at: New file.
* tests/remfiles07b.at: New file.
* tests/remfiles07c.at: New file.
* tests/remfiles08a.at: New file.
* tests/remfiles08b.at: New file.
* tests/remfiles08c.at: New file.
* tests/remfiles08.at: Rename to ...
* tests/remfiles09a.at: ... this.
* tests/remfiles09b.at: New file.
* tests/remfiles07.at: Rename to ...
* tests/remfiles09c.at: ... this.
2013-10-05 08:57:42 +03:00
Sergey Poznyakoff
74ce228f6d Tiny changes.
* src/misc.c: Fix comments, rename wd.cwd to wd.abspath (Nathan Stratton
Treadway);
* src/tar.c (options): Reword description of the --starting-file and
--preserve-order options.
(decode_options): Both --starting-file and --preserve-order have meaning
only when used together with an archive reading command. (Pavel Raiskup).
2013-10-03 22:41:04 +03:00
Sergey Poznyakoff
d28eee6b4f Revamp tar_getcwd/normalize_filename stuff.
The changes are based on the discussion with Nathan.

* src/common.h (normalize_filename): Take two arguments. All
callers updated.
(tar_getcwd): Replaced with ..
(tar_getcdpath): New proto.
* src/misc.c (normalize_filename): Take two arguments.
(chdir_arg): Populate cwd along with creating the
structure.
(tar_getcwd): Removed.
(tar_getcdpath): New function.

* tests/incr09.at: New test case.
* tests/Makefile.am: Add new tests.
* tests/testsuite.at: Likewise.
2013-10-01 21:48:30 +03:00
Sergey Poznyakoff
d3fd92c6fb Bugfix
* tests/remfiles08.at: Restore missing find
2013-09-27 00:59:49 +03:00
Sergey Poznyakoff
f7077dd38b Use relative addressing in deferred unlinks.
* src/common.h (tar_dirname): New function.
* src/misc.c (normalize_filename_x): Make extern.
(tar_dirname): New function.
(tar_getcwd): Take into account absoulte pathnames.
* src/unlink.c (deferred_unlink) <dir_idx>: New member; keeps the
value of chdir_current at the moment of structure allocation.
(flush_deferred_unlinks): Use chdir_do and relative addressing.
(queue_deferred_unlink): Initialize dir_idx.
* tests/Makefile.am: Add new tests.
* tests/testsuite.at: Add new tests.
* tests/remfiles06.at: Fix description.
* tests/remfiles07.at: Fix description.
* tests/remfiles08.at: New test case.
2013-09-26 15:46:44 +03:00
Nathan Stratton Treadway
5cb79ed519 Improve tar-snapshot-edit
Support architecture-specific field ranges for the "-c" function.
Better handle negative or larger-than-32-bit field values even
when running in 32-bit Perl (for the default "print a summary"
function)
2013-09-25 18:02:05 +03:00
Sergey Poznyakoff
b41b004638 Improve tar_getcwd
* src/common.h (tar_getcwd): Return pointer is const.
* src/misc.c (wd) <cwd>: New member.
(chdir_arg): Initialize cwd.
(tar_getcwd): Use cwd member to cache the result.  Take into
account absolute pathnames,
(normalize_filename): Don't free the value
returned from tar_getcwd.
* src/names.c (name_next_elt): Remove leftover call chdir().
* tests/Makefile.am: Add new tests.
* tests/testsuite.at: Likewise.

* tests/incr08.at: New testcase.
* tests/remfiles04.at: New testcase.
* tests/remfiles05.at: New testcase.
* tests/remfiles06.at: New testcase.
* tests/remfiles07.at: New testcase.
2013-09-25 16:04:21 +03:00
Sergey Poznyakoff
e3d28d84bd Fix normalize_filename.
The function did not take into account eventual -C options, which
in particular led to various problems when using -C and --remove-files
together.

* src/common.h (namebuf_add_dir,namebuf_finish)
(tar_getcwd): New prototypes.
* src/misc.c (namebuf_add_dir,namebuf_finish)
(tar_getcwd): New functions.
(normalize_filename): Use tar_getcwd.
2013-09-24 14:01:13 +03:00
Sergey Poznyakoff
2c06a80918 Changes for compatibility with Slackware installation scripts.
* src/buffer.c (short_read): the "Record size" message
is controlled by the WARN_RECORD_SIZE warning_option bit.
* src/common.h (keep_directory_symlink_option): New global.
(WARN_RECORD_SIZE): New constant.
(WARN_VERBOSE_WARNINGS): Add WARN_RECORD_SIZE.
* src/extract.c (extract_dir): If keep_directory_symlink_option is
set, follow symlinks to directories.
* src/suffix.c (compression_suffixes): Add support for txz
suffix.
* src/tar.c (KEEP_DIRECTORY_SYMLINK_OPTION): New constant.
(options): New option --keep-directory-symlink.
(parse_opt): Handle this option.
* src/warning.c: Implement "record-size" warning control.

* NEWS: Update.
* doc/tar.texi: Document new features.
2013-09-23 19:35:29 +03:00
Sergey Poznyakoff
570a2c5f3d Fix error message (complements 0ea6e686)
* src/tar.c (set_subcommand_option): Mention --delete in the error message.
2013-09-21 15:08:24 +03:00
Sergey Poznyakoff
b6979c7278 Improve the incr07 test 2013-09-15 20:38:57 +03:00
Nathan Stratton Treadway
751b61ab25 Implement the --show-snapshot-field-ranges option
* src/common.h (show_snapshot_field_ranges): New prototype.
* src/incremen.c (show_snapshot_field_ranges): New function.
* src/tar.c: New option --show-snapshot-field-ranges.
* doc/snapshot.texi: Document the --show-snapshot-field-ranges
option.
* doc/tar.texi: Likewise.
2013-09-15 16:02:30 +03:00
Sergey Poznyakoff
738fb9c2f4 Take into account chdir_fd when extracting from incremental dumps.
* src/common.h (tar_savedir): New prototype.
* src/misc.c (tar_savedir): New function.
(remove_any_file): Use tar_savedir.
* src/incremen.c (try_purge_directory): Use tar_savedir.
* src/update.c (update_archive): Use tar_savedir.
* tests/incr07.at: New testcase.
* tests/Makefile.am (TESTSUITE_AT): Add new test.
* tests/testsuite.at: Likewise.
* THANKS: Updated.
2013-09-15 10:13:45 +03:00
Sergey Poznyakoff
0ea6e68655 Minor fix
* src/tar.c (main): Mention --delete in the error message.
* THANKS: Update
2013-09-15 09:00:46 +03:00
Paul Eggert
dd549cc257 * src/names.c (file_list_name): Properly prototype. 2013-09-13 11:10:39 -07:00
Paul Eggert
28b44aaacb tar: don't warn about zero timestamps
* src/extract.c (check_time): Suppress warniing when t.tv_sec == 0.
Problem reported by Denis Excoffier.
2013-09-13 11:10:39 -07:00
Pavel Raiskup
88cb5008a6 Minor fix in the testsuite.
* tests/T-cd.at: sort the 'tar cf' output.
2013-08-19 14:26:18 +03:00
Sergey Poznyakoff
bff9c3637d Improve error diagnostics
* src/names.c (file_list_name): New static function.
(add_file_id): If a filelist is being read twice, print the names
of the files that caused it.
* tests/T-rec.at: New test case.
* tests/Makefile.am: Add new file.
* tests/testsuite.at: Include new file.
2013-08-17 13:48:24 +03:00
Sergey Poznyakoff
1fe0c83de4 Revamp initial name collection functions to ensure proper argument ordering.
* src/names.c (NELT_NOOP): New constant
(name_elt) <next,prev>: New members.
(name_array,allocated_entries,entries,scanned): Remove.
(check_name_alloc): Remove function.
(name_elt_alloc): New static.
(name_list_adjust,name_list_advance): New functions.
(name_add_name,name_add_dir)
(name_add_file): Use new allocation functions.
(read_next_name): Advance list head pointer as necessary
before returning.
(name_next_elt): Read elements from list.
* tests/T-cd.at: New file.
* tests/T-mult.at: New file.
* tests/T-nest.at: New file.
* tests/Makefile.am: Add new testcases.
* tests/testsuite.at: Likewise.
2013-08-16 23:03:35 +03:00
Sergey Poznyakoff
077d7bceff Don't treat attempts to read an already read file list as fatal errors.
* src/names.c (add_file_id): Report error and return 1 if the file
has already been read.
(read_next_name): Don't try to open file if add_file_id returns 1.
(name_next_elt): Simplify conditional.
2013-08-16 15:17:22 +03:00
Sergey Poznyakoff
162bbcb45f Minor change.
* src/names.c (name_next_elt): Simplify conditional.
2013-08-16 14:29:51 +03:00
Pavel Raiskup
69007e652a Fix use of uninitialized memory
* src/names.c (name_add_file): Initialize the ep->v.file.fp pointer
after structure allocation.
2013-08-15 13:56:04 +03:00
Sergey Poznyakoff
95d7b37a34 Minor changes
* src/names.c (handle_option): Use program_invocation_short_name
instead of the constant string.
(read_next_name): Remove unused variable.
2013-08-05 15:14:08 +03:00
Sergey Poznyakoff
ddff3e9038 Update the docs.
* doc/tar.texi: Parsing of the options found in the file list
follows the same rules as for command line.  Remove the obsolete
description.  This complements 26538c9b.
2013-08-04 19:40:11 +03:00
Sergey Poznyakoff
47560a0498 Fix interacton of --verbose and --append.
* src/buffer.c (_open_archive): don't overwrite existing archive
if given the --verify option.
* tests/append04.at: New file.
* tests/Makefile.am: Add new testcase.
* tests/testsuite.at: Add new testcase.
* THANKS: Update.
2013-08-04 19:00:46 +03:00
Sergey Poznyakoff
6e5e4420f4 Bugfix.
* src/names.c (read_name_from_file): Fix a typo. Remove
unused variable.
2013-08-04 18:45:15 +03:00
Sergey Poznyakoff
26538c9bfc Reduce memory consuption when handling the -T option.
The commit cdb27293 made the -T option more flexible, but
incurred a very considerable memory overhead by storing
all file names in the argument array.  In case of very
big file lists this caused tar to run out of memory.  This
was reported by Christian Wetzel <wetzel@phoenix-pacs.de>
on March 14, 2013
(http://lists.gnu.org/archive/html/bug-tar/2013-03/msg00018.html).

On the other hand, Michal Žeidl discovered that tar misfunctioned
when given empty file lists or lists with the trailing newline
misssing in the last entry.  This was reported by Pavel Raiskup
on July 23
(http://lists.gnu.org/archive/html/bug-tar/2013-07/msg00009.html and
msg00010.html).

This change fixes both issues.

* src/common.h (name_add_file,request_stdin): New prototype.
(more_options): New prototype.
* src/names.c (NELT_FILE): New entry type.
(name_elt) <file>: New union member.
(name_add_file): New function.
(read_name_from_file): New function, a rewrite of
the same function from tar.c
(read_next_name,copy_name): New static functions.
(name_next_elt): Handle NELT_FILE entries.
* src/tar.c (request_stdin): Make extern.
(read_name_from_file,add_file_id)
(update_argv): Removed.
(parse_opt): Change handling of the -T option.
(more_options): New function.

* tests/T-null.at: Rewrite test.
* tests/T-zfile.at: New file.
* tests/T-nonl.at: New file.
* tests/Makefile.am: Add new testcases.
* tests/testsuite.at: Likewise.

* THANKS: Update.
2013-08-04 18:22:02 +03:00
Sergey Poznyakoff
8a834dfa10 Fix the compatibility check for the --occurrence option.
* src/tar.c (SUBCL_OCCUR): New class.
(subcommand_class): Update.
(decode_options): Accept the --occurrence option
with any subcommand from the SUBCL_OCCUR class.
2013-06-29 15:05:21 +03:00
Pavel Raiskup
cf199be81d testsuite: do not resist on file order in archive
On my Fedora 19 box, the exclude08 & exclude11 tests failed before
this fix.  The reason was that the directory traversing chosen the
file order differently than the testsuite expected.

* tests/exclude08.at: Sort the tarball content output.
* tests/exclude09.at: Likewise.
* tests/exclude10.at: Likewise.
* tests/exclude11.at: Likewise.
* tests/exclude12.at: Likewise.
* tests/exclude13.at: Likewise.
* tests/exclude14.at: Likewise.
* tests/exclude15.at: Likewise.
* tests/exclude16.at: Likewise.
2013-06-29 10:45:45 +03:00
Sergey Poznyakoff
cfebb3cedf Improve checks for incompatible options.
* src/common.h (READ_LIKE_SUBCOMMAND): Remove define.
* src/tar.c (IS_SUBCOMMAND_CLASS): New macro.
(decode_options): Use IS_SUBCOMMAND_CLASS in checking
option compatibility.
Accept the --verify option only with subcommands that
write to the archive.

* tests/opcomp01.at: New test case.
* tests/opcomp02.at: New test case.
* tests/opcomp03.at: New test case.
* tests/opcomp04.at: New test case.
* tests/opcomp05.at: New test case.
* tests/opcomp06.at: New test case.
* tests/Makefile.am: Add new testcases.
* tests/testsuite.at: Likewise.
2013-06-29 10:38:47 +03:00
Paul Eggert
87369861f9 tar: port to Mingw Shell
* src/extract.c (extract_symlink) [!HAVE_SYMLINK]:
Fix typo by replacing WARN_SYMBOLIC_CAST with WARN_SYMLINK_CAST.
Problem reported by kaka in
<http://lists.gnu.org/archive/html/bug-tar/2013-06/msg00008.html>.
2013-06-27 22:33:26 -07:00
Paul Eggert
f547c0332d maint: revert previous change
It wasn't actually needed.  Reported by Stefano Lattarini in
<http://lists.gnu.org/archive/html/bug-tar/2013-04/msg00041.html>.
* configure.ac (AM_GNU_GETTEXT_VERSION): Decrease from 0.18.2 back to 0.16.
2013-05-06 06:23:28 -07:00
Paul Eggert
57e5a7a1e7 maint: port to bleeding-edge Automake by assuming Gettext 0.18.2
Reported by Stefano Lattarini in
<http://lists.gnu.org/archive/html/bug-tar/2013-04/msg00009.html>.
* configure.ac (AM_GNU_GETTEXT_VERSION): Increase from 0.16 to 0.18.2.
README-alpha says that we do not make any efforts to accommodate
older versions of Gettext.
2013-04-24 21:22:23 -07:00
Paul Eggert
f678e47eb0 tar: port to --without-xattrs --enable-gcc-warnings
Reported by Pavel Raiskup in
<http://lists.gnu.org/archive/html/bug-tar/2013-03/msg00029.html>.
* src/xattrs.c (xattrs__fd_set) [!HAVE_XATTRS]: Omit.
2013-04-24 21:06:54 -07:00
Paul Eggert
f92cb1fe16 doc: port to texinfo 5
* doc/tar.texi (Reports, assumptions, Mixing):
Put FIXMEs at line start.
2013-04-24 18:44:18 -07:00
Sergey Poznyakoff
beca89bccb Continue extracting from a separate volume after skipping a partial member.
Reported by Göran Udeborg on 2013-03-09.

* src/extract.c (extract_skip): New function.
(prepare_to_extract): Set extractor to extract_skip if starting
at a partial member.
2013-03-12 23:19:39 +02:00
Sergey Poznyakoff
a40e565719 Fix interaction of various --exclude-tag options with --listed-incremental.
* src/incremen.c (procdir): Set directory->tagfile in
the exclusion_tag_contents case.
(makedumpdir): Mark all entries as ignored if directory->tagfile
is set.
Free new_dump before returning.
(maketagdumpdir): New function.
(scan_directory): If directory->children is set to
NO_CHILDREN and directory->tagfile is set, create a
dumpdir consisting of the tagfile only.

* tests/exclude08.at: New testcase.
* tests/exclude09.at: New testcase.
* tests/exclude10.at: New testcase.
* tests/exclude11.at: New testcase.
* tests/exclude12.at: New testcase.
* tests/exclude13.at: New testcase.
* tests/exclude14.at: New testcase.
* tests/exclude15.at: New testcase.
* tests/exclude16.at: New testcase.
* tests/Makefile.am: Add new tests.
* tests/testsuite.at: Include new tests.
* tests/atlocal.in (mkexcltest): New function.
* tests/chtype.at: Update keywords.
* tests/filerem01.at: Likewise.
* tests/filerem02.at: Likewise.
* tests/incremental.at: Likewise.
* tests/multiv04.at: Likewise.
2013-03-12 23:08:53 +02:00
Paul Eggert
17f99bc6f1 tar: remove lint
* lib/wordsplit.c (_wsplit_error): Mark with printf attribute.
(expvar): "Use" defstr to pacify GCC.
* src/system.c (xexec): Now _Noreturn, to pacify GCC.
(run_decompress_program): Add cast to pacify GCC.
(sys_exec_command, sys_exec_info_script, sys_exec_checkpoint_script):
Remove unused variables.
2013-02-20 08:10:10 -08:00
Sergey Poznyakoff
7b5e803963 Pass command line arguments to external commands.
Any option taking a command name as its argument accepts
additional arguments as well.

* lib/wordsplit.c: New file.
* lib/wordsplit.h: New file.
* lib/Makefile.am: Add new files.
* src/system.c (xexec): New function.
(run_decompress_program): Use wordsplit.
(sys_child_open_for_compress,sys_exec_command)
(sys_exec_info_script)
(sys_exec_checkpoint_script): Use xexec to invoke external
command.

* NEWS: Update.
* doc/tar.texi: Update.
2013-02-10 14:43:43 +02:00
Nathan Stratton Treadway
20dcc4d122 tar: improve compile-time diagnostics
* src/misc.c (sysinttostr, strtosysint): Improve #error wording.
2013-01-28 22:49:08 -08:00
Paul Eggert
9cf743abf8 tar: improve quality of diagnostics with incrementals
Inspired by a prototype by Nathan Stratton Treadway in
<http://lists.gnu.org/archive/html/bug-tar/2013-01/msg00000.html>.
* src/incremen.c (read_num): Rewrite by merging read_negative_num
and read_unsigned_num.  Use strtosysint rather than rolling this
stuff ourselves.  Change return type to bool.  All uses changed.
(read_negative_num, read_unsigned_num): Remove.
(read_num, read_timespec, read_incr_db_2): Improve quality of
diagnostics, e.g., by supplying byte offset of error.
2013-01-27 08:42:06 -08:00
Paul Eggert
2f6c03cba2 tar: fix bug with sparse files with effective size of 8 GiB or more
Reported by Pavel Raiskup in
<http://lists.gnu.org/archive/html/bug-tar/2013-01/msg00001.html>.
* NEWS: Document the fix.
* src/sparse.c (pax_start_header): New function.
(pax_dump_header_0, pax_dump_header_1): Use it.
2013-01-26 09:54:02 -08:00
Paul Eggert
cd7bdd4076 maint: update copyrights for 2013 and as per current GNU standards 2012-12-31 13:17:15 -08:00
Paul Eggert
d99ecd6c75 maint: remove unnecessary file
* src/configure.in: Remove.  This file has been obsolete for a while.
2012-12-31 13:17:06 -08:00
Paul Eggert
53358983eb maint: don't enable warnings by default unless GCC 4.6 or later
* configure.ac (gl_GCC_VERSION_IFELSE): New macro, from coreutils.
(gl_gcc_warnings): By default, disable warnings for GCC versions
before 4.6.  This works around a failure when building from git on
Ubuntu 10, reported privately by Nathan Stratton Treadway.
2012-12-23 17:11:05 -08:00
Paul Eggert
7c43775f4f Handle incremental format 2 with negative numbers, too.
* src/incremen.c (read_unsigned_num): Last arg is intmax_t *, not
uintmax_t, for consistency with other readers.  All callers changed.
Avoid signed integer overflow.
(read_num):
2012-12-22 22:28:04 -08:00
Paul Eggert
df7b55a8f6 Fix some problems with negative and out-of-range integers.
Original problem reported for HP-UX LVM v2.2 by Michael White in
<http://lists.gnu.org/archive/html/bug-tar/2012-10/msg00000.html>.
This patch fixes some other gotchas that I noticed.
* gnulib.modules: Add extern-inline.
* src/common.h: Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END.
(COMMON_INLINE, max, min): New macros.
(represent_uintmax, valid_timespec): New inline functions.
(SYSINT_BUFSIZE): New constant.
(sysinttostr, strtosysint, decode_timespec): New decls.
* src/create.c (start_private_header): Silently bring the time_t
value into range; it is now the caller's responsibility to deal
with any overflow error.  Use uid 0 and gid 0 rather than the
user's uid/gid, since the faked header isn't "owned" by the user
and the uid/gid could in theory be out of range.  Leave major and
minor zeroed.
(FILL): Remove.
(write_gnu_long_link): Let start_private_header zero things out.
* src/create.c (write_gnu_long_link, write_extended):
* src/xheader.c (xheader_write_global):
Use start_time, not current time; no point hammering on the clock.
* src/compare.c (diff_multivol): Check that offset, size are in range.
* src/incremen.c (read_incr_db_01, write_directory_file_entry):
Allow negative time_t, dev_t, and ino_t.
* src/list.c (max): Remove (moved to common.h).
(read_header): Check that size is in range.
(from_header): Return intmax_t, not uintmax_t, to allow negative.
All callers changed.  At compile time, check assumptions about
intmax_t and uintmax_t.  Use bool for booleans.  Avoid overflow
hassles on picky hosts.
(mode_from_header): Last arg is now bool *, not unsigned *.
All callers changed.
(simple_print_header): Do not assume UID, GID fit in 'long'.
* src/list.c (from_header):
* src/xheader.c (out_of_range_header):
Arg is now a plain minimum value, not minus minval converted to
uintmax_t.  All callers changed.
* src/misc.c (COMMON_INLINE): New macro.
(sysinttostr, strtosysint, decode_timespec): New functions.
* src/sparse.c (oldgnu_add_sparse, oldgnu_fixup_header)
(star_fixup_header):
Check for offset overflow.
(decode_num): Clear errno before calling strtoumax.
* src/tar.c (expand_pax_option): Don't discard nanoseconds.
* src/xheader.c (assign_time_option): Allow negative time_t.
(decode_record): Simplify, since out-of-range string is guaranteed
to produce a value exceeding len_max.
(xheader_read): Last arg is off_t, not size_t.
Caller should diagnose negative arg, as needed.
Check that it's in range.
(enum decode_time_status): Remove.
(_decode_time): Remove, folding into decode_time.
(decode_time): Return bool, not enum decode_time_status.
Rely on decode_timespec to do most of the work.
(code_signed_num): New function.
(code_num): Use it.
(decode_signed_num): New function.
(decode_num): Use it.
(gid_coder, gid_decoder, uid_coder, uid_decoder, sparse_map_decoder)
(sparse_map_decoder): Code and decode negative values.
(sparse_map_decoder): Improve check for out-of-range values.
* tests/time01.at: New file.
* tests/Makefile.am (TESTSUITE_AT): Add it.
* tests/testsuite.at: Include it.
2012-12-22 20:41:52 -08:00
Paul Eggert
d8ac237663 Port use of mkdirat etc. to Solaris 10.
* gnulib.modules (fchmodat, fchownat, fstatat, mkdirat, unlinkat):
Add.  These were split out in gnulib, so we now need to request
them separately.  mkdirat, for example, is not in Solaris 10.
2012-12-22 13:25:39 -08:00
Paul Eggert
f39eadac4b Port ACL configuration to Solaris 10.
* configure.ac (with_posix_acls): Fix misspellings.
Stop checking at the first failure, to speed up 'configure'.
2012-12-22 13:25:33 -08:00
Paul Eggert
8ebbef8a15 tar: remove unused externs, or make them static
* src/buffer.c (record_buffer_aligned, flush_write_ptr, flush_read_ptr)
(duration):
* src/list.c (recent_global_header):
* src/unlink.c (deferred_unlink_delay):
* src/transform.c (transform_flags):
* src/xattrs.c (acl_get_file_at, acl_set_file_at, file_has_acl_at):
Now static.
* src/common.h (rmt_command_option): Remove; unused.
* src/tar.c (check_links_option, allocated_archive_names):
Move decls here from common.h; these are now static.
2012-12-19 12:34:24 -08:00
Paul Eggert
616e421350 * .gitignore: Regenerate. 2012-12-19 12:34:19 -08:00
Paul Eggert
cbc51277aa build: new configure option --enable-gcc-warnings
This has a similar meaning as in other GNU applications
such as coreutils and Emacs.
* NEWS: Document it.
* .gitignore: Remove redundant build-aux.
Remove gnu, since gnu/Makefile.am is now in git.
Add gnu/.gitignore, gnu/charset.alias, gnu/*.h, gnu/*/ to cover
autogenerated files.
* bootstrap.conf (gnulib_mk): Remove.
* configure.ac: Add support for --enable-gcc-warnings,
taken from coreutils and simplified.
* gnu/Makefile.am: New file.  Formerly this was autogenerated,
but the autogenerated file has been renamed to gnulib.mk,
its usual name when bootstrapping from gnulib.
This way, AM_CFLAGS can incorporate warning options.
* gnulib.modules: Add manywarnings.
* lib/Makefile.am, src/Makefile.am (AM_CFLAGS): New macro,
incorporating warning options.
* lib/attr-xattr.in.h (ENOATTR): New macro, if not already defined.
* src/buffer.c (magic): Don't rely on incomplete initializers.
* src/common.h (report_difference): Add printf format attribute.
* src/system.c (sys_exec_command, sys_exec_info_script)
(sys_exec_checkpoint_script):
* src/tar.c (update_argv):
Add casts to char * to pacify GCC warnings about using string
literals in a char * context.
* src/xattrs.c, src/xattrs.h (xattrs_clear_setup):
Declare parameters as (void), not ().
* src/xheader.c (xheader_format_name): Initialize pptr to null,
to pacify GCC.  Remove unnecessary test of nptr versus null.
2012-12-18 20:37:03 -08:00
Paul Eggert
8c0146d2c9 tar: don't truncate diagnostic
* src/list.c (from_header): Fix buffer size calculation when
generating a diagnostic.
2012-12-18 20:36:57 -08:00
Sergey Poznyakoff
4bfa82acd5 Bugfix.
* tests/Makefile.am: Fix double AM_CPPFLAGS
2012-12-03 23:54:19 +02:00
Sergey Poznyakoff
d350b509c0 Use AM_CPPFLAGS instead of INCLUDES. 2012-12-01 19:07:47 +02:00
Sergey Poznyakoff
383701a590 Housekeeping.
* NEWS: Mention the support for POSIX ACLs, extended
attributes and SELinux context.
* THANKS: List James Antill and Pavel Raiskup.
2012-11-19 23:51:09 +02:00
Sergey Poznyakoff
545e4cd69d Fix indentation. 2012-11-19 23:29:55 +02:00
Pavel Raiskup
a974e9c997 Allow to store/extract '=' character in xattr keyword
* src/xheader.c (xattr_decode_keyword)
(xattr_encode_keyword): New functions.
(xheader_print_n,xattr_decoder): Use them.
* tests/xattr05.at: New test case.
* tests/Makefile.am: Add new test case.
* tests/testsuite.at: Likewise.
2012-11-19 23:25:49 +02:00
Pavel Raiskup
4a3564fe85 Bugfixes.
* configure.ac: Avoid linking against -lacl when
--without-posix-acls is given.
* tests/selacl01.at: Call restorecon
* tests/selnx01.at: Likewise.
* tests/testsuite.at (AT_SELINUX_UTILS_PREREQ): Likewise.
(AT_SELINUX_PREREQ,AT_ACLS_PREREQ): Use the right _PREREQ macros.
2012-11-19 23:08:04 +02:00
Pavel Raiskup
6bd463c97e Fix bootstrapping.
* bootstrap (gnulib_extra_files): Remove $build_aux/missing
2012-11-19 22:54:17 +02:00
Sergey Poznyakoff
3c4e51fad6 Various fixes.
* src/xattrs.c: Don't mix variable declarations and statements.
Use proper data types.  Remove improper use of const qualifiers.
Use x2nrealloc to reallocate memory buffers.
2012-11-19 00:14:31 +02:00
Sergey Poznyakoff
4ac671c49b Minor change.
* src/xattrs.c: Fix indentation. Fix copyleft statement, promote to GPLv3+.
* src/xattrs.h: Likewise
2012-11-18 23:05:00 +02:00
Pavel Raiskup
085cace180 Add SELinux context store/restore/list support.
* gnulib.modules: Add selinux-at.
* src/Makefile.am (tar_LDADD): Add LIB_SELINUX.

* src/create.c (start_header, dump_file0): Handle selinux contexts.
* src/extract.c (delayed_set_stat) <cntx_name>: New member.
(delayed_link) <cntx_name>: New member.
(set_stat, delay_set_stat)
(apply_nonancestor_delayed_set_stat): Handle selinux contexts.
* src/tar.c: New options: "--selinux", "--no-selinux".
(tar_stat_destroy): Free cntx_name.
* src/tar.h (tar_stat_info) <cntx_name>: New member.
* src/xattrs.c (xattrs_selinux_get)
(xattrs_selinux_set): New functions.
(xattrs_print_char): Honor selinux_context_option.
(xattrs_print): Print selinux context.
* src/xheader.c: Handle new keyword "RHT.security.selinux".
* tests/Makefile.am: Add new tests.
* tests/testsuite.at: Likewise.
* tests/selacl01.at: New test.
* tests/selnx01.at: New test.
2012-11-18 22:28:01 +02:00
Pavel Raiskup
d36f5a3cc3 Support for POSIX ACLs
* configure.ac: Check whether ACLs are available on the
host system.
* gnulib.modules: Add acl
* src/create.c (start_header): Store ACLs when creating
a POSIX archive.
(dump_file0): Handle ACLs.
* src/extract.c (delayed_set_stat) <acls_a_ptr, acls_a_len>
<acls_d_ptr, acls_d_len>: New members.
(delayed_link): Likewise.
(set_stat,delay_set_stat)
(apply_nonancestor_delayed_set_stat): Set ACLs.
* src/tar.c: New options: "--acls", "--no-acls"
(tar_stat_destroy): Free acls_a_ptr and acls_d_ptr fields.
* src/tar.h (tar_stat_info) <acls_a_ptr, acls_a_len>
<acls_d_ptr, acls_d_len>: New members.
* src/xattrs.c (xattrs_acls_get, xattrs_acls_set): New functions.
* src/xheader.c: Support new keywors: "SCHILY.acl.access" and
"SCHILY.acl.default".
* tests/Makefile.am: Add new tests.
* tests/testsuite.at: Likewise.
* tests/acls01.at: New test.
* tests/acls02.at: New test.
2012-11-18 20:54:02 +02:00
Pavel Raiskup
696338043e Add basic suuport for extended attributes.
* src/Makefile.am: Add xattrs.[ch]
* src/xattrs.c: New file.
* src/xattrs.h: New file.
* src/common.h (READ_LIKE_SUBCOMMAND): New define.
(selinux_context_option, acls_option, xattrs_option): New globals.
(xheader_xattr_init, xheader_xattr_free)
(xheader_xattr_copy, xheader_xattr_add): New protos.
(WARN_XATTR_WRITE): New mask.
* src/create.c (start_header): Handle xattrs pairs if in POSIX format.
(dump_file0): Handle extended attributes.
* src/extract.c (delayed_set_stat,delayed_link) <xattr_map_size>
<xattr_map>: New members.
(set_xattr): New static function.
(open_output_file): Accept an additional argument indicating
whether the file has already been created.
(set_stat,delay_set_stat)
(apply_nonancestor_delayed_set_stat)
(extract_file): Handle extended attributes.
* src/list.c (decode_header, simple_print_header): Display
extended attributes.
* src/tar.c: New options --xattrs, --no-xattrs, --xattrs-include,
--xattrs-exclude
(tar_stat_destroy): Free the xattr_map storage.
* src/tar.h (xattr_array): New struct.
(tar_stat_info) <xattr_map_size, xattr_map>: New members.
* src/warning.c: New warning control keyword "xattr-write".
* src/xheader.c (xheader_xattr_init)
(xheader_xattr_free, xheader_xattr_add)
(xheader_xattr_copy): New functions.
(struct xhdr_tab) <prefix>: New member.
(locate_handler): Permit selecting the keyword based on its
prefix.
(xheader_protected_pattern_p)
(xheader_protected_keyword_p): Likewise.
(xattr_coder, xattr_decoder): New functions.
(xhdr_tab): Reflect the changes to struct xhdr_tab.
New keyword "SCHILY.xattr".
* tests/Makefile.am: Add new tests.
* tests/testsuite.at: Likewise.
(AT_CHECK_UTIL, AT_XATTRS_UTILS_PREREQ)
(AT_CAPABILITIES_UTILS_PREREQ, AT_XATTRS_PREREQ): New defuns.
* tests/xattr01.at: New test.
* tests/xattr02.at: New test.
* tests/xattr03.at: New test.
* tests/xattr04.at: New test.
* tests/capabs_raw01.at: New test.
2012-11-18 20:15:03 +02:00
Sergey Poznyakoff
b997c90f9e Prepare for implementing extended attribute support.
This patch adds *xattr() stubs in case extended attribute support is
not present and implements the *attrat() family of functions.  Based
on the patch by Pavel Raiskup <pavel@raiskup.cz> for gnulib.

* acinclude.m4 (TAR_HEADERS_ATTR_XATTR_H): New defun.
* configure.ac: Call TAR_HEADERS_ATTR_XATTR_H
* lib/Makefile.am: Add xattr-at.[ch], distribute attr-xattr.in.h
[!TAR_COND_XATTR_H]: Build attr/xattr.h
* lib/attr-xattr.in.h: New file.
* lib/xattr-at.c: New file.
* lib/xattr-at.h: New file.
2012-11-18 19:55:43 +02:00
Sergey Poznyakoff
643a8844a5 Fix creation of incremental archives when a subdirectory becomes a mountpoint.
When used with --listed-incrfental and --one-file-system, tar
was unable to cope with directories that had once been part of the
dumped system and became separate mount points afterwards.  The bug
has been reported and a fix proposed by Nathan Stratton Treadway.

* src/incremen.c (procdir): If one_file_system_option is in effect,
clear out dumpdir info from the directory.
* tests/Makefile.am: Add new testcase.
* tests/listed05.at: New testcase.
* tests/testsuite.at (AT_PRIVILEGED_PREREQ): New macro.
include listed05.at.
* THANKS: Update.
2012-11-14 09:09:47 +02:00
Jim Meyering
099f71f78d maint: try to avoid unwanted chatter in ChangeLog
* bootstrap.conf: Do not alter ChangeLog if it already exists.
2012-07-27 01:32:31 -07:00
Paul Eggert
07ef59cab8 doc: improve discussion of compressed archives
* doc/tar.texi (gzip): Don't claim that -I 'gzip --best' works.
Problem reported by Davide Brini in
<http://lists.gnu.org/archive/html/bug-tar/2012-07/msg00025.html>.
Also, improve some of the surrounding text.

This file is a placeholder. It will be replaced with the actual ChangeLog
by make dist.  Run make ChangeLog if you wish to create it earlier.
2012-07-26 08:50:17 -07:00
Paul Eggert
0708c153e4 tests: fix permissions-assumption bug in test
* tests/owner.at: Don't assume umask is 022.
Reported by Pavel Raiskup in
<http://lists.gnu.org/archive/html/bug-tar/2012-06/msg00015.html>.
2012-06-27 09:56:31 -07:00
Paul Eggert
1cd2725227 tar: don't assume root is uid 0
This is not true for Tandem NonStop Kernel.  See Joachim Schmitz's
comment in <http://bugs.gnu.org/10305#111>.
* gnulib.modules: Add root-uid.
* src/extract.c: Include <root-uid.h>.
(extr_init): Don't assume root is uid 0.
2012-06-26 17:15:21 -07:00
Paul Eggert
6a61354ea0 * src/compare.c (diff_dumpdir): Omit useless 'stat'. 2012-04-24 22:06:00 -07:00
Paul Eggert
273dfb16cc * doc/tar.texi (Option Summary): Fix xref typo.
Reported by Nathan Stratton Treadway in
<http://lists.gnu.org/archive/html/bug-tar/2012-04/msg00035.html>.

This file is a placeholder. It will be replaced with the actual ChangeLog
by make dist.  Run make ChangeLog if you wish to create it earlier.
2012-04-24 21:39:56 -07:00
Sergey Poznyakoff
2a61a3701f Fix unrecognized option.
* src/tar.c (parse_opt): Handle OLD_ARCHIVE_OPTION.
2012-03-29 08:57:29 +03:00
Paul Eggert
5bb0433507 tar: remove lint
This lint was found by GCC 4.6.2 on Fedora 15 x86-64.
* src/buffer.c (buffer_write_global_xheader, mv_end, set_start_time)
(compute_duration, print_total_stats, flush_read, flush_write):
* src/checkpoint.c (checkpoint_finish_compile):
* src/list.c (test_archive_label):
* src/misc.c (chdir_count):
* src/names.c (const):
* src/unlink.c (finish_deferred_unlinks):
Define with (void) instead of with (), for slightly-better C type
checking and to avoid a GCC warning.
* src/compare.c (diff_dumpdir):
* src/tar.c (parse_owner_group): Remove unused local.
* src/misc.c (chdir_do):
* src/tar.c (add_exclude_array): Rename local to avoid shadowing.
(LOW_DENSITY_NUM, MID_DENSITY_NUM, HIGH_DENSITY_NUM):
Define only if needed.
* src/update.c (update_archive): Initialize a local; this fixes
what appears to be a real bug.
2012-03-11 13:01:51 -07:00
Paul Eggert
8c75b1387a doc: suggest Bash for large-fd script
* doc/tar.texi (Multi-Volume Archives): Suggest Bash for shell
script that might use >&10.  Problem reported by Edward F Eaglehouse in
<http://lists.gnu.org/archive/html/bug-tar/2012-02/msg00002.html>.
2012-02-14 10:18:30 -08:00
Paul Eggert
debc485626 tar: quote 'like this', not `like this'
This fixes some test failures recently introduced by gnulib updates
prompted by recent changes to the GNU coding standards,
which now advise to use quotes 'like this' or "like this"
rather than `like this'.
* NEWS: Document this.
* README, README-hacking, doc/Makefile.am, scripts/backup.in:
* scripts/backup.sh.in, scripts/dump-remind.in:
* src/buffer.c, src/checkpoint.c, src/create.c, src/incremen.c:
* src/misc.c, src/names.c, src/sparse.c, src/transform.c:
* tests/incr02.at, tests/incremental.at, tests/multiv08.at:
* tests/sparse04.at, tests/star/README, tests/update01.at:
Quote 'like this' in comments.
* src/tar.h:
Quote "like this" in comments, when quoting English phrases rather
than code.
* configure.ac:
* scripts/xsparse.c (get_var, read_xheader, main):
* src/compare.c (diff_archive):
* src/extract.c (prepare_to_extract):
* src/tar.c (request_stdin, tar_set_quoting_style, doc, options)
(set_subcommand_option, report_textual_dates, parse_opt)
(decode_options, main):
* src/xheader.c (decx):
Quote 'like this' in diagnostics.
* doc/tar.texi (list, warnings, override)
(Selecting Archive Members, quoting styles, after, hard links)
(Sparse Recovery, Multi-Volume Archives, label):
Adjust documentation to match new output.
* tests/backup01.at, tests/incr01.at, tests/incr04.at:
* tests/label04.at, tests/label05.at, tests/link03.at:
* tests/listed02.at, tests/multiv03.at, tests/multiv05.at:
* tests/rename01.at, tests/rename02.at, tests/rename03.at:
* tests/volume.at:
Adjust tests to match new quoting behavior.
2012-01-18 00:25:23 -08:00
Paul Eggert
6689e8db4f tar: port --overwrite symlink test to GNU/Hurd
Problem reported by Pino Toscano in
<http://lists.gnu.org/archive/html/bug-tar/2012-01/msg00040.html>.
* gnulib.modules: Add fcntl-h, which defines
HAVE_WORKING_O_NOFOLLOW.
* src/extract.c (open_output_file): Use HAVE_WORKING_O_NOFOLLOW,
not O_NOFOLLOW, when testing whther O_NOFOLLOW works.

This file is a placeholder. It will be replaced with the actual ChangeLog
by make dist.  Run make ChangeLog if you wish to create it earlier.
2012-01-17 22:22:23 -08:00
Paul Eggert
9a82a0215b tar: fix core dump with --index-file=bad_path
* src/tar.c (decode_options): Exit cleanly if index file won't open.
Problem reported by Khanh-Dang Nguyen Thu Lam in
<http://lists.gnu.org/archive/html/bug-tar/2012-01/msg00018.html>.
2012-01-11 11:37:33 -08:00
Paul Eggert
03858cf583 tar: don't assume O_NONBLOCK is benign on regular files
On Data Migration Facility (DMF), High Peformance Storage System (HPSS),
and presumably other file systems based on hierarchical storage, opening
a regular file with O_NONBLOCK can cause later reads to fail with
errno == EAGAIN.  We need the O_NONBLOCK to avoid some security races.
Work around the problem by using fcntl to clear the O_NONBLOCK
flag if I/O fails with that errno value.
Problem reported by Vitezslav Cizek in
<http://lists.gnu.org/archive/html/bug-tar/2012-01/msg00000.html>.
* src/common.h (blocking_read, blocking_write): New decls.
* src/misc.c (blocking_read, blocking_write): New functions.
* src/compare.c (process_rawdata):
* src/create.c (dump_regular_file):
* src/extract.c (extract_file):
* src/sparse.c (sparse_scan_file, sparse_extract_region):
2012-01-06 12:40:47 -08:00
Sergey Poznyakoff
7a5a3708cb Fix --keep-old-files option.
The regression was introduced by 8f390db9.  This patch implements additional
option --skip-old-files, which silently skips members which would cause
writing over existing files, and restores --keep-old-files to its traditional
behavior.

* NEWS: Update.
* configure.ac: Update.
* doc/tar.texi: Document the changes.
* src/common.h (SKIP_OLD_FILES): New old_files mode.
* src/extract.c (maybe_recoverable): Restore KEEP_OLD_FILES behavior.
Handle SKIP_OLD_FILES.
* src/tar.c: New option --skip-old-files.
* tests/extrac18.at: New file.
* tests/extrac19.at: New file.
* tests/Makefile.am: Add new test cases.
* tests/testsuite.at: Likewise.
2011-11-26 15:50:40 +02:00
Sergey Poznyakoff
02bf3a96a9 Warn about existing files in keep-old-files mode (complements 8f390db9).
This is controlled by "existing-file" warning code, which is off
by default.

* src/common.h (WARN_EXISTING_FILE): New warning code.
(WARN_VERBOSE_WARNINGS): Add WARN_EXISTING_FILE.
* src/extract.c (maybe_recoverable): warn about existing file
if WARN_EXISTING_FILE is set.
* src/warning.c: New warning type: "existing-file"
2011-11-17 22:19:05 +02:00
Sergey Poznyakoff
79138eaef1 Fix the "Creating directory:" output
* src/list.c (print_for_mkdir): don't use unquoted name length for
computing its output width.
2011-11-17 10:27:52 +02:00
Sergey Poznyakoff
d88b2a613f Fix operation of --verify in conjunction with --listed-incremental
* src/common.h (clear_directory_table): New proto.
* src/incremen.c (clear_directory_table): New function.
* src/compare.c (diff_dumpdir): Take a pointer to struct
tar_stat_info as argument.
Initialize its fd.
(diff_archive): Update call to diff_dumpdir.
(verify_volume): Call clear_directory_table.
2011-11-15 13:23:44 +02:00
Paul Eggert
1e1fc0336b * doc/tar.texi (Option Summary, absolute): Document -P better,
by describing how it deals with symbolic links on extraction.
2011-10-18 13:07:29 -07:00
Paul Eggert
02533d1a60 2011-09-27 Paul Eggert <eggert@cs.ucla.edu>
* src/tar.c (stat_on_signal): Use SA_RESTART if available.
2011-09-27 21:22:15 -07:00
Paul Eggert
d0dd0473f7 * doc/tar.texi: Remove front- and back-cover texts.
These are no longer needed for this manual, according to the
GNU maintainers guide.	Update copyright date to 2011.
2011-09-20 10:29:30 -07:00
Sergey Poznyakoff
8f70a3294c Minor changes.
* scripts/tar-snapshot-edit: License under GPLv3+.
Remove trailing whitespace.
2011-09-19 20:23:40 +03:00
Nathan Stratton Treadway
a6cc856fbe Minor changes.
* doc/snapshot.texi: Clarify the use of nfs field in 0 and 1 formats.
Give more precise information about which versions of tar used each
format.
2011-09-19 16:13:47 +03:00
Nathan Stratton Treadway
51b272f572 Upgrade tar-snapshot-edit script.
* scripts/tar-snapshot-edit: Update Perl syntax to work
correctly with more recent versions of Perl.  (The original
code worked with in the v5.8 timeframe but not with
Perl v5.10.1 and later.)
Add a "-c" option to check the snapshot file for invalid
field values.
Handle NFS indicator character ("+") in version 0 and 1 files.
Preserve the original header/version line when editing version 1
or 2 files.
Tweak output formatting.
* doc/tar-snapshot-edit.texi: Update documentation.
2011-09-19 15:29:00 +03:00
Paul Eggert
1f9b376c90 tar: --owner and --group names and numbers
The --owner and --group options now accept operands of the form
NAME:NUM, so that you can specify both symbolic name and numeric
ID for owner and group.  Also, in these options, NAME no longer
needs to be present in the current host's user and group
databases; this implements Debian enhancement request 136231
<http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=136231> reported
by Mark W. Eichin, communicated by Thayne Harbaugh to bug-tar in
<http://lists.gnu.org/archive/html/bug-tar/2011-08/msg00001.html>.
* NEWS, doc/tar.texi (Option Summary, override): Document enhancement.
* src/common.h (group_name_option, owner_name_option): New decls.
* src/create.c (start_header): Don't assume owner and group names
are in current host database.
* src/tar.c (parse_owner_group): New function, for parsing NAME:NUM.
(parse_opt): Use it.
(decode_options): Initialize owner_name_option, group_name_option.
* tests/owner.at: New file, to test this enhancement.
* tests/Makefile.am (TESTSUITE_AT): Add it.
* tests/testsuite.at: Include it.
2011-08-13 10:20:40 -07:00
Paul Eggert
9fe65e2520 .gitignore: update
* .gitignore: Add rmt.
* lib/.gitignore: New file.
2011-08-13 10:20:40 -07:00
Sergey Poznyakoff
fa307a6655 Fix the --exclude-backups option.
* src/tar.c (add_exclude_array): Take exclude option filags in its
second argument.
(parse_opt): Register backup_file_table with the EXCLUDE_WILDCARDS flag.
* tests/exclude07.at: New testcase.
* tests/Makefile.am (TESTSUITE_AT): Add testsuite.at.
* tests/testsuite.at: Include exclude07.at.
2011-07-30 18:26:38 +03:00
Paul Eggert
49bd102a1b tar: simplify birthtime calculations
* src/extract.c (same_birthtime): Remove.
(extract_link, apply_delayed_links): Go back to using timestamp_cmp
instead of same_birthtime, as this is a bit simpler.  This fix relies
on an up-to-date gnulib.
2011-06-07 16:07:29 -07:00
Paul Eggert
189e436474 tar: use birthtime rather than ctime when checking identity
Without this fix, tar would sometimes mishandle the extraction of
hard links to symbolic links.  Problem reported in
<http://lists.gnu.org/archive/html/bug-tar/2011-06/msg00000.html>
by Andreas Stolcke.
* src/extract.c (struct delayed_link): Change ctime member to birthtime.
(same_birthtime): New function.
(create_placeholder_file, extract_link, apply_delayed_links):
Use it to compare birthtimes (when available) instead of ctime.
2011-06-07 15:18:01 -07:00
Paul Eggert
9708b248e8 * doc/tar.texi (Old Options): Clarify distinction from short options.
Adjust other parts of the manual to use examples that parse the
same regardless of whether "-" is in front of the option clump.  See
<http://lists.gnu.org/archive/html/bug-tar/2011-05/msg00022.html>.
2011-05-26 12:10:39 -07:00
Sergey Poznyakoff
afcdb89492 Testsuite fix.
* tests/sparse04.at: Use the -f option.
2011-03-12 22:22:21 +02:00
Sergey Poznyakoff
aea443b9e8 Version 1.26
* NEWS, configure.ac: Update.
* po/POTFILES.in: Remove paxexit.c (see bb971a1e).
2011-03-12 12:20:07 +02:00
Paul Eggert
881e5626c5 --atime-preserve=replace: fix correctness and performance bugs
reported by Eric Blake in
<http://lists.gnu.org/archive/html/bug-tar/2011-03/msg00000.html>.
* src/compare.c (diff_file): Do not restore atime of size-zero files.
* src/create.c (dump_file0): Likewise.  Also, do not restore atime
when fd is zero, because that indicates a file we haven't opened.
2011-03-07 15:40:56 -08:00
Paul Eggert
67ae04ba31 * doc/tar.texi: Adjust example commands and output for accuracy.
The original problem was reported by Michael Witten in
<http://lists.gnu.org/archive/html/bug-tar/2011-02/msg00033.html>.
2011-02-22 16:41:10 -08:00
Paul Eggert
2807513841 tar: if (p) free (p); -> free (p);
There is no longer (since SunOS 4) any need to guard against
free (NULL), so replace each "if (p) free (p);" with "free (p);".
From Jim Meyering in
<http://lists.gnu.org/archive/html/bug-tar/2011-01/msg00026.html>.
* src/incremen.c (scan_directory, read_directory_file): As above.
(try_purge_directory): Likewise.
* src/list.c (read_header): Likewise.
* src/misc.c (assign_string): Likewise.
2011-02-16 13:47:28 -08:00
Sergey Poznyakoff
bb0af96c54 Correctly store long sparse file names in PAX archives.
* src/sparse.c (pax_dump_header_1): Make sure the created header name is
shorter than NAME_FIELD_SIZE bytes.
* tests/sparse04.at: New testcase.
* tests/Makefile.am (TESTSUITE_AT): Add sparse04.at.
* tests/testsuite.at: Include sparse04.at.
* NEWS: Update.
2010-12-14 15:27:55 +02:00
Paul Eggert
ec586b37e0 tests: make the truncate test smaller and less buggy (tiny change)
Reported by Solar Designer in
<http://lists.gnu.org/archive/html/bug-tar/2010-12/msg00003.html>.
* tests/truncate.at: Use a smaller test case, and make its
race condition less likely.
2010-12-06 14:27:29 -08:00
Paul Eggert
a7fc5ecead tests: skip SIGPIPE-dependent tests in environments ignoring SIGPIPE
Problem reported by Sven Joachim in
<http://lists.gnu.org/archive/html/bug-tar/2010-11/msg00043.html>.
* tests/remfiles01.at: Use AT_SIGPIPE_PREREQ.
* tests/sigpipe.at: Likewise.
* tests/testsuite.at (AT_SIGPIPE_PREREQ): New macro.
2010-11-26 19:36:05 -08:00
Paul Eggert
649b747913 tar: work around NetBSD and Tru64 symlink incompatibility with POSIX
Problem reported by Bruno Haible in
<http://lists.gnu.org/archive/html/bug-gnulib/2010-11/msg00306.html>.
* src/extract.c (maybe_recoverable):  Also treat EFTYPE (if defined)
and ENOTSUP like ELOOP.
2010-11-24 23:08:07 -08:00
Paul Eggert
bb971a1e8a tar: adjust to paxutils change: paxexit.c -> paxexit-status.c
* lib/Makefile.am (libtar_a_SOURCES): paxexit.c renamed to
paxexit-status.c.
2010-11-23 21:41:50 -08:00
Paul Eggert
50a57a0147 tar: remove unused function dir_removed_diag
* src/common.h (dir_removed_diag): Remove unused decl.
* src/misc.c (dir_removed_diag): Remove unused function.
2010-11-23 17:56:58 -08:00
Paul Eggert
1584b72ff2 tar: work around FreeBSD symlink incompatibility with POSIX
* src/extract.c (maybe_recoverable): Treat EMLINK like ELOOP, for
FreeBSD.  Problem reported by Christian Weisgerber in
<http://lists.gnu.org/archive/html/bug-tar/2010-11/msg00080.html>.
2010-11-23 12:58:09 -08:00
Paul Eggert
065cf0958c * src/names.c: tar: fix bug with --one-file-system --listed-incremental
Problem (and idea for fix) reported by Martin Weigel
<http://lists.gnu.org/archive/html/bug-tar/2010-11/msg00071.html>.
* src/common.h (is_individual_file): Remove decl.
* src/create.c (dump_file0): Replace "is_individual_file (p)"
with "top_level".
* src/incremen.c (procdir): Replace "!is_individual_file
(name_buffer)" with "st->parent".  Fix bug with --one-file-system
and --listed-incremental.
* src/names.c (individual_file_table, register_individual_file):
(is_individual_file): Remove.  All uses removed.
2010-11-22 22:51:29 -08:00
Paul Eggert
2a55b4b037 tests: new test listed04 for --one-file-system --listed-incremental
* tests/Makefile.am (TESTSUITE_AT): Add listed04.at.
* tests/listed04.at: New file.
* tests/testsuite.at: Include it.
2010-11-22 17:59:21 -08:00
Paul Eggert
27225be1a3 scripts: fix option parsing
Problem reported by Dennis Wydra in
<http://lists.gnu.org/archive/html/bug-tar/2010-11/msg00082.html>.
* scripts/backup.in: Accept "-l LEVEL".  Be more systematic about
backslashes inside ``; it shouldn't matter for modern shells but
it might matter for older ones.
* scripts/restore.in: Likewise.
* scripts/backup.in: Adjust implementation of -t/--time to match
the new implementation of -l/--level.
2010-11-22 15:18:41 -08:00
Sergey Poznyakoff
73d0d1a0f8 Issue a warning if the archive being compared contais transformed file names.
* src/common.h (transform_program_p): New proto.
* src/transform.c (transform_program_p): New function.
* src/compare.c (verify_volume): Warn if the archive contains
transformed file names.
2010-11-15 11:22:27 +02:00
Sergey Poznyakoff
ff2bc5c0a1 Minor change.
* doc/tar.texi: Reword the description of decompress-program.
2010-11-15 11:21:45 +02:00
Paul Eggert
24214ca5d5 tar: fix --verify option, which broke in 1.24
* NEWS: Document this.
* src/compare.c (verify_volume): Decode the header before invoking
diff_archive, as diff_archive no longer does this as of the
2010-06-28 commit.  Also, don't try to invoke diff_archive on a
zero block.
* tests/Makefile.am (TESTSUITE_AT): Add verify.at.
* tests/testsuite.at: Include verify.at.
* tests/verify.at: New file.
2010-11-15 00:08:27 -08:00
Paul Eggert
777042e024 Merge branch 'master' of ssh://git.sv.gnu.org/srv/git/tar 2010-11-08 11:14:28 -08:00
Jim Meyering
1801399830 tests: avoid spurious failure when VERSION_CONTROL envvar is set
* tests/backup01.at: Unset VERSION_CONTROL.  Otherwise,
when set to e.g., 'always', it would cause this test to fail.
2010-11-08 11:13:39 -08:00
Sergey Poznyakoff
ecd700fbfb Version 1.25
* configure.ac: Version 1.25
* NEWS: Describe the changes.
2010-11-07 16:04:48 +02:00
Sergey Poznyakoff
f1fed3996a Run alternative decompression programs if the principal one is not available.
Some compression programs are able to handle various compression formats
(e.g. `gzip' can decompress files created by `compress', `xz' is able
to handle lzma, etc.)  Tar tries to use such programs for decompression
if the principal decompressor cannot be started.

* src/buffer.c (compress_type): Swap ct_none and ct_tar.
(archive_compression_type): New static variable.
(zip_magic): Remove program and option fields.
(zip_program): New structure and static.
(compress_program): Remove macro.
(find_zip_program): New static function.
(first_decompress_program,next_decompress_program): New functions.
(open_compressed_archive): Set archive_compression_type instead of
use_compress_program_option.
* src/common.h (first_decompress_program)
(next_decompress_program): New functions.
(WARN_DECOMPRESS_PROGRAM): New flag.
(WARN_VERBOSE_WARNINGS): Include WARN_DECOMPRESS_PROGRAM.
* src/warning.c (warning_args): Add "decompress-program".
(warning_types): Add WARN_DECOMPRESS_PROGRAM.
* src/system.c (run_decompress_program): New function.
(sys_child_open_for_uncompress): Use run_decompress_program
instead of calling execlp directly.
2010-11-05 10:09:51 +02:00
Paul Eggert
b32edff5aa tests: fix some issues with signals, timestamps, "test" typo
* tests/extrac17.at: Add --warning=no-timestamp, to avoid
bogus warning due to NFS clock skew.
* tests/remfiles01.at: Discard diagnostics that some shells
generate about broken pipes.
* tests/sigpipe.at: Likewise.
* tests/remfiles01.at: Fix typo: "test $EC" was written where
"test $EC -ne 0" was intended.
2010-11-02 01:05:16 -07:00
Sergey Poznyakoff
3913675640 Fix extraction of device nodes.
* src/extract.c (extract_node): Do not mask out node type.
The bug was introduced in commit ea964cce.
2010-11-01 15:05:25 +02:00
Paul Eggert
b8feb2b142 tar: don't cross struct member boundaries with OLDGNU_MAGIC
* src/create.c (write_gnu_long_link, start_header): Access
header->buffer + offsetof (struct posix_header, magic), instead of
header->header.magic, when reading or writing the OLDGNU_MAGIC
pattern.  The code violates the C standard without this change,
and GCC warns about this if fortify checking is enabled.  It's not
a bug on traditional (i.e., non-debugging) platforms, but it does
violate the C standard so it should be fixed.  Problem originally
reported by John Emil Karlson in
<http://lists.gnu.org/archive/html/bug-tar/2010-04/msg00023.html>.
* src/list.c (decode_header): Likewise.
2010-10-27 22:31:16 -07:00
Paul Eggert
3fe59ed5ef tests: port to sh variants that squirrel away file descriptors
OpenBSD /bin/sh, and some other sh variants, squirrel away file
descriptors before closing them.  For example, for "cat 3<&-" they
first dup file descriptor 3 to a fd that is 10 or greater, then
close 3 (because if "cat" had been a builtin command like ":" then
they would have wanted to avoid the fork and restore the fd after
":" finished); and they treat ordinary (forking) commands the same
as builtin commands.  This approach fails after "ulimit -n 10".
Work around this deficiency by closing the file descriptors before
invoking ulimit.  Problem reported by Christian Weisgerber in
<http://lists.gnu.org/archive/html/bug-tar/2010-10/msg00041.html>;
solution suggested by Jilles Tjoelker in
<http://article.gmane.org/gmane.comp.shells.dash/415>.

* tests/extrac11.at (scarce file descriptors): Close file
descriptors before invoking ulimit -n.
2010-10-27 20:25:56 -07:00
Sergey Poznyakoff
5af29cb944 Transform file names when updating and appendig to archives.
This complements 28e91b48.

* src/common.h (transform_stat_info): New prototype.
* src/list.c (transform_stat_info): Remove static qualifier.
* src/update.c (update_archive): Call transform_stat_info.
* tests/Makefile.am (TESTSUITE_AT): Add append03.at
* tests/testsuite.at: Include append03.at
2010-10-27 14:07:46 +03:00
Paul Eggert
7dd57ebdfa tests: port to Solaris diff
* tests/extrac13.at: Don't assume that "diff -c" outputs nothing
when there are no differences.  This is not true on Solaris,
where it outputs "No differences encounted".
2010-10-26 18:13:03 -07:00
Paul Eggert
e23d123b93 tar: fix -x --overwrite bug (no --dereference, ! O_NOFOLLOW)
This bug was discovered on Solaris 8.  On older hosts lacking
O_NOFOLLOW, tar -x --overwrite (without --dereference) follows
symbolic links, causing the "extract over symlinks" test to fail.

* src/extract.c (open_output_file): If O_NOFOLLOW is needed but
does not work, check for a symlink separately.
2010-10-26 17:58:53 -07:00
Paul Eggert
6398c7a79c tar: don't use "((" in shell scripts
* tests/extrac11.at: Replace "((" with "( (" in shell scripts, as
"((" is not portable to the Korn shell, and POSIX 1003.1-2008 says
that "((" is not portable.
2010-10-26 15:04:56 -07:00
Sergey Poznyakoff
28e91b48f6 Make sure name matching occurs before name transformation.
The commit 9c194c99 altered that order.

* src/list.c (transform_stat_info): New function.  Split off from
decode_header.
(read_and): Call transform_stat_info right before do_something,
and after deciding if we should proceed with this member name,
so that name matching occurs before name transformation.

* tests/extrac17.at: New file.
* tests/Makefile.am (TESTSUITE_AT): Add extrac17.at
* tests/testsuite.at: Include extrac17.at.
2010-10-26 22:29:02 +03:00
Paul Eggert
3c0bedd494 tar: don't assume stdin is open when testing fd limits
* tests/extrac11.at: Redirect stdin from /dev/null, in case
the parent 'make' is running with stdin closed.
2010-10-26 11:33:38 -07:00
Sergey Poznyakoff
c520964e84 Further fixes in bootstrap.
* bootstrap: Restore the default for gnulib_path
(symlink_to_dir): Re-apply 67cad07.
2010-10-26 16:48:40 +03:00
Paul Eggert
acb77ac5bd tar: fix bug with -C and extracting directories
Problem reported by Denis Excoffier in
<http://lists.gnu.org/archive/html/bug-tar/2010-10/msg00034.html>.

* src/extract.c (extract_dir): Use mkdirat, not mkdir.
* tests/extrac16.at: New file, to test for this bug.
* tests/Makefile.am (TESTSUITE_AT): Add it.
* tests/testsuite.at: Include it.

This file is a placeholder. It will be replaced with the actual ChangeLog
by make dist.  Run make ChangeLog if you wish to create it earlier.
2010-10-25 20:21:06 -07:00
348 changed files with 30653 additions and 9842 deletions

47
.gitignore vendored
View File

@@ -1,31 +1,32 @@
*.a
*.[aios]
*.[gx]z
*.bz2
*.cache
*.diff
*.la
*.lo
*.o
*.orig
*.patch
*.rej
*.so
*DISTFILES
*~
.bootstrap
.deps
.emacs*
.libs
ABOUT-NLS
ChangeLog
INSTALL
Make.rules
.gdbinit
/.bootstrap
/ABOUT-NLS
/ChangeLog
/INSTALL
/Make.rules
/aclocal.m4
/build-aux/
/conf*
!/configure.ac
/gnu/
/m4/
/rmt/
/stamp-h1
Makefile
Makefile.in
aclocal.m4
autom4te.cache
build-aux
build-aux/
config.h
config.h.in
config.log
config.status
configure
gnu
gnulib
libtool
m4
paxutils
stamp-h1
TAGS

6
.gitmodules vendored Normal file
View File

@@ -0,0 +1,6 @@
[submodule "gnulib"]
path = gnulib
url = https://git.savannah.gnu.org/git/gnulib.git
[submodule "paxutils"]
path = paxutils
url = https://git.savannah.gnu.org/git/paxutils.git

View File

@@ -1,7 +1,7 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
@@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
<https://www.gnu.org/licenses/why-not-lgpl.html>.

View File

@@ -2,25 +2,22 @@ Currently there is just one ChangeLog file for tar, but
there used to be separate ChangeLog files for each subdirectory.
This file records what used to be in those separate files.
Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
Free Software Foundation, Inc.
Copyright 1989-1997, 2013, 2023-2025 Free Software Foundation, Inc.
This file is part of GNU Tar.
This file is part of GNU tar.
GNU Tar is free software; you can redistribute it and/or modify
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
GNU Tar is distributed in the hope that it will be useful,
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Tar; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
along with this program. If not, see <http://www.gnu.org/licenses/>.
----- ChangeLog -----
@@ -346,7 +343,7 @@ Boston, MA 02110-1301, USA.
* configure.in: For mknod, also include <sys/types.h> prior to
<sys/stat.h>, as Ultrix needs this.
Reported by Bruce Jerrick, Bryant Fujimoto, Conrad Hughes, Erich
Stefan Boleyn, Jason R. Mastaler, Joshua R. Poulson, Jurgen Botz,
Stefan Boleyn, Jason R. Mastaler, Joshua R. Poulson, Jürgen Botz,
Serge Granik, Simon Wright, Ulrich Drepper and Vince Del Vecchio.
* configure.in: Replace execlp as needed (for Minix, mainly).
@@ -1296,7 +1293,7 @@ Boston, MA 02110-1301, USA.
* gmalloc.c: New, from elsewhere. This renames and updates
what was previously malloc.c. This also solves __const vs const.
* Makefile.in: Distribute gmalloc.c.
Reported by Cliff Krumvieda, Francois Pinard, Henrik Bakman,
Reported by Cliff Krumvieda, François Pinard, Henrik Bakman,
J.T. Conklin, Nelson H.F. Beebe and Tilman Schmidt.
1994-07-22 François Pinard <pinard@iro.umontreal.ca>
@@ -2941,7 +2938,7 @@ Boston, MA 02110-1301, USA.
Elmer Fittery, Eric Benson, Eric M. Boehm, Gerd Knorr, Graham
Whitted, Harald Milz, Heiko Schlichting, James V. Di Toro III,
Jan Carlson, Janne Snabb, Jeff Sorensen, Jens Henrik Jensen,
Jim Clausing, John J. Szetela, John R. Vanderpool, Jurgen Botz,
Jim Clausing, John J. Szetela, John R. Vanderpool, Jürgen Botz,
Karl Berry, Karlos Z. Smith, Karsten Thygesen, Koji Kishi,
Luke Mewburn, Manuel Munier, Marc Ewing, Matthew J. D'Errico,
Martin Goik, Maxime Taksar, maximum entropy, Michael Hayes,
@@ -3189,7 +3186,7 @@ Boston, MA 02110-1301, USA.
Reported by Jeffrey Goldberg.
* rmt.h (_remdev): A filename is not remote if the colon is
preceeded by a slash, to take care of `/:/' which is a shorthand
preceded by a slash, to take care of `/:/' which is a shorthand
for `/.../<CELL-NAME>/fs' on OSF's Distributing Computing
Environment (DCE) and Distributed File System (DFS).
Reported by Travis L. Priest.
@@ -3854,7 +3851,7 @@ Boston, MA 02110-1301, USA.
* tar.h: Merely define valloc as being malloc if valloc does
not exist.
* port.h: Remove valloc, which was only a dummy for malloc.
Reported by Cliff Krumvieda, Francois Pinard, Henrik Bakman,
Reported by Cliff Krumvieda, François Pinard, Henrik Bakman,
J.T. Conklin, Nelson H.F. Beebe and Tilman Schmidt.
1994-07-22 François Pinard <pinard@iro.umontreal.ca>
@@ -5389,7 +5386,7 @@ Boston, MA 02110-1301, USA.
* getdate.y : Parse European dates of the form YYMMDD.
In ftime(): Init timezone by calling localtime(), and remember that
timezone is in seconds, but we want timeb->timezone to be in minutes.
Reported by Jörgen Haegg.
Reported by Jörgen Hägg.
* rtape_lib.c (__rmt_open): Also look for /usr/bsd/rsh.
Declare signal handler as returning void instead of int if USG is

View File

@@ -1,3 +1,25 @@
Currently the ChangeLog is generated automatically from the Git
revision history, but from 1997 to 2009 the ChangeLog file was
maintained by hand, under CVS. This file records the older log.
Copyright 1997-2001, 2003-2009, 2013, 2023-2025 Free Software
Foundation, Inc.
This file is part of GNU tar.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
2009-03-05 Sergey Poznyakoff <gray@gnu.org.ua>
* src/incremen.c: --no-recursive works with --incremental.
@@ -913,7 +935,7 @@
2006-10-02 Sergey Poznyakoff <gray@gnu.org.ua>
* THANKS: Add Joerg Weilbier
* THANKS: Add Jörg Weilbier
* src/buffer.c (new_volume): Initialize current_block
* src/xheader.c (xheader_string_end): Fix diagnostic message.
* tests/multiv05.at: New testcase.
@@ -1007,7 +1029,7 @@
this has undefined behavior. Likewise for assigning arbitrary
uintmax_t values to other types.
(read_negative_num, read_unsigned_num, read_timespec):
New functions, to check input values a bit more carefuly.
New functions, to check input values a bit more carefully.
(read_num): Use read_unsigned_num. New arg MAX_VAL;
all callers changed.
(read_incr_db_2): Use these new functions.
@@ -1187,7 +1209,7 @@
* src/delete.c: Remove second argument from calls to name_scan
* src/update.c: Likewise
* src/incremen.c (procdir): Use is_individual_file to check for
files explicitely specified in the command line. Fixes bug
files explicitly specified in the command line. Fixes bug
reported by Dat Head on 19 Jun 2006 (descending into mountpoints
with --one-file-system in use)
* src/misc.c (maybe_backup_file): Second argument is bool
@@ -1246,7 +1268,7 @@
* src/delete.c (records_skipped): Remove static qualifier, the
variable is used by print_total_stats in buffer.c
* src/extract.c (check_time): Use volume_start_time when checking
for timestamp plausability.
for timestamp plausibility.
* src/tar.c: (options, parse_opt): Allow for optional argument to
the --totals option, which specifies a signal upon delivery of which
the statistics must be output.
@@ -1304,7 +1326,7 @@
* src/transform.c (set_transform_expr,_transform_name_to_obstack):
Implement NUMBER flag.
(add_char_segment): Fix length assignement
(add_char_segment): Fix length assignment
* doc/tar.texi: Update
@@ -1361,7 +1383,7 @@
* doc/tar.texi: Update
* configure.ac (AM_INIT_AUTOMAKE): Use tar-ustar option. Raise
version requirement to 1.9
* src/common.h (struct name): Refactured
* src/common.h (struct name): Refactored
(warn_regex_usage): New variable.
(dump_file): First argument is const char*.
(name_init,name_add): Removed
@@ -1736,13 +1758,13 @@
* src/common.h (struct name): New member `explicit'. Remove unused
member `isdir'.
* src/incremen.c (procdir): If name_scan() returns something,
check if it was explicitely given in the command line
check if it was explicitly given in the command line
* src/names.c (addname,add_hierarchy_to_namelist): Initialize
explicit member appropriately.
* src/incremen.c (procdir): If --one-file-system is given and a
directory is found to be on another device, *and* this directory
is explicitely given in the command line, then do not omit it.
is explicitly given in the command line, then do not omit it.
2005-12-11 Sergey Poznyakoff <gray@gnu.org.ua>
@@ -1777,7 +1799,7 @@
(mode_to_chars, off_to_chars, size_to_chars, time_to_chars)
(uid_to_chars, uintmax_to_chars): Return bool
(to_chars): Return bool
(start_header): Check return values of convertion routines. Fail
(start_header): Check return values of conversion routines. Fail
if unable to store data in the header.
2005-12-07 Sergey Poznyakoff <gray@gnu.org.ua>
@@ -2077,13 +2099,13 @@
archives.
* src/incremen.c (dumpdir_size, get_gnu_dumpdir): New functions.
(purge_directory): Use stat_info.dumpdir instead of getting its
value explicitely.
value explicitly.
* src/list.c (list_archive): Handle incremental backups in pax
format.
(decode_header): Initialize stat_info.dumpdir
* src/sparse.c (sparse_diff_file): Bugfix: set seekable.
(pax_dump_header): Store sparse map in GNU.sparse.map. If this
variable has been explicitely deleted, use GNU.sparse.offset/
variable has been explicitly deleted, use GNU.sparse.offset/
GNU.sparse.numbytes variables.
* src/tar.c (decode_options): Incremental options are allowed with
--format=pax
@@ -2161,7 +2183,7 @@
* bootstrap: Fix quoting in help output.
(update_po): Use backward-compatible wget option --cache instead
of deprecated -C to accomodate for wget 1.10.
of deprecated -C to accommodate for wget 1.10.
Changes proposed by Eric Blake
* THANKS: Add Eric Blake
@@ -2712,7 +2734,7 @@
* src/list.c: Likewise
* tests/multiv03.at: Modified to match the new behavior
* tests/multiv04.at: New file. Test splittind directory members between
* tests/multiv04.at: New file. Test splitting directory members between
the archive volumes.
* tests/Makefile.am: Add multiv04.at
* tests/testsuite.at: Likewise.
@@ -4466,7 +4488,7 @@
* src/create.c: Do not zero-terminate name field if
the name is exactly 100 characters long.
(write_ustar_long_name): Fixed cheking for unsplittable
(write_ustar_long_name): Fixed checking for unsplittable
names.
2003-11-14 Sergey Poznyakoff <gray@Mirddin.farlep.net>
@@ -4501,7 +4523,7 @@
2003-11-12 Paul Eggert <eggert@twinsun.com>
Fix some C compatibility bugs reported by Joerg Schilling.
Fix some C compatibility bugs reported by Jörg Schilling.
* src/common.h (stripped_prefix_len): Fix misspelling
"stripped_path_len" in declaration.
@@ -5163,7 +5185,7 @@
interface.
(child_open_for_compress): Do not increase size to BLOCKSIZE.
(open_archive): Open index file name.
Strip trailing slahes from file names.
Strip trailing slashes from file names.
(flush_write): Set size to 0 if not saving names.
(flush_write, flush_read): Use safer_name_suffix rather than
inline code.
@@ -5996,7 +6018,7 @@
(decode_options): Dates that look like an absolute path name,
or that start with '.', are presumed to be file names whose
dates are taken.
Remove 'I' as an aliase for 'T'.
Remove 'I' as an alias for 'T'.
Update copyright.
* src/extract.c (<time.h>): Do not include; system.h now does this.
@@ -8806,26 +8828,6 @@
See ChangeLog.1 for earlier changes.
-----
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007
Free Software Foundation, Inc.
This file is part of GNU tar.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU tar; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
Local Variables:
mode: change-log

70
ChangeLog.amend Normal file
View File

@@ -0,0 +1,70 @@
# Fix typos in tar ChangeLog entries generated from git log
f24b30ec8ca1851b7bd14694241de3b38194c99c
s/commit 2bd9c153_\./commit 2bd9c153)./
29a6964af3e1baabe978ce608e0466e1250d08ab
s/ORDER \(none, name, or order\)\./ORDER (none, name, or inode)./
2af87fa2776c8125a587a9b0c2c4fae3bf921ff7
s/contant\./content./
2bd9c15391b0bd6ef0bff76aebf09cfb53003199
s/ocurrence/occurrence/
47da28892e6860a3a6fc06745f640e3bb878c757
s/aruond/around/
f7077dd38b018f19d3a5c7df6accc6b07b8a2356
s/absoulte/absolute/
28b44aaacb45680aa6640e0a6d7ceab04cfdbf11
s/warniing/warning/
47560a0498bde20621ce4e367b1d68bf8cd8f1a3
s/interacton/interaction/
26538c9bfc5fd726d625bef5fa3f08212d50173a
s/consuption/consumption/;
s/misfunctioned/malfunctioned/;
s/misssing/missing/;
696338043e52f440853e1143c52b81b41cd59723
s/suuport/support/
643a8844a578ff146cfe746fe6091d29502b6c40
s/incrfental/incremental/;
s/afterwards/afterward/;
03858cf583ce299b836d8a848967ce290a6bf303
s/Peformance/Performance/
fa307a665545753b6729191fd2559ce872fa470a
s/filags/flags/
73d0d1a0f883be5f67534362c99382f1eae8d178
s/contais/contains/
5af29cb944c84e2d539ce9df527d63c29f6012b9
s/appendig/appending/
7dd57ebdfa9ac0d2af4622449f45b5025f6c184f
s/encounted/encountered/
ecbcb7b6d74c2d69386c8d7e435486a4690c9993
s/inadvertantly/inadvertently/
4dfcd6c054a5e9e1a371c822a3be90564dd9b690
s/succesfully/successfully/

View File

@@ -1,22 +1,21 @@
# Main Makefile for GNU tar.
# Copyright (C) 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2003, 2007,
# 2009 Free Software Foundation, Inc.
# Copyright 1994-2025 Free Software Foundation, Inc.
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3, or (at your option)
## any later version.
# This file is part of GNU tar.
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = ChangeLog.1 Make.rules
@@ -26,7 +25,7 @@ dist-hook:
$(MAKE) changelog_dir=$(distdir) ChangeLog
-rm -f $(distdir).cpio
find $(distdir) | cpio -Hcrc -o | \
GZIP=$(GZIP_ENV) gzip -c > $(distdir).cpio.gz
eval GZIP= gzip $(GZIP_ENV) -c > $(distdir).cpio.gz
distclean-local:
-rm -f $(distdir).cpio.gz
@@ -36,3 +35,4 @@ include Make.rules
gen_start_date = 2009-03-06
prev_change_log = ChangeLog.CVS
changelog_dir = .
changelog_amend_file=ChangeLog.amend

715
NEWS

File diff suppressed because it is too large Load Diff

128
README
View File

@@ -4,31 +4,30 @@ See the end of file for copying conditions.
* Introduction
Please glance through *all* sections of this
`README' file before starting configuration. Also make sure you read files
`ABOUT-NLS' and `INSTALL' if you are not familiar with them already.
'README' file before starting configuration. Also make sure you read files
'ABOUT-NLS' and 'INSTALL' if you are not familiar with them already.
If you got the `tar' distribution in `shar' format, time stamps ought to be
properly restored; do not ignore such complaints at `unshar' time.
If you got the 'tar' distribution in 'shar' format, time stamps ought to be
properly restored; do not ignore such complaints at 'unshar' time.
GNU `tar' saves many files together into a single tape or disk
GNU 'tar' saves many files together into a single tape or disk
archive, and can restore individual files from the archive. It includes
multivolume support, the ability to archive sparse files, automatic archive
compression/decompression, remote archives and special features that allow
`tar' to be used for incremental and full backups. This distribution
also includes `rmt', the remote tape server. The `mt' tape drive control
program is in the GNU `cpio' distribution.
'tar' to be used for incremental and full backups. This distribution
also includes 'rmt', the remote tape server. The 'mt' tape drive control
program is in the GNU 'cpio' distribution.
GNU `tar' is derived from John Gilmore's public domain `tar'.
GNU 'tar' is derived from John Gilmore's public domain 'tar'.
See file `ABOUT-NLS' for how to customize this program to your language.
See file `COPYING' for copying conditions.
See file `INSTALL' for compilation and installation instructions.
See file `PORTS' for various ports of GNU tar to non-Unix systems.
See file `NEWS' for a list of major changes in the current release.
See file `THANKS' for a list of contributors.
See file 'ABOUT-NLS' for how to customize this program to your language.
See file 'COPYING' for copying conditions.
See file 'INSTALL' for compilation and installation instructions.
See file 'NEWS' for a list of major changes in the current release.
See file 'THANKS' for a list of contributors.
Besides those configure options documented in files `INSTALL' and
`ABOUT-NLS', an extra option may be accepted after `./configure':
Besides those configure options documented in files 'INSTALL' and
'ABOUT-NLS', an extra option may be accepted after './configure':
* Install
@@ -40,11 +39,11 @@ values are GNU, V7, OLDGNU, USTAR and POSIX.
** Selecting the default archive device
The default archive device is now `stdin' on read and `stdout' on write.
The installer can still override this by presetting `DEFAULT_ARCHIVE'
in the environment before configuring (the behavior of `-[0-7]' or
`-[0-7]lmh' options in `tar' are then derived automatically). Similarly,
`DEFAULT_BLOCKING' can be preset to something else than 20.
The default archive device is now 'stdin' on read and 'stdout' on write.
The installer can still override this by presetting 'DEFAULT_ARCHIVE'
in the environment before configuring (the behavior of '-[0-7]' or
'-[0-7]lmh' options in 'tar' are then derived automatically). Similarly,
'DEFAULT_BLOCKING' can be preset to something else than 20.
** Selecting full pathname of the "rmt" binary.
@@ -76,13 +75,13 @@ directory.
Use option --enable-backup-scripts to compile and install these
scripts.
** `--disable-largefile' omits support for large files, even if the
** '--disable-largefile' omits support for large files, even if the
operating system supports large files. Typically, large files are
those larger than 2 GB on a 32-bit host.
* Installation hints
Here are a few hints which might help installing `tar' on some systems.
Here are a few hints which might help installing 'tar' on some systems.
** gzip and bzip2.
@@ -103,7 +102,7 @@ then you have encountered a gzip incompatibility that should be fixed
in gzip test version 1.3, which as of this writing is available at
<ftp://alpha.gnu.org/gnu/gzip/>. You can work around the
incompatibility by using a shell command like
`gzip -d <file.tar.gz | tar -xzf -'.
'gzip -d <file.tar.gz | tar -xzf -'.
** Solaris issues.
@@ -118,13 +117,13 @@ understand these headers.
** Static linking.
Some platform will, by default, prepare a smaller `tar' executable
which depends on shared libraries. Since GNU `tar' may be used for
Some platform will, by default, prepare a smaller 'tar' executable
which depends on shared libraries. Since GNU 'tar' may be used for
system-level backups and disaster recovery, installers might prefer to
force static linking, making a bigger `tar' executable maybe, but able to
force static linking, making a bigger 'tar' executable maybe, but able to
work standalone, in situations where shared libraries are not available.
The way to achieve static linking varies between systems. Set LDFLAGS
to a value from the table below, before configuration (see `INSTALL').
to a value from the table below, before configuration (see 'INSTALL').
Platform Compiler LDFLAGS
@@ -137,18 +136,18 @@ to a value from the table below, before configuration (see `INSTALL').
Solaris (vendor) -Bstatic
SunOS (vendor) -Bstatic
** Failed tests `ignfail.sh' or `incremen.sh'.
** Failed tests 'ignfail.sh' or 'incremen.sh'.
In an NFS environment, lack of synchronization between machine clocks
might create difficulties to any tool comparing dates and file time stamps,
like `tar' in incremental dumps. This has been a recurrent problem with
like 'tar' in incremental dumps. This has been a recurrent problem with
GNU Make for the last few years. We would like a general solution.
** BSD compatibility matters.
Set LIBS to `-lbsd' before configuration (see `INSTALL') if the linker
complains about `bsd_ioctl' (Slackware). Also set CPPFLAGS to
`-I/usr/include/bsd' if <sgtty.h> is not found (Slackware).
Set LIBS to '-lbsd' before configuration (see 'INSTALL') if the linker
complains about 'bsd_ioctl' (Slackware). Also set CPPFLAGS to
'-I/usr/include/bsd' if <sgtty.h> is not found (Slackware).
** OPENStep 4.2 swap files
@@ -159,43 +158,43 @@ the simplest workaround is to avoid tarring this file.
* Special topics
Here are a few special matters about GNU `tar', not related to build
Here are a few special matters about GNU 'tar', not related to build
matters. See previous section for such.
** File attributes.
About *security*, it is probable that future releases of `tar' will have
About *security*, it is probable that future releases of 'tar' will have
some behavior changed. There are many pending suggestions to choose from.
Today, extracting an archive not being `root', `tar' will restore suid/sgid
bits on files but owned by the extracting user. `root' automatically gets
a lot of special privileges, `-p' might later become required to get them.
Today, extracting an archive not being 'root', 'tar' will restore suid/sgid
bits on files but owned by the extracting user. 'root' automatically gets
a lot of special privileges, '-p' might later become required to get them.
GNU `tar' does not properly restore symlink attributes. Various systems
GNU 'tar' does not properly restore symlink attributes. Various systems
implement flavors of symbolic links showing different behavior and
properties. We did not successfully sorted all these out yet. Currently,
the `lchown' call will be used if available, but that's all.
the 'lchown' call will be used if available, but that's all.
** POSIX compliance.
GNU `tar' is able to create archive in the following formats:
GNU 'tar' is able to create archive in the following formats:
*** The format of UNIX version 7
*** POSIX.1-1988 format, also known as "ustar format"
*** POSIX.1-2001 format, also known as "pax format"
*** Old GNU format (described below)
In addition to those, GNU `tar' is also able to read archives
produced by `star' archiver.
In addition to those, GNU 'tar' is also able to read archives
produced by 'star' archiver.
A so called `Old GNU' format is based on an early draft of the
POSIX 1003.1 `ustar' standard which is different from the final
A so called 'Old GNU' format is based on an early draft of the
POSIX 1003.1 'ustar' standard which is different from the final
standard. It defines its extensions (such as incremental backups
and handling of the long file names) in a way incompatible with
any existing tar archive format, therefore the use of old GNU
format is strongly discouraged.
Please read the file NEWS for more information about POSIX compliance
and new `tar' features.
and new 'tar' features.
* What's next?
@@ -216,32 +215,35 @@ to the report address; rather take special arrangement with the maintainer.
Your feedback will help us to make a better and more portable package.
Consider documentation errors as bugs, and report them as such. If you
develop anything pertaining to `tar' or have suggestions, let us know
develop anything pertaining to 'tar' or have suggestions, let us know
and share your findings by writing to <bug-tar@gnu.org>.
* Copying
Copyright (C) 1990, 1991, 1992, 1994, 1997, 1998, 1999, 2000,
2001, 2003, 2004, 2007 Free Software Foundation, Inc.
Copyright 1990-2025 Free Software Foundation, Inc.
This file is part of GNU tar.
This file is part of GNU tar.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with tar; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
NOTE ON COPYRIGHT YEARS
In copyright notices where the copyright holder is the Free Software
Foundation, then where a range of years appears, this is an inclusive
range that applies to every year in the range. For example: 2005-2008
represents the years 2005, 2006, 2007, and 2008.
Local Variables:
mode: outline

View File

@@ -3,73 +3,16 @@ This is GNU tar.
This is a *pre-release* version, and not ready for production use yet.
Please send comments and problem reports to <bug-tar@gnu.org>.
If you have taken the sources from CVS you will need the following
packages (or later) to build GNU tar. We don't make any extra effort
to accommodate older versions of these packages, so please make sure
that you have the latest stable version.
- Automake <http://www.gnu.org/software/automake/>
- Autoconf <http://www.gnu.org/software/autoconf/>
- Bison <http://www.gnu.org/software/bison/>
- Gettext <http://www.gnu.org/software/gettext/>
- Gzip <http://www.gnu.org/software/gzip/>
- M4 <http://www.gnu.org/software/m4/>
- Texinfo <http://www.gnu.org/software/texinfo>
- Wget <http://www.gnu.org/software/wget/>
As of this writing, the latest stable version of Gzip is 1.2.4 but we
suggest using test version 1.3.5 (or later, if one becomes available).
Valgrind <http://valgrind.org/> is also highly recommended, if
Valgrind supports your architecture.
Before building the package, run "bootstrap". It obtains various
additional files from the CVS repository and the Translation Project
site and prepares the source directory for building.
When run without arguments, bootstrap will try to obtain gnulib and
paxutils files from their corresponding CVS repositories on Savannah
using anonymous SSH access. Then, it will fetch the po files from tar
page at Translation Project, and, finally, it will start autoconfiguration
process. Simply running it without arguments should do in most cases.
Several options allow to control the behavior of bootstrap:
--gnulib-srcdir=DIRNAME Specify the local directory where gnulib
sources reside. Use this if you already
have gnulib sources on your machine, and
do not want to waste your bandwidth dowloading
them again.
--paxutils-srcdir=DIRNAME Specify the local directory where paxutils
sources reside. Use this if you already
have paxutils sources on your machine, and
do not want to waste your bandwidth dowloading
them again.
--cvs-auth=METHOD Set the CVS access method used for downloading
gnulib files. METHOD is one of the keywords
accepted by cvs -d option (see info cvs
repository).
--cvs-user=USERNAME Set the CVS username to be used when accessing
the gnulib repository.
--no-po Do not download po files.
Notice also that when using CVS authentication method "ext", bootstrap
will set the variable CVS_RSH to "ssh", unless it is already set to
some other value.
Copyright (C) 2001, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
Copyright 2001-2025 Free Software Foundation, Inc.
This file is part of GNU tar.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -77,6 +20,4 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with tar; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
along with this program. If not, see <http://www.gnu.org/licenses/>.

View File

@@ -8,12 +8,22 @@ tar. We do not make any efforts to accommodate older versions of
these packages, so please make sure that you have the latest stable
version.
- Automake <http://www.gnu.org/software/automake/>
- Autoconf <http://www.gnu.org/software/autoconf/>
- Automake <http://www.gnu.org/software/automake/>
- Bison <http://www.gnu.org/software/bison/>
- M4 <http://www.gnu.org/software/m4/>
- Texinfo <http://www.gnu.org/software/texinfo>
- Gnulib <http://www.gnu.org/software/gnulib>
- Gettext <http://www.gnu.org/software/gettext/>
- Git <http://git.or.cz>
- Gzip <http://www.gnu.org/software/gzip/>
- Texinfo <http://www.gnu.org/software/texinfo>
- Wget <http://www.gnu.org/software/wget/>
Up-to-date compilers and libraries are also recommended, for better
static checking. You may be able to use an older compiler by building
with 'make WERROR_CFLAGS='; if so, don't worry about its false alarms.
Valgrind <http://valgrind.org/> is also highly recommended, if
Valgrind supports your architecture.
* Bootstrapping
@@ -33,33 +43,43 @@ Once done, proceed as described in the file README (section
INSTALLATION).
Normally you will have to run bootstrap only once. However, if you
intend to hack on GNU tar, you might need to run it again later. In
this case, you will probably want to save some time and bandwidth by
avoiding downloading the same files again. If so, create in GNU tar
root directory the file named `.bootstrap' with the following
contents:
intend to hack on GNU tar, you might need to run it again later.
There are lots of options that you may find useful in this case.
See './bootstrap --help' for a detailed list.
--gnulib-srcdir=$HOME/gnulib
Bootstrapping obtains Gnulib and Paxutils files from their Git
repositories on Savannah. Then, it fetches translations from the
Translation Project, and, finally, it builds files useful for
configuration. Simply running ./bootstrap without arguments should do
in most cases.
Replace `$HOME/gnulib' with the actual directory where the Gnulib
sources reside.
The file bootstrap.conf contains bootstrapping configuration.
Several options are provided that modify its behavior.
Run './bootstrap --help' for a list.
For more information about `bootstrap', run `bootstrap --help'.
To only fetch auxiliary files from the network, run './bootstrap --pull'.
To only generate files such as 'configure', without accessing the
network, run './bootstrap --gen'.
* Copyright information
Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
Copyright 2007-2025 Free Software Foundation, Inc.
Permission is granted to anyone to make or distribute verbatim copies
of this document as received, in any medium, provided that the
copyright notice and this permission notice are preserved,
thus giving the recipient permission to redistribute in turn.
This file is part of GNU tar.
Permission is granted to distribute modified versions
of this document, or of portions of it,
under the above conditions, provided also that they
carry prominent notices stating who last changed them.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
^L
Local Variables:

29
THANKS
View File

@@ -8,6 +8,7 @@ list of these people. Help me keep it complete and exempt of errors.
See various ChangeLogs for a detailed description of contributions.
Aage Robeck aagero@ifi.uio.no
Adam Borowski kilobyte@angband.pl
Adye, TJ (Tim) T.J.Adye@rl.ac.uk
Akiko Matsushita matusita@sra.co.jp
Alan Bawden Alan@lcs.mit.edu
@@ -36,6 +37,7 @@ Andrew Torda torda@igc.chem.ethz.ch
Andrey A. Chernov ache@astral.msk.su
Andy Gay andy@rdl.co.uk
Antonio Jose Coutinho ajc@di.uminho.pt
Anthony G. Basile blueness@gentoo.org
Ariel Faigon ariel@engr.sgi.com
Arne Wichmann aw@math.uni-sb.de
Arnold Robbins arnold@gnu.org
@@ -77,6 +79,7 @@ Cesar Romani romani@ifm.uni-hamburg.de
Chad Hurwitz churritz@cts.com
Chance Reschke creschke@usra.edu
Charles Fu ccwf@klab.caltech.edu
Charles McGarvey chazmcgarvey@brokenzipper.com
Charles Lopes Charles.Lopes@infm.ulst.ac.uk
Charles M. Hannum mycroft@gnu.org
Chip Salzenberg tct!chip
@@ -91,6 +94,8 @@ Christian Kirsch ck@held.mind.de
Christian Laubscher christian.laubscher@tiscalinet.ch
Christian T. Dum ctd@mpe-garching.mpg.de
Christian von Roques roques@pond.sub.org
Christian Wetzel wetzel@phoenix-pacs.de
Christian Weisgerber naddy@mips.inka.de
Christoph Litauer litauer@mailhost.uni-koblenz.de
Christophe Colle colle@krtkg1.rug.ac.be
Christophe Kalt Christophe.Kalt@kbcfp.com
@@ -100,10 +105,12 @@ Claude Scarpelli claude@genethon.fr
Claus Heine Claus_Heine@ac2.maus.de
Cliff Krumvieda cliff@cs.cornell.edu
Clinton Carr clint@netcom.com
Connor Behan connor.behan@gmail.com
Conrad Hughes chughes@maths.tcd.ie
Constantin Belous const@cris.net
Coranth Gryphon gryphon@bur.visidyne.com
Cyril Strejc strejc@unicontrols.cz
Dagobert Michelsen dam@opencsw.org
Dale R. Worley worley@world.std.com
Dale Wiles wiles@geordi.calspan.com
Dan Bloch dan@transarc.com
@@ -111,6 +118,7 @@ Dan Drake dan@dandrake.org
Dan Reish dreish@izzy.net
Daniel Hagerty hag@gnu.org
Daniel Quinlan quinlan@pathname.com
Daniel Kahn Gillmor dkg@fifthhorseman.net
Daniel R. Guilderson d.guilderson@ma30.bull.com
Daniel S. Barclay daniel@compass-da.com
Daniel Trinkle trinkle@cs.purdue.edu
@@ -118,6 +126,7 @@ Danny R. Johnston danny@cs.weber.edu
Dave Barr barr@math.psu.edu
Dave Gentzel gentzel@nova.enet.dec.com
Dave Gregorich dtg@ipac.caltech.edu
David Barri japgolly@gmail.com
David Brown davidb@davidb.org
David J. MacKenzie djm@uunet.uu.net
David Johnson David.W.Johnson@colorado.edu
@@ -131,11 +140,13 @@ David Nugent davidn@blaze.net.au
David Shaw david.shaw@alcatel.com.au
David Steiner dsteiner@ispa.uni-osnabrueck.de
David Taylor taylor@think.com
Dawid dpc@dpc.pw
Dean Gaudet dgaudet@watdragon.uwaterloo.ca
Demizu Noritoshi nori-d@is.aist-nara.ac.jp
Denis Excoffier denis.excoffier@free.fr
Denis Fortin fortin@acm.org
Dennis Pixton dennis@math.binghamton.edu
Derek Terveer dt@hawkmoon.mn.org
Dick Streefland dicks@tasking.nl
Dietmar Braun dietmar@highway.bertelsmann.de
Dimitri Bougoulias opus@hol.gr
@@ -168,6 +179,7 @@ Erik D. Frederick edf@deckard.mc.duke.edu
Esa Karell karell@cs.helsinki.fi
Ezra Peisach epeisach@mit.edu
Fabio d'Alessi cars@civ.bio.unipd.it
Flavio Poletti polettix@gmail.com
Frank Heckenbach frank@g-n-u.de
Frank Koenen koenfr@lidp.com
Franz-Werner Gergen gergen@edvulx.mpi-stuttgart.mpg.de
@@ -198,6 +210,7 @@ Helmut Waitzmann Helmut.Waitzmann@web.de
Henrik Bakman hb@csd.uu.se
Hernan Prieto Schmidt hernan@pea.usp.br
Hiroyuki Bessho bsh@grotto.iijnet.or.jp
Holger Levsen holger@layer-acht.org
Holger Teutsch holger@hotbso.rhein-main.de
Hugh Secker-Walker hugh@ear.mit.edu
Hunyue Yau hunyue.yau@picksys.com
@@ -236,11 +249,13 @@ Jeffrey Goldberg J.Goldberg@cranfield.ac.uk
Jeffrey Mark Siskind Qobi@emba.uvm.edu
Jeffrey W. Parker jwpkr@mcs.com
Jens Henrik Jensen recjhl@mediator.uni-c.dk
Jérémy Bobbio lunar@debian.org
Jim Blandy jimb@totoro.cs.oberlin.edu
Jim Clausing jac@postbox.acs.ohio-state.edu
Jim Farrell jwf@platinum.com
Jim Meyering meyering@na-net.ornl.gov
Jim Murray jjm@jjm.com
Jivko Angelov jivko@siteground.com
Joachim Holzfuss Joachim.Holzfuss@iap.physik.th-darmstadt.de
Joachim Seelig joachim@kruemel.han.de
Joe DeBattista joed@itsa.ucsf.edu
@@ -268,7 +283,7 @@ Joutsiniemi Tommi Il tj75064@cs.tut.fi
Joy Kendall jak8@world.std.com
Judy Ricker jricker@gdstech.grumman.com
Juha Sarlin juha@tds.kth.se
Jurgen Botz jbotz@orixa.mtholyoke.edu
Jürgen Botz jbotz@orixa.mtholyoke.edu
Jyh-Shyang Wang erik@vsp.ee.nctu.edu.tw
Jörg Schilling schilling@fokus.fraunhofer.de
Jörg Weule weule@cs.uni-duesseldorf.de
@@ -293,9 +308,11 @@ Kevin D Quitt drs@netcom.com
Kevin Dalley kevin@aimnet.com
Kimball Collins kpc@ptolemy.arc.nasa.gov
Kimmy Posey kimmyd@bnr.ca
Kirill Furman kfurman@astralinux.ru
Koji Kishi kis@rqa.sony.co.jp
Konno Hiroharu konno@pac.co.jp
Kurt Jaeger pi@lf.net
James Antill jantill@redhat.com
Larry Creech lcreech@lonestar.rcclub.org
Larry Schwimmer rosebud@cyclone.stanford.edu
Lasse Collin lasse.collin@tukaani.org
@@ -311,6 +328,7 @@ Mads Martin Joergensen mmj@suse.de
Manfred Weichel Manfred.Weichel@mch.sni.de
Manuel Munier Manuel.Munier@loria.fr
Marc Boucher marc@cam.org
Marc Espie marc.espie.openbsd@gmail.com
Marc Ewing marc@redhat.com
Marcin Matuszewski marcin@frodo.nask.org.pl
Marcus Daniels marcus@sysc.pdx.edu
@@ -349,6 +367,7 @@ Michael P Urban urban@cobra.jpl.nasa.gov
Michael Schmidt michael@muc.de
Michael Schwingen m.schwingen@stochastik.rwth-aachen.de
Michael Smolsky fnsiguc@astro.weizmann.ac.il
Michal Žejdl zejdl@suas.cz
Mike Muuss mike@brl.mil
Mike Nolan nolan@lpl.arizona.edu
Mike Rogers mike@demon.net
@@ -357,11 +376,14 @@ Mike Walker M.D.Walker@larc.nasa.gov
Milan Hodoscek milan@kihp6.ki.si
Minh Tran-Le tranle@intellicorp.com
Mitsuaki Masuhara masuhara@mcprv.mec.mei.co.jp
Natalie Alifanova na@nxc.no
Nate Eldredge nate@cs.hmc.edu
Nathan Stratton Treadway nathanst+bugtar@ontko.com
Neil Faulks neil@dcs.kcl.ac.uk
Neil Jerram nj104@cus.cam.ac.uk
Nelson H.F. Beebe beebe@math.utah.edu
Nick Barron nikb@cix.compulink.co.uk
Nicolas Dudebout nicolas.dudebout@gmail.com
Noah Friedman friedman@gnu.org
Noel Cragg noel@red-bean.com
Norbert Kiesel norbert@rwthi3.informatik.rwth-aachen.de
@@ -374,7 +396,8 @@ Oswald P. Backus IV backus@lks.csi.com
Pascal Meheut pascal@cnam.cnam.fr
Patrick Fulconis fulco@sig.uvsq.fr
Patrick Timmons timmons@electech.polymtl.ca
Paul Eggert eggert@twinsun.com
Pavel Raiskup praiskup@redhat.com
Paul Eggert eggert@cs.ucla.edu
Paul Kanz paul@icx.com
Paul Mitchell P.Mitchell@surrey.ac.uk
Paul Nevai pali+@osu.edu
@@ -395,6 +418,7 @@ Phil Proudman phil@proudman51.freeserve.co.uk
Philippe Defert defert@cern.ch
Piercarlo Grandi piercarl@sabi.demon.co.uk
Pierce Cantrell cantrell@ee.tamu.edu
Piotr Rotter piotr.rotter@active24.pl
R. Kent Dybvig dyb@cadence.bloomington.in.us
R. Scott Butler butler@prism.es.dupont.com
Rainer Orth ro@TechFak.Uni-Bielefeld.DE
@@ -513,6 +537,7 @@ Warner Losh imp@boulder.parcplace.com
Warren Dodge warrend@sptekwv3.wv.tek.com
Wayne Christopher wayne@icemcfd.com
Werner Almesberger werner.almesberger@lrc.di.epfl.ch
Wicher Minnaard wicher@nontrivialpursuit.org
William Bader william@nscs.fast.net
William J. Eaton wje@hoffman.rstnu.bcm.tmc.edu
William Kucharski kucharsk@netcom.com

30
TODO
View File

@@ -15,7 +15,7 @@ Suggestions for improving GNU tar.
* Add support for a 'pax' command that conforms to POSIX 1003.1-2001.
This would unify paxutils with tar.
* Interoperate better with Joerg Schilling's star implementation.
* Interoperate better with Jörg Schilling's star implementation.
* Add an option to remove files that compare successfully.
@@ -25,7 +25,7 @@ Suggestions for improving GNU tar.
It would be useful to be able to use '--remove-files' with '--diff',
to remove all files that compare successfully, when verifying a backup.
* Add tests for the new functonality.
* Add tests for the new functionality.
* Consider this:
@@ -45,24 +45,22 @@ Suggestions for improving GNU tar.
* Copyright notice
Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc.
Copyright 2003-2025 Free Software Foundation, Inc.
This file is part of GNU tar.
This file is part of GNU tar.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with tar; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Local variables:

View File

@@ -1,26 +1,62 @@
dnl Special Autoconf macros for GNU Tar -*- autoconf -*-
dnl Copyright (C) 2009 Free Software Foundation, Inc.
dnl Special Autoconf macros for GNU tar -*- autoconf -*-
dnl Copyright 2009-2025 Free Software Foundation, Inc.
dnl
dnl This file is part of GNU tar.
dnl
dnl GNU tar is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 3, or (at your option)
dnl any later version.
dnl the Free Software Foundation; either version 3 of the License, or
dnl (at your option) any later version.
dnl
dnl GNU tar is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License along
dnl with GNU tar. If not, see <http://www.gnu.org/licenses/>.
dnl You should have received a copy of the GNU General Public License
dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
AC_DEFUN([TAR_COMPR_PROGRAM],[
m4_pushdef([tar_compr_define],translit($1,[a-z+-],[A-ZX_])[_PROGRAM])
m4_pushdef([tar_compr_var],[tar_cv_compressor_]translit($1,[+-],[x_]))
AC_ARG_WITH($1,
AC_HELP_STRING([--with-]$1[=PROG],
AS_HELP_STRING([--with-]$1[=PROG],
[use PROG as ]$1[ compressor program]),
[tar_compr_var=${withval}],
[tar_compr_var=m4_if($2,,$1,$2)])
AC_DEFINE_UNQUOTED(tar_compr_define, "$tar_compr_var",
[Define to the program name of ]$1[ compressor program])])
# Provide <attr/xattr.h>, if necessary
AC_DEFUN([TAR_HEADERS_ATTR_XATTR_H],
[
AC_ARG_WITH([xattrs],
AS_HELP_STRING([--without-xattrs], [don't use linux extended attributes]),
[], [with_xattrs=maybe]
)
# First check for <sys/xattr.h>
AC_CHECK_HEADERS([sys/xattr.h])
AM_CONDITIONAL([TAR_COND_XATTR_H],[test "$ac_cv_header_sys_xattr_h" = yes])
if test "$ac_cv_header_sys_xattr_h" != yes; then
AC_CHECK_HEADERS([attr/xattr.h])
AM_CONDITIONAL([TAR_COND_XATTR_H],[test "$ac_cv_header_attr_xattr_h" = yes])
fi
if test "$with_xattrs" != no; then
for i in getxattr fgetxattr lgetxattr \
setxattr fsetxattr lsetxattr \
listxattr flistxattr llistxattr
do
AC_SEARCH_LIBS($i, attr)
eval found=\$ac_cv_search_$i
test "$found" = "no" && break
done
if test "$found" != no; then
AC_DEFINE([HAVE_XATTRS],,[Define when we have working linux xattrs.])
fi
fi
])

1931
bootstrap

File diff suppressed because it is too large Load Diff

View File

@@ -1,36 +1,33 @@
# Bootstrap configuration for GNU tar.
# Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
# Copyright 2006-2025 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# This file is part of GNU tar.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
source_base=gnu
gnulib_name=libgnu
gnulib_mk=Makefile.am
# We don't need these modules, even though gnulib-tool mistakenly
# includes them because of gettext dependencies.
# We don't need these modules, even though gnulib-tool ordinarily
# includes them because of dependencies on the modules 'exclude' and 'regex'.
avoided_gnulib_modules='
--avoid=lock
--avoid=mbuiter
--avoid=mbuiterf
'
# gnulib modules used by this package.
gnulib_modules="$avoided_gnulib_modules
`grep '^[^#]' gnulib.modules`
"
# Additional xgettext options to use. Use "\\\newline" to break lines.
XGETTEXT_OPTIONS=$XGETTEXT_OPTIONS'\\\
@@ -65,10 +62,68 @@ if [ -r .bootstrap ]; then
eval set -- "`sed 's/#.*$//;/^$/d' .bootstrap | tr '\n' ' '` $*"
fi
test -d m4 || mkdir m4
test -d $source_base || mkdir $source_base
bootstrap_post_pull_hook() {
mkdir -p m4 $source_base
git submodule init
git submodule update
}
cat > ChangeLog <<EOT
PAXUTILS=paxutils
# gnulib modules used by this package.
# getopt-gnu is for paxutils.
gnulib_modules="$avoided_gnulib_modules
`grep -h '^[^#]' gnulib.modules`
getopt-gnu
"
# copy_files srcdir dstdir
copy_files() {
for file in `cat $1/DISTFILES`
do
case $file in
"#*") continue;;
esac
dst=`echo $file | sed 's^.*/^^'`
if [ $# -eq 3 ]; then
case $dst in
${3}*) ;;
*) dst=${3}$dst;;
esac
fi
if [ "$2" = '.' ]; then
ln -sf $1/$file $2
else
symlink_to_dir "$1" "$file" "$2/$dst" || exit
fi
# FIXME ignorefile $2 $dst
done
}
bootstrap_post_import_hook() {
test -f ChangeLog || cat > ChangeLog <<EOT
This file is a placeholder. It will be replaced with the actual ChangeLog
by make dist. Run make ChangeLog if you wish to create it earlier.
EOT
# Import from paxutils
copy_files ${PAXUTILS} .
copy_files ${PAXUTILS}/am m4
echo "$0: Creating m4/paxutils.m4"
(echo "# This file is generated automatically. Please, do not edit."
echo "#"
echo "AC_DEFUN([${package}_PAXUTILS],["
cat ${PAXUTILS}/am/DISTFILES | sed '/^#/d;s/\(.*\)\.m4/pu_\1/' | tr a-z A-Z
echo "])") > ./m4/paxutils.m4
#FIXME ignorefile m4 paxutils.m4
mkdir -p rmt
for dir in doc rmt lib tests; do
copy_files ${PAXUTILS}/$dir $dir
done
copy_files ${PAXUTILS}/paxlib lib pax
}

View File

@@ -1,30 +1,28 @@
# Configure template for GNU tar. -*- autoconf -*-
# Copyright (C) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
# Software Foundation, Inc.
# Copyright 1991, 1994-2010, 2013-2025 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# This file is part of GNU tar.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
AC_INIT([GNU tar], [1.24], [bug-tar@gnu.org])
AC_INIT([GNU tar], [1.35], [bug-tar@gnu.org])
AC_CONFIG_SRCDIR([src/tar.c])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_HEADERS([config.h])
AC_PREREQ([2.63])
AM_INIT_AUTOMAKE([1.11 gnits tar-ustar dist-bzip2 dist-xz dist-shar std-options silent-rules])
AC_PREREQ([2.71])
AM_INIT_AUTOMAKE([1.15 gnits tar-ustar dist-bzip2 dist-xz std-options silent-rules])
# Enable silent rules by default:
AM_SILENT_RULES([yes])
@@ -34,69 +32,202 @@ AC_EXEEXT
AC_PROG_RANLIB
AC_PROG_YACC
gl_EARLY
AC_CHECK_TOOLS([AR], [ar])
AC_SYS_LARGEFILE
AC_ISC_POSIX
AC_C_INLINE
AC_CHECK_HEADERS_ONCE([linux/fd.h sys/mtio.h])
AC_CHECK_HEADERS_ONCE(fcntl.h linux/fd.h memory.h net/errno.h \
sgtty.h string.h \
sys/param.h sys/device.h sys/gentape.h \
sys/inet.h sys/io/trioctl.h \
sys/mtio.h sys/time.h sys/tprintf.h sys/tape.h \
unistd.h locale.h)
AC_CHECK_HEADERS([sys/buf.h], [], [],
[#if HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif])
AC_HEADER_SYS_WAIT
AC_HEADER_DIRENT
AC_HEADER_MAJOR
AC_HEADER_STAT
AC_HEADER_STDC
AC_MSG_CHECKING([for st_fstype string in struct stat])
AC_CACHE_VAL(diff_cv_st_fstype_string,
[AC_TRY_COMPILE([#include <sys/types.h>
#include <sys/stat.h>], [struct stat s; s.st_fstype[0] = 'x';],
diff_cv_st_fstype_string=yes,
diff_cv_st_fstype_string=no)])
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[#include <sys/types.h>
#include <sys/stat.h>
]],
[[struct stat s; s.st_fstype[0] = 'x';]])],
[diff_cv_st_fstype_string=yes],
[diff_cv_st_fstype_string=no])])
AC_MSG_RESULT($diff_cv_st_fstype_string)
if test $diff_cv_st_fstype_string = yes; then
AC_DEFINE(HAVE_ST_FSTYPE_STRING, 1,
[Define if struct stat has a char st_fstype[] member.])
fi
AC_TYPE_SIGNAL
# even if we use gnulib's acl.h with integrated m4 file later on (used because
# of very useful file_has_acl() function) we need following checks that restrict
# tar to use POSIX.1e ACLs only.
AC_ARG_WITH([posix-acls],
AS_HELP_STRING([--without-posix-acls],
[do not use POSIX.1e access control lists]),
[],
[with_posix_acls=yes])
if test "x$with_posix_acls" != "xno"; then
AC_CHECK_HEADERS(sys/acl.h,, [with_posix_acls=no])
for tar_acl_func in acl_get_file acl_get_fd acl_set_file acl_set_fd \
acl_to_text acl_from_text acl_delete_def_file \
acl_free; do \
test "x$with_posix_acls" = xno && break
AC_SEARCH_LIBS([$tar_acl_func], [acl pacl], [], [with_posix_acls=no])
done
if test "x$with_posix_acls" != xno; then
AC_DEFINE(HAVE_POSIX_ACLS,,[Define when we have working POSIX acls])
fi
else
# disable acls in gnulib's checks
export enable_acl=no
fi
AC_TYPE_MODE_T
AC_TYPE_PID_T
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
AC_TYPE_UID_T
AC_CHECK_TYPE(major_t, , AC_DEFINE(major_t, int,
[Type of major device numbers.]))
AC_CHECK_TYPE(minor_t, , AC_DEFINE(minor_t, int,
[Type of minor device numbers.]))
AC_CHECK_TYPE(dev_t, unsigned)
AC_CHECK_TYPE(ino_t, unsigned)
# Taken from GNU/Linux, and should be good enough on platforms
# lacking these types.
AC_CHECK_TYPE([dev_t], [unsigned long long int])
AC_CHECK_TYPE([ino_t], [unsigned long long int])
# Taken from GNU/Linux, and should be good enough on platforms
# lacking these types.
AC_CHECK_TYPE([major_t], [unsigned int])
AC_CHECK_TYPE([minor_t], [unsigned int])
gt_TYPE_SSIZE_T
# gnulib modules
gl_INIT
AC_DEFINE([GNULIB_EXCLUDE_SINGLE_THREAD], [1],
[Define if all programs in this package call functions of the Gnulib
'exclude' module only from a single thread.])
AC_DEFINE([GNULIB_MBRTOWC_SINGLE_THREAD], [1],
[Define if all programs in this package call functions of the Gnulib
'mbtowc' module only from a single thread.])
AC_DEFINE([GNULIB_REGEX_SINGLE_THREAD], [1],
[Define if all programs in this package call functions of the Gnulib
'regex' module only from a single thread.])
AC_DEFINE([GNULIB_WCHAR_SINGLE_LOCALE], [1],
[Define if all programs in this package call locale-sensitive functions
like mbrtowc only after setting the locale, and never change the
locale once set.])
if test $COMPILE_ERROR_C = 1; then
# This means that Gnulib's 'error' function will be used. It precedes
# error messages it prints with the program name as returned by getprogname()
# call, instead of using the name set by set_program_name.
# Install workaround.
AC_DEFINE([ENABLE_ERROR_PRINT_PROGNAME],[1],
[Enable the use of error_print_progname to print program name with error messages.
See comment to function tar_print_progname in src/tar.c])
fi
# paxutils modules
tar_PAXUTILS
AC_CHECK_FUNCS_ONCE([fchmod fchown fsync lstat mkfifo readlink symlink])
AC_CHECK_DECLS([getgrgid],,, [#include <grp.h>])
AC_CHECK_DECLS([getpwuid],,, [#include <pwd.h>])
AC_CHECK_DECLS([time],,, [#include <time.h>])
# gl_GCC_VERSION_IFELSE([major], [minor], [run-if-found], [run-if-not-found])
# ------------------------------------------------
# If $CPP is gcc-MAJOR.MINOR or newer, then run RUN-IF-FOUND.
# Otherwise, run RUN-IF-NOT-FOUND.
AC_DEFUN([gl_GCC_VERSION_IFELSE],
[AC_PREPROC_IFELSE(
[AC_LANG_PROGRAM(
[[
#if ($1) < __GNUC__ || (($1) == __GNUC__ && ($2) <= __GNUC_MINOR__)
/* ok */
#else
# error "your version of gcc is older than $1.$2"
#endif
]]),
], [$3], [$4])
]
)
AC_REPLACE_FUNCS(waitpid)
AC_ARG_ENABLE([gcc-warnings],
[AS_HELP_STRING([--enable-gcc-warnings],
[turn on many GCC warnings (for developers; best with GNU make)])],
[case $enableval in
yes|no) ;;
*) AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
esac
gl_gcc_warnings=$enableval],
[gl_gcc_warnings=no
if test -d "$srcdir"/.git; then
gl_GCC_VERSION_IFELSE([11], [2], [gl_gcc_warnings=yes])
fi]
)
if test "$gl_gcc_warnings" = yes; then
gl_WARN_ADD([-Werror], [WERROR_CFLAGS])
AC_SUBST([WERROR_CFLAGS])
nw=
# This, $nw, is the list of warnings we disable.
nw="$nw -Wformat-nonliteral" # warnings in Fedora 17 stdio.h
nw="$nw -Wvla" # warnings in gettext.h
nw="$nw -Wswitch-default" # Too many warnings for now
nw="$nw -Wunsafe-loop-optimizations" # It's OK to omit unsafe optimizations.
nw="$nw -Winline" # It's OK to not inline.
nw="$nw -Wstrict-overflow" # It's OK to optimize strictly.
nw="$nw -Wsuggest-attribute=pure" # Too many warnings for now.
nw="$nw -Wstack-protector"
gl_MANYWARN_ALL_GCC([ws])
gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
for w in $ws; do
gl_WARN_ADD([$w])
done
gl_WARN_ADD([-Wno-sign-compare]) # Too many warnings for now
gl_WARN_ADD([-Wno-type-limits]) # It's OK to optimize based on types.
gl_WARN_ADD([-Wno-format-nonliteral])
gl_WARN_ADD([-fdiagnostics-show-option])
gl_WARN_ADD([-funit-at-a-time])
AC_SUBST([WARN_CFLAGS])
AC_DEFINE([lint], [1], [Define to 1 if the compiler is checking for lint.])
AH_VERBATIM([FORTIFY_SOURCE],
[/* Enable compile-time and run-time bounds-checking, and some warnings,
without upsetting glibc 2.15+. */
#if !defined _FORTIFY_SOURCE && defined __OPTIMIZE__ && __OPTIMIZE__
# define _FORTIFY_SOURCE 2
#endif
])
AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks])
# Use a slightly smaller set of warning options for lib/.
# Remove the following and save the result in GNULIB_WARN_CFLAGS.
nw=
nw="$nw -Wmissing-prototypes"
nw="$nw -Wunused-macros"
#
# These are for argp.
nw="$nw -Wmissing-field-initializers"
nw="$nw -Wshadow"
#
gl_MANYWARN_COMPLEMENT([GNULIB_WARN_CFLAGS], [$WARN_CFLAGS], [$nw])
# This is also for argp.
gl_WARN_ADD([-Wno-missing-field-initializers], [GNULIB_WARN_CFLAGS])
AC_SUBST([GNULIB_WARN_CFLAGS])
# For gnulib-tests, the set is slightly smaller still.
nw=
# It's not worth being this picky about test programs.
nw="$nw -Wsuggest-attribute=const"
gl_MANYWARN_COMPLEMENT([GNULIB_TEST_WARN_CFLAGS],
[$GNULIB_WARN_CFLAGS], [$nw])
AC_SUBST([GNULIB_TEST_WARN_CFLAGS])
fi
TAR_HEADERS_ATTR_XATTR_H
AC_CHECK_FUNCS_ONCE([fchmod fchown fsync mkfifo waitpid])
AC_ARG_VAR([RSH], [Configure absolute path to default remote shell binary])
AC_CACHE_CHECK(for remote shell, tar_cv_path_RSH,
[if test -n "$RSH"; then
tar_cv_path_RSH=$RSH
@@ -118,9 +249,7 @@ AC_CACHE_CHECK(for remote shell, tar_cv_path_RSH,
fi
done
fi])
if test $tar_cv_path_RSH = no; then
AC_CHECK_HEADERS(netdb.h)
else
if test $tar_cv_path_RSH != "no"; then
AC_DEFINE_UNQUOTED(REMOTE_SHELL, "$tar_cv_path_RSH",
[Define to the full path of your rsh, if any.])
fi
@@ -132,6 +261,7 @@ TAR_COMPR_PROGRAM(lzip)
TAR_COMPR_PROGRAM(lzma)
TAR_COMPR_PROGRAM(lzop)
TAR_COMPR_PROGRAM(xz)
TAR_COMPR_PROGRAM(zstd)
AC_MSG_CHECKING(for default archive format)
@@ -157,7 +287,7 @@ if test -z "$DEFAULT_ARCHIVE"; then
DEFAULT_ARCHIVE=-
else
if test -z "`ls $DEFAULT_ARCHIVE 2>/dev/null`"; then
AC_MSG_WARN(DEFAULT_ARCHIVE \`$DEFAULT_ARCHIVE' not found on this system)
AC_MSG_WARN(DEFAULT_ARCHIVE '$DEFAULT_ARCHIVE' not found on this system)
fi
# FIXME: Look for DEFTAPE in <sys/mtio.h>.
# FIXME: Let DEVICE_PREFIX be configured from the environment.
@@ -213,7 +343,7 @@ AC_DEFINE_UNQUOTED(DEFAULT_QUOTING_STYLE, $DEFAULT_QUOTING_STYLE,
# Iconv
AM_ICONV
AC_CHECK_HEADERS(iconv.h)
AC_CHECK_HEADERS_ONCE([iconv.h])
AC_CHECK_TYPE(iconv_t,:,
AC_DEFINE(iconv_t, int,
[Conversion descriptor type]),
@@ -225,7 +355,7 @@ AC_CHECK_TYPE(iconv_t,:,
# Gettext.
AM_GNU_GETTEXT([external], [need-formatstring-macros])
AM_GNU_GETTEXT_VERSION([0.16])
AM_GNU_GETTEXT_VERSION([0.21])
# Initialize the test suite.
AC_CONFIG_TESTDIR(tests)
@@ -235,8 +365,8 @@ AM_MISSING_PROG([AUTOM4TE], [autom4te])
AC_SUBST(BACKUP_LIBEXEC_SCRIPTS)
AC_SUBST(BACKUP_SBIN_SCRIPTS)
AC_ARG_ENABLE(backup-scripts,
AC_HELP_STRING([--enable-backup-scripts],
[Create and install backup and restore scripts]),
AS_HELP_STRING([--enable-backup-scripts],
[Create and install backup and restore scripts]),
[case $enableval in
yes) BACKUP_LIBEXEC_SCRIPTS='$(BACKUP_LIBEXEC_SCRIPTS_LIST)'
BACKUP_SBIN_SCRIPTS='$(BACKUP_SBIN_SCRIPTS_LIST)'
@@ -250,7 +380,7 @@ else
BACKUP_SED_COND='/^\#IF_DATE_FORMAT_OK/,/^\#ELSE_DATE_FORMAT_OK/d;/^\#ENDIF_DATE_FORMAT_OK/d'
fi
AC_OUTPUT([Makefile\
AC_CONFIG_FILES([Makefile\
doc/Makefile\
gnu/Makefile\
lib/Makefile\
@@ -258,3 +388,4 @@ AC_OUTPUT([Makefile\
scripts/Makefile\
rmt/Makefile\
src/Makefile])
AC_OUTPUT

View File

@@ -1,11 +1,11 @@
%%comments:
Copyright (C) 2004 Free Software Foundation, Inc.
Copyright 2004-2025 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2 or
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the file COPYING.
Texts. For a copy of the license, see <http://www.gnu.org/licenses/>.
%%name: tar
@@ -59,12 +59,12 @@ programs (using pipes); tar can even access remote devices or files
%%developers:
John Gilmore,
Thomas Bushnell,
Paul Eggert <eggert@twinsun.com>,
Sergey Poznyakoff <gray@Mirddin.farlep.net>
Paul Eggert <eggert@cs.ucla.edu>,
Sergey Poznyakoff <gray@gnu.org>
%%contributors: Jay Fenlason,
Joy Kendall,
Francois Pinard <pinard@iro.umontreal.ca>
François Pinard
%%source-tarball: ftp://ftp.gnu.org/pub/gnu/tar/tar-1.15.1.tar.gz
%%source-info: http://savannah.gnu.org/projects/tar

3
doc/.gitignore vendored
View File

@@ -1,7 +1,6 @@
genfile.texi
header.texi
manual
parse-datetime.texi
stamp-vti
tar.aux
tar.cp
@@ -24,3 +23,5 @@ tar.toc
tar.tp
tar.vr
version.texi
/parse-datetime.texi
/rmt.8

View File

@@ -1,40 +1,46 @@
# Makefile for GNU tar documentation.
# Copyright (C) 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2003, 2006,
# 2007 Free Software Foundation, Inc.
# Copyright 1994-2025 Free Software Foundation, Inc.
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3, or (at your option)
## any later version.
# This file is part of GNU tar.
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software Foundation,
## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
info_TEXINFOS = tar.texi
tar_TEXINFOS = \
dumpdir.texi\
tar-snapshot-edit.texi\
fdl.texi\
freemanuals.texi\
genfile.texi\
header.texi\
intern.texi\
parse-datetime.texi\
recipes.texi\
rendition.texi\
snapshot.texi\
sparse.texi\
value.texi
EXTRA_DIST = gendocs_template mastermenu.el texify.sed untabify.el
dist_man_MANS=tar.1 $(RMT_8)
if PU_RMT_COND
RMT_8=rmt.8
endif
EXTRA_DIST = gendocs_template mastermenu.el texify.sed untabify.el rmt.8
# The rendering level is anyone of PUBLISH, DISTRIB or PROOF.
# Just call `make RENDITION=PROOF [target]' if you want PROOF rendition.
# Just call 'make RENDITION=PROOF [target]' if you want PROOF rendition.
RENDITION = DISTRIB
MAKEINFOFLAGS=-D$(RENDITION)
@@ -132,9 +138,9 @@ check-docs:
clean-local:
rm -rf manual
GENDOCS=gendocs.sh
GENDOCS=$(srcdir)/gendocs.sh
TEXI2DVI=texi2dvi -t '@set $(RENDITION)' -E
TEXI2DVI=texi2dvi -E
# Make sure you set TEXINPUTS
# Usual value is:
@@ -142,5 +148,8 @@ TEXI2DVI=texi2dvi -t '@set $(RENDITION)' -E
manual:
TEXINPUTS=$(srcdir):$(top_srcdir)/build-tex:$(TEXINPUTS) \
MAKEINFO="$(MAKEINFO) $(MAKEINFOFLAGS)" \
TEXI2DVI="$(TEXI2DVI) -t @finalout" \
TEXI2DVI="$(TEXI2DVI) -t '@set DISTRIB' -t @finalout" \
$(GENDOCS) --texi2html tar 'GNU tar manual'
manual-rebuild: clean-local manual

91
doc/README.manual Normal file
View File

@@ -0,0 +1,91 @@
* Overview
This file is a short instruction for maintainers on how to create and
publish the online version of the Tar Manual.
In the sections below we assume that the tar project has been properly
cloned from the git repo, bootstrapped and configured. We also assume
that top-level directory of the project is the current local directory.
* Creating the web manual
To create the online version of the documentation, run
make -C doc manual-rebuild
This will create the directory doc/manual populated with the tar
documentation files in various formats. If the doc/manual directory
already exists, it will be removed prior to rebuilding.
The command produces very copious output. We advise you to examine it
closely to make sure no error messages slip your attention.
For the completeness sake, there are two more Makefile goals related
to the online manual:
** make -C doc clean-local
Removes the doc/manual directory, if it exists.
** make -C doc manual
Builds the doc/manual, unless it already exists.
* CVS Repository
The online tar manual[1] is a part of tar web pages[2] and is
traditionally maintained in the CVS repository[3]. To publish the
generated documentation, you will need first to check out tar web
pages from the CVS. To do so, run
cvs -z3 -d:ext:<username>@cvs.savannah.gnu.org:/web/tar co tar
where <username> is your user name on Savannah. For the rest of this
document we will assume that the checked out version of the tar web
pages resides in the ~/websrc/tar directory.
If you have already checked out the web pages, be sure to update them
before publishing:
cd ~/websrc/tar
cvs update
* Publishing
To publish the created manual, change to the tar top-level directory
and run:
rsync -avz --exclude CVS --delete manual ~/websrc/tar
This will synchronize the newly created manual pages with the content
of the CVS sandbox. Then, change to the ~/websrc/tar directory and
schedule any removed files for removal and any new files for addition
to the repository:
cvs diff --brief 2>&1 | sed -n 's/.*cannot find //p' | xargs cvs rm
cvs diff --brief 2>&1 | sed -n 's/^? //p' | xargs cvs add
Then commit your changes:
cvs commit
Once the changes are committed to CVS a job is scheduled on the server,
which synchronizes them with the content of the directory served by
the httpd daemon. Normally such synchronization happens within
several seconds from the commit.
For more information about CVS, please see its documentation[4].
* References
[1] https://www.gnu.org/software/tar/manual/
[2] https://www.gnu.org/software/tar/
[3] https://web.cvs.savannah.gnu.org/viewvc/tar/
[4] https://www.nongnu.org/cvs/#documentation
Local Variables:
mode: outline
paragraph-separate: "[ ]*$"
version-control: never
End:

View File

@@ -1,5 +1,5 @@
@c This is part of the paxutils manual.
@c Copyright (C) 2006, 2007 Free Software Foundation, Inc.
@c Copyright (C) 2006--2025 Free Software Foundation, Inc.
@c Written by Sergey Poznyakoff
@c This file is distributed under GFDL 1.1 or any later version
@c published by the Free Software Foundation.

View File

@@ -5,8 +5,9 @@
@c hence no sectioning command or @node.
@display
Copyright @copyright{} 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
@uref{http://fsf.org/}
Copyright @copyright{} 2000--2002, 2007--2008, 2022 Free Software
Foundation, Inc.
@uref{https://fsf.org/}
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@@ -97,7 +98,7 @@ format, SGML or XML using a publicly available
DTD, and standard-conforming simple HTML,
PostScript or PDF designed for human modification. Examples
of transparent image formats include PNG, XCF and
JPG. Opaque formats include proprietary formats that can be
JPG@. Opaque formats include proprietary formats that can be
read and edited only by proprietary word processors, SGML or
XML for which the DTD and/or processing tools are
not generally available, and the machine-generated HTML,
@@ -414,7 +415,7 @@ The Free Software Foundation may publish new, revised versions
of the GNU Free Documentation License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns. See
@uref{http://www.gnu.org/copyleft/}.
@uref{https://www.gnu.org/licenses/}.
Each version of the License is given a distinguishing version number.
If the Document specifies that a particular numbered version of this
@@ -481,7 +482,7 @@ license notices just after the title page:
@end smallexample
If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
replace the ``with@dots{}Texts.'' line with this:
replace the ``with@dots{}Texts.''@: line with this:
@smallexample
@group
@@ -503,4 +504,3 @@ to permit their use in free software.
@c Local Variables:
@c ispell-local-pdict: "ispell-dict"
@c End:

View File

@@ -1,89 +0,0 @@
@cindex free documentation
The biggest deficiency in the free software community today is not in
the software---it is the lack of good free documentation that we can
include with the free software. Many of our most important
programs do not come with free reference manuals and free introductory
texts. Documentation is an essential part of any software package;
when an important free software package does not come with a free
manual and a free tutorial, that is a major gap. We have many such
gaps today.
Consider Perl, for instance. The tutorial manuals that people
normally use are non-free. How did this come about? Because the
authors of those manuals published them with restrictive terms---no
copying, no modification, source files not available---which exclude
them from the free software world.
That wasn't the first time this sort of thing happened, and it was far
from the last. Many times we have heard a GNU user eagerly describe a
manual that he is writing, his intended contribution to the community,
only to learn that he had ruined everything by signing a publication
contract to make it non-free.
Free documentation, like free software, is a matter of freedom, not
price. The problem with the non-free manual is not that publishers
charge a price for printed copies---that in itself is fine. (The Free
Software Foundation sells printed copies of manuals, too.) The
problem is the restrictions on the use of the manual. Free manuals
are available in source code form, and give you permission to copy and
modify. Non-free manuals do not allow this.
The criteria of freedom for a free manual are roughly the same as for
free software. Redistribution (including the normal kinds of
commercial redistribution) must be permitted, so that the manual can
accompany every copy of the program, both on-line and on paper.
Permission for modification of the technical content is crucial too.
When people modify the software, adding or changing features, if they
are conscientious they will change the manual too---so they can
provide accurate and clear documentation for the modified program. A
manual that leaves you no choice but to write a new manual to document
a changed version of the program is not really available to our
community.
Some kinds of limits on the way modification is handled are
acceptable. For example, requirements to preserve the original
author's copyright notice, the distribution terms, or the list of
authors, are ok. It is also no problem to require modified versions
to include notice that they were modified. Even entire sections that
may not be deleted or changed are acceptable, as long as they deal
with nontechnical topics (like this one). These kinds of restrictions
are acceptable because they don't obstruct the community's normal use
of the manual.
However, it must be possible to modify all the @emph{technical}
content of the manual, and then distribute the result in all the usual
media, through all the usual channels. Otherwise, the restrictions
obstruct the use of the manual, it is not free, and we need another
manual to replace it.
Please spread the word about this issue. Our community continues to
lose manuals to proprietary publishing. If we spread the word that
free software needs free reference manuals and free tutorials, perhaps
the next person who wants to contribute by writing documentation will
realize, before it is too late, that only free manuals contribute to
the free software community.
If you are writing documentation, please insist on publishing it under
the GNU Free Documentation License or another free documentation
license. Remember that this decision requires your approval---you
don't have to let the publisher decide. Some commercial publishers
will use a free license if you insist, but they will not propose the
option; it is up to you to raise the issue and say firmly that this is
what you want. If the publisher you are dealing with refuses, please
try other publishers. If you're not sure whether a proposed license
is free, write to @email{licensing@@gnu.org}.
You can encourage commercial publishers to sell more free, copylefted
manuals and tutorials by buying them, and particularly by buying
copies from the publishers that paid for their writing or for major
improvements. Meanwhile, try to avoid buying non-free documentation
at all. Check the distribution terms of a manual before you buy it,
and insist that whoever seeks your business must respect your freedom.
Check the history of the book, and try reward the publishers that have
paid or pay the authors to work on it.
The Free Software Foundation maintains a list of free documentation
published by other publishers, at
@url{http://www.fsf.org/doc/other-free-books.html}.

512
doc/gendocs.sh Executable file
View File

@@ -0,0 +1,512 @@
#!/bin/sh -e
# gendocs.sh -- generate a GNU manual in many formats. This script is
# mentioned in maintain.texi. See the help message below for usage details.
scriptversion=2021-03-01.13
# Copyright 2003-2025 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Original author: Mohit Agarwal.
# Send bug reports and any other correspondence to bug-gnulib@gnu.org.
#
# The latest version of this script, and the companion template, is
# available from the Gnulib repository:
#
# https://git.savannah.gnu.org/cgit/gnulib.git/tree/build-aux/gendocs.sh
# https://git.savannah.gnu.org/cgit/gnulib.git/tree/doc/gendocs_template
# TODO:
# - image importing was only implemented for HTML generated by
# makeinfo. But it should be simple enough to adjust.
# - images are not imported in the source tarball. All the needed
# formats (PDF, PNG, etc.) should be included.
prog=`basename "$0"`
srcdir=`pwd`
scripturl="https://git.savannah.gnu.org/cgit/gnulib.git/plain/build-aux/gendocs.sh"
templateurl="https://git.savannah.gnu.org/cgit/gnulib.git/plain/doc/gendocs_template"
: ${SETLANG="env LANG= LC_MESSAGES= LC_ALL= LANGUAGE="}
: ${MAKEINFO="makeinfo"}
: ${TEXI2DVI="texi2dvi"}
: ${DOCBOOK2HTML="docbook2html"}
: ${DOCBOOK2PDF="docbook2pdf"}
: ${DOCBOOK2TXT="docbook2txt"}
: ${GENDOCS_TEMPLATE_DIR="."}
: ${PERL='perl'}
: ${TEXI2HTML="texi2html"}
unset CDPATH
unset use_texi2html
MANUAL_TITLE=
PACKAGE=
EMAIL=webmasters@gnu.org # please override with --email
commonarg= # passed to all makeinfo/texi2html invcations.
dirargs= # passed to all tools (-I dir).
dirs= # -I directories.
htmlarg="--css-ref=/software/gnulib/manual.css -c TOP_NODE_UP_URL=/manual"
default_htmlarg=true
infoarg=--no-split
generate_ascii=true
generate_html=true
generate_info=true
generate_tex=true
outdir=manual
source_extra=
split=node
srcfile=
texarg="-t @finalout"
version="gendocs.sh $scriptversion
Copyright 2021, 2025 Free Software Foundation, Inc.
There is NO warranty. You may redistribute this software
under the terms of the GNU General Public License.
For more information about these matters, see the files named COPYING."
usage="Usage: $prog [OPTION]... PACKAGE MANUAL-TITLE
Generate output in various formats from PACKAGE.texinfo (or .texi or
.txi) source. See the GNU Maintainers document for a more extensive
discussion:
https://www.gnu.org/prep/maintain_toc.html
Options:
--email ADR use ADR as contact in generated web pages; always give this.
-s SRCFILE read Texinfo from SRCFILE, instead of PACKAGE.{texinfo|texi|txi}
-o OUTDIR write files into OUTDIR, instead of manual/.
-I DIR append DIR to the Texinfo search path.
--common ARG pass ARG in all invocations.
--html ARG pass ARG to makeinfo or texi2html for HTML targets,
instead of '$htmlarg'.
--info ARG pass ARG to makeinfo for Info, instead of --no-split.
--no-ascii skip generating the plain text output.
--no-html skip generating the html output.
--no-info skip generating the info output.
--no-tex skip generating the dvi and pdf output.
--source ARG include ARG in tar archive of sources.
--split HOW make split HTML by node, section, chapter; default node.
--tex ARG pass ARG to texi2dvi for DVI and PDF, instead of -t @finalout.
--texi2html use texi2html to make HTML target, with all split versions.
--docbook convert through DocBook too (xml, txt, html, pdf).
--help display this help and exit successfully.
--version display version information and exit successfully.
Simple example: $prog --email bug-gnu-emacs@gnu.org emacs \"GNU Emacs Manual\"
Typical sequence:
cd PACKAGESOURCE/doc
wget \"$scripturl\"
wget \"$templateurl\"
$prog --email BUGLIST MANUAL \"GNU MANUAL - One-line description\"
Output will be in a new subdirectory \"manual\" (by default;
use -o OUTDIR to override). Move all the new files into your web CVS
tree, as explained in the Web Pages node of maintain.texi.
Please use the --email ADDRESS option so your own bug-reporting
address will be used in the generated HTML pages.
MANUAL-TITLE is included as part of the HTML <title> of the overall
manual/index.html file. It should include the name of the package being
documented. manual/index.html is created by substitution from the file
$GENDOCS_TEMPLATE_DIR/gendocs_template. (Feel free to modify the
generic template for your own purposes.)
If you have several manuals, you'll need to run this script several
times with different MANUAL values, specifying a different output
directory with -o each time. Then write (by hand) an overall index.html
with links to them all.
If a manual's Texinfo sources are spread across several directories,
first copy or symlink all Texinfo sources into a single directory.
(Part of the script's work is to make a tar.gz of the sources.)
As implied above, by default monolithic Info files are generated.
If you want split Info, or other Info options, use --info to override.
You can set the environment variables MAKEINFO, TEXI2DVI, TEXI2HTML,
and PERL to control the programs that get executed, and
GENDOCS_TEMPLATE_DIR to control where the gendocs_template file is
looked for. With --docbook, the environment variables DOCBOOK2HTML,
DOCBOOK2PDF, and DOCBOOK2TXT are also consulted.
By default, makeinfo and texi2dvi are run in the default (English)
locale, since that's the language of most Texinfo manuals. If you
happen to have a non-English manual and non-English web site, see the
SETLANG setting in the source.
Email bug reports or enhancement requests to bug-gnulib@gnu.org.
"
while test $# -gt 0; do
case $1 in
-s) shift; srcfile=$1;;
-o) shift; outdir=$1;;
-I) shift; dirargs="$dirargs -I '$1'"; dirs="$dirs $1";;
--common) shift; commonarg=$1;;
--docbook) docbook=yes;;
--email) shift; EMAIL=$1;;
--html) shift; default_htmlarg=false; htmlarg=$1;;
--info) shift; infoarg=$1;;
--no-ascii) generate_ascii=false;;
--no-html) generate_ascii=false;;
--no-info) generate_info=false;;
--no-tex) generate_tex=false;;
--source) shift; source_extra=$1;;
--split) shift; split=$1;;
--tex) shift; texarg=$1;;
--texi2html) use_texi2html=1;;
--help) echo "$usage"; exit 0;;
--version) echo "$version"; exit 0;;
-*)
echo "$0: Unknown option \`$1'." >&2
echo "$0: Try \`--help' for more information." >&2
exit 1;;
*)
if test -z "$PACKAGE"; then
PACKAGE=$1
elif test -z "$MANUAL_TITLE"; then
MANUAL_TITLE=$1
else
echo "$0: extra non-option argument \`$1'." >&2
exit 1
fi;;
esac
shift
done
# makeinfo uses the dirargs, but texi2dvi doesn't.
commonarg=" $dirargs $commonarg"
# For most of the following, the base name is just $PACKAGE
base=$PACKAGE
if $default_htmlarg && test -n "$use_texi2html"; then
# The legacy texi2html doesn't support TOP_NODE_UP_URL
htmlarg="--css-ref=/software/gnulib/manual.css"
fi
if test -n "$srcfile"; then
# but here, we use the basename of $srcfile
base=`basename "$srcfile"`
case $base in
*.txi|*.texi|*.texinfo) base=`echo "$base"|sed 's/\.[texinfo]*$//'`;;
esac
PACKAGE=$base
elif test -s "$srcdir/$PACKAGE.texinfo"; then
srcfile=$srcdir/$PACKAGE.texinfo
elif test -s "$srcdir/$PACKAGE.texi"; then
srcfile=$srcdir/$PACKAGE.texi
elif test -s "$srcdir/$PACKAGE.txi"; then
srcfile=$srcdir/$PACKAGE.txi
else
echo "$0: cannot find .texinfo or .texi or .txi for $PACKAGE in $srcdir." >&2
exit 1
fi
if test ! -r $GENDOCS_TEMPLATE_DIR/gendocs_template; then
echo "$0: cannot read $GENDOCS_TEMPLATE_DIR/gendocs_template." >&2
echo "$0: it is available from $templateurl." >&2
exit 1
fi
# Function to return size of $1 in something resembling kilobytes.
calcsize()
{
size=`ls -ksl $1 | awk '{print $1}'`
echo $size
}
# copy_images OUTDIR HTML-FILE...
# -------------------------------
# Copy all the images needed by the HTML-FILEs into OUTDIR.
# Look for them in . and the -I directories; this is simpler than what
# makeinfo supports with -I, but hopefully it will suffice.
copy_images()
{
local odir
odir=$1
shift
$PERL -n -e "
BEGIN {
\$me = '$prog';
\$odir = '$odir';
@dirs = qw(. $dirs);
}
" -e '
/<img src="(.*?)"/g && ++$need{$1};
END {
#print "$me: @{[keys %need]}\n"; # for debugging, show images found.
FILE: for my $f (keys %need) {
for my $d (@dirs) {
if (-f "$d/$f") {
use File::Basename;
my $dest = dirname ("$odir/$f");
#
use File::Path;
-d $dest || mkpath ($dest)
|| die "$me: cannot mkdir $dest: $!\n";
#
use File::Copy;
copy ("$d/$f", $dest)
|| die "$me: cannot copy $d/$f to $dest: $!\n";
next FILE;
}
}
die "$me: $ARGV: cannot find image $f\n";
}
}
' -- "$@" || exit 1
}
case $outdir in
/*) abs_outdir=$outdir;;
*) abs_outdir=$srcdir/$outdir;;
esac
echo "Making output for $srcfile"
echo " in `pwd`"
mkdir -p "$outdir/"
#
if $generate_info; then
cmd="$SETLANG $MAKEINFO -o $PACKAGE.info $commonarg $infoarg \"$srcfile\""
echo "Generating info... ($cmd)"
rm -f $PACKAGE.info* # get rid of any strays
eval "$cmd"
tar czf "$outdir/$PACKAGE.info.tar.gz" $PACKAGE.info*
ls -l "$outdir/$PACKAGE.info.tar.gz"
info_tgz_size=`calcsize "$outdir/$PACKAGE.info.tar.gz"`
# do not mv the info files, there's no point in having them available
# separately on the web.
fi # end info
#
if $generate_tex; then
cmd="$SETLANG $TEXI2DVI $dirargs $texarg \"$srcfile\""
printf "\nGenerating dvi... ($cmd)\n"
eval "$cmd"
# compress/finish dvi:
gzip -f -9 $PACKAGE.dvi
dvi_gz_size=`calcsize $PACKAGE.dvi.gz`
mv $PACKAGE.dvi.gz "$outdir/"
ls -l "$outdir/$PACKAGE.dvi.gz"
cmd="$SETLANG $TEXI2DVI --pdf $dirargs $texarg \"$srcfile\""
printf "\nGenerating pdf... ($cmd)\n"
eval "$cmd"
pdf_size=`calcsize $PACKAGE.pdf`
mv $PACKAGE.pdf "$outdir/"
ls -l "$outdir/$PACKAGE.pdf"
fi # end tex (dvi + pdf)
#
if $generate_ascii; then
opt="-o $PACKAGE.txt --no-split --no-headers $commonarg"
cmd="$SETLANG $MAKEINFO $opt \"$srcfile\""
printf "\nGenerating ascii... ($cmd)\n"
eval "$cmd"
ascii_size=`calcsize $PACKAGE.txt`
gzip -f -9 -c $PACKAGE.txt >"$outdir/$PACKAGE.txt.gz"
ascii_gz_size=`calcsize "$outdir/$PACKAGE.txt.gz"`
mv $PACKAGE.txt "$outdir/"
ls -l "$outdir/$PACKAGE.txt" "$outdir/$PACKAGE.txt.gz"
fi
#
if $generate_html; then
# Split HTML at level $1. Used for texi2html.
html_split()
{
opt="--split=$1 --node-files $commonarg $htmlarg"
cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html $opt \"$srcfile\""
printf "\nGenerating html by $1... ($cmd)\n"
eval "$cmd"
split_html_dir=$PACKAGE.html
(
cd ${split_html_dir} || exit 1
if [ ! -f index.html ]; then
ln -sf ${PACKAGE}.html index.html
fi
tar -czf "$abs_outdir/${PACKAGE}.html_$1.tar.gz" -- *.html
)
eval html_$1_tgz_size=`calcsize "$outdir/${PACKAGE}.html_$1.tar.gz"`
rm -f "$outdir"/html_$1/*.html
mkdir -p "$outdir/html_$1/"
mv ${split_html_dir}/*.html "$outdir/html_$1/"
rmdir ${split_html_dir}
}
if test -z "$use_texi2html"; then
opt="--no-split --html -o $PACKAGE.html $commonarg $htmlarg"
cmd="$SETLANG $MAKEINFO $opt \"$srcfile\""
printf "\nGenerating monolithic html... ($cmd)\n"
rm -rf $PACKAGE.html # in case a directory is left over
eval "$cmd"
html_mono_size=`calcsize $PACKAGE.html`
gzip -f -9 -c $PACKAGE.html >"$outdir/$PACKAGE.html.gz"
html_mono_gz_size=`calcsize "$outdir/$PACKAGE.html.gz"`
copy_images "$outdir/" $PACKAGE.html
mv $PACKAGE.html "$outdir/"
ls -l "$outdir/$PACKAGE.html" "$outdir/$PACKAGE.html.gz"
# Before Texinfo 5.0, makeinfo did not accept a --split=HOW option,
# it just always split by node. So if we're splitting by node anyway,
# leave it out.
if test "x$split" = xnode; then
split_arg=
else
split_arg=--split=$split
fi
#
opt="--html -o $PACKAGE.html $split_arg $commonarg $htmlarg"
cmd="$SETLANG $MAKEINFO $opt \"$srcfile\""
printf "\nGenerating html by $split... ($cmd)\n"
eval "$cmd"
split_html_dir=$PACKAGE.html
copy_images $split_html_dir/ $split_html_dir/*.html
(
cd $split_html_dir || exit 1
tar -czf "$abs_outdir/$PACKAGE.html_$split.tar.gz" -- *
)
eval \
html_${split}_tgz_size=`calcsize "$outdir/$PACKAGE.html_$split.tar.gz"`
rm -rf "$outdir/html_$split/"
mv $split_html_dir "$outdir/html_$split/"
du -s "$outdir/html_$split/"
ls -l "$outdir/$PACKAGE.html_$split.tar.gz"
else # use texi2html:
opt="--output $PACKAGE.html $commonarg $htmlarg"
cmd="$SETLANG $TEXI2HTML $opt \"$srcfile\""
printf "\nGenerating monolithic html with texi2html... ($cmd)\n"
rm -rf $PACKAGE.html # in case a directory is left over
eval "$cmd"
html_mono_size=`calcsize $PACKAGE.html`
gzip -f -9 -c $PACKAGE.html >"$outdir/$PACKAGE.html.gz"
html_mono_gz_size=`calcsize "$outdir/$PACKAGE.html.gz"`
mv $PACKAGE.html "$outdir/"
html_split node
html_split chapter
html_split section
fi
fi # end html
#
printf "\nMaking .tar.gz for sources...\n"
d=`dirname $srcfile`
(
cd "$d"
srcfiles=`ls -d *.texinfo *.texi *.txi *.eps $source_extra 2>/dev/null` || true
tar czfh "$abs_outdir/$PACKAGE.texi.tar.gz" $srcfiles
ls -l "$abs_outdir/$PACKAGE.texi.tar.gz"
)
texi_tgz_size=`calcsize "$outdir/$PACKAGE.texi.tar.gz"`
#
# Do everything again through docbook.
if test -n "$docbook"; then
opt="-o - --docbook $commonarg"
cmd="$SETLANG $MAKEINFO $opt \"$srcfile\" >${srcdir}/$PACKAGE-db.xml"
printf "\nGenerating docbook XML... ($cmd)\n"
eval "$cmd"
docbook_xml_size=`calcsize $PACKAGE-db.xml`
gzip -f -9 -c $PACKAGE-db.xml >"$outdir/$PACKAGE-db.xml.gz"
docbook_xml_gz_size=`calcsize "$outdir/$PACKAGE-db.xml.gz"`
mv $PACKAGE-db.xml "$outdir/"
split_html_db_dir=html_node_db
opt="$commonarg -o $split_html_db_dir"
cmd="$DOCBOOK2HTML $opt \"${outdir}/$PACKAGE-db.xml\""
printf "\nGenerating docbook HTML... ($cmd)\n"
eval "$cmd"
(
cd ${split_html_db_dir} || exit 1
tar -czf "$abs_outdir/${PACKAGE}.html_node_db.tar.gz" -- *.html
)
html_node_db_tgz_size=`calcsize "$outdir/${PACKAGE}.html_node_db.tar.gz"`
rm -f "$outdir"/html_node_db/*.html
mkdir -p "$outdir/html_node_db"
mv ${split_html_db_dir}/*.html "$outdir/html_node_db/"
rmdir ${split_html_db_dir}
cmd="$DOCBOOK2TXT \"${outdir}/$PACKAGE-db.xml\""
printf "\nGenerating docbook ASCII... ($cmd)\n"
eval "$cmd"
docbook_ascii_size=`calcsize $PACKAGE-db.txt`
mv $PACKAGE-db.txt "$outdir/"
cmd="$DOCBOOK2PDF \"${outdir}/$PACKAGE-db.xml\""
printf "\nGenerating docbook PDF... ($cmd)\n"
eval "$cmd"
docbook_pdf_size=`calcsize $PACKAGE-db.pdf`
mv $PACKAGE-db.pdf "$outdir/"
fi
#
printf "\nMaking index.html for $PACKAGE...\n"
if test -z "$use_texi2html"; then
CONDS="/%%IF *HTML_SECTION%%/,/%%ENDIF *HTML_SECTION%%/d;\
/%%IF *HTML_CHAPTER%%/,/%%ENDIF *HTML_CHAPTER%%/d"
else
# should take account of --split here.
CONDS="/%%ENDIF.*%%/d;/%%IF *HTML_SECTION%%/d;/%%IF *HTML_CHAPTER%%/d"
fi
curdate=`$SETLANG date '+%B %d, %Y'`
sed \
-e "s!%%TITLE%%!$MANUAL_TITLE!g" \
-e "s!%%EMAIL%%!$EMAIL!g" \
-e "s!%%PACKAGE%%!$PACKAGE!g" \
-e "s!%%DATE%%!$curdate!g" \
-e "s!%%HTML_MONO_SIZE%%!$html_mono_size!g" \
-e "s!%%HTML_MONO_GZ_SIZE%%!$html_mono_gz_size!g" \
-e "s!%%HTML_NODE_TGZ_SIZE%%!$html_node_tgz_size!g" \
-e "s!%%HTML_SECTION_TGZ_SIZE%%!$html_section_tgz_size!g" \
-e "s!%%HTML_CHAPTER_TGZ_SIZE%%!$html_chapter_tgz_size!g" \
-e "s!%%INFO_TGZ_SIZE%%!$info_tgz_size!g" \
-e "s!%%DVI_GZ_SIZE%%!$dvi_gz_size!g" \
-e "s!%%PDF_SIZE%%!$pdf_size!g" \
-e "s!%%ASCII_SIZE%%!$ascii_size!g" \
-e "s!%%ASCII_GZ_SIZE%%!$ascii_gz_size!g" \
-e "s!%%TEXI_TGZ_SIZE%%!$texi_tgz_size!g" \
-e "s!%%DOCBOOK_HTML_NODE_TGZ_SIZE%%!$html_node_db_tgz_size!g" \
-e "s!%%DOCBOOK_ASCII_SIZE%%!$docbook_ascii_size!g" \
-e "s!%%DOCBOOK_PDF_SIZE%%!$docbook_pdf_size!g" \
-e "s!%%DOCBOOK_XML_SIZE%%!$docbook_xml_size!g" \
-e "s!%%DOCBOOK_XML_GZ_SIZE%%!$docbook_xml_gz_size!g" \
-e "s,%%SCRIPTURL%%,$scripturl,g" \
-e "s!%%SCRIPTNAME%%!$prog!g" \
-e "$CONDS" \
$GENDOCS_TEMPLATE_DIR/gendocs_template >"$outdir/index.html"
echo "Done, see $outdir/ subdirectory for new files."
# Local variables:
# eval: (add-hook 'before-save-hook 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$"
# End:

174
doc/gendocs_template Executable file → Normal file
View File

@@ -1,125 +1,101 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- $Id: gendocs_template,v 1.5 2007/10/30 14:58:52 gray Exp $ -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<!--#include virtual="/server/header.html" -->
<!-- Parent-Version: 1.78 -->
<head>
<title>%%TITLE%% - GNU Project - Free Software Foundation (FSF)</title>
<meta http-equiv="content-type" content='text/html; charset=utf-8' />
<link rel="stylesheet" type="text/css" href="/gnu.css" />
<link rev="made" href="mailto:gray@gnu.org" />
<link rel="icon" type="image/png" href="/graphics/gnu-head-icon.png" />
</head>
<!--
Copyright (C) 2006-2025 Free Software Foundation, Inc.
<!-- This document is in XML, and xhtml 1.0 -->
<!-- Please make sure to properly nest your tags -->
<!-- and ensure that your final document validates -->
<!-- consistent with W3C xhtml 1.0 and CSS standards -->
<!-- See validator.w3.org -->
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. This file is offered as-is,
without any warranty.
-->
<body>
<h3>%%TITLE%%</h3>
<title>%%TITLE%% - GNU Project - Free Software Foundation</title>
<!--#include virtual="/server/banner.html" -->
<h2>%%TITLE%%</h2>
<address>Free Software Foundation</address>
<address>last updated %%DATE%%</address>
<p>
<a href="/graphics/gnu-head.jpg">
<img src="/graphics/gnu-head-sm.jpg"
alt=" [image of the head of a GNU] "
width="129" height="122" />
</a>
</p>
<hr />
<p>The manual for %%PACKAGE%% is available in the following formats:</p>
<p>This manual (%%PACKAGE%%) is available in the following formats:</p>
<ul>
<li><a href="%%PACKAGE%%.html">HTML
(%%HTML_MONO_SIZE%%K bytes)</a> - entirely on one web page.</li>
<li><a href="html_node/index.html">HTML</a> - with one web page per
node.</li>
<li><a href="%%PACKAGE%%.html">HTML
(%%HTML_MONO_SIZE%%K bytes)</a> - entirely on one web page.</li>
<li><a href="html_node/index.html">HTML</a> - with one web page per
node.</li>
%%IF HTML_SECTION%%
<li><a href="html_section/index.html">HTML</a> - with one web page per
section.</li>
<li><a href="html_section/index.html">HTML</a> - with one web page per
section.</li>
%%ENDIF HTML_SECTION%%
%%IF HTML_CHAPTER%%
<li><a href="html_chapter/index.html">HTML</a> - with one web page per
chapter.</li>
<li><a href="html_chapter/index.html">HTML</a> - with one web page per
chapter.</li>
%%ENDIF HTML_CHAPTER%%
<li><a href="%%PACKAGE%%.html.gz">HTML compressed
(%%HTML_MONO_GZ_SIZE%%K gzipped characters)</a> - entirely on
one web page.</li>
<li><a href="%%PACKAGE%%.html_node.tar.gz">HTML compressed
(%%HTML_NODE_TGZ_SIZE%%K gzipped tar file)</a> -
with one web page per node.</li>
<li><a href="%%PACKAGE%%.html.gz">HTML compressed
(%%HTML_MONO_GZ_SIZE%%K gzipped characters)</a> - entirely on
one web page.</li>
<li><a href="%%PACKAGE%%.html_node.tar.gz">HTML compressed
(%%HTML_NODE_TGZ_SIZE%%K gzipped tar file)</a> -
with one web page per node.</li>
%%IF HTML_SECTION%%
<li><a href="%%PACKAGE%%.html_section.tar.gz">HTML compressed
(%%HTML_SECTION_TGZ_SIZE%%K gzipped tar file)</a> -
with one web page per section.</li>
<li><a href="%%PACKAGE%%.html_section.tar.gz">HTML compressed
(%%HTML_SECTION_TGZ_SIZE%%K gzipped tar file)</a> -
with one web page per section.</li>
%%ENDIF HTML_SECTION%%
%%IF HTML_CHAPTER%%
<li><a href="%%PACKAGE%%.html_chapter.tar.gz">HTML compressed
(%%HTML_CHAPTER_TGZ_SIZE%%K gzipped tar file)</a> -
with one web page per chapter.</li>
<li><a href="%%PACKAGE%%.html_chapter.tar.gz">HTML compressed
(%%HTML_CHAPTER_TGZ_SIZE%%K gzipped tar file)</a> -
with one web page per chapter.</li>
%%ENDIF HTML_CHAPTER%%
<li><a href="%%PACKAGE%%.info.tar.gz">Info document
(%%INFO_TGZ_SIZE%%K characters gzipped tar file)</a>.</li>
<li><a href="%%PACKAGE%%.txt">ASCII text
(%%ASCII_SIZE%%K characters)</a>.</li>
<li><a href="%%PACKAGE%%.txt.gz">ASCII text compressed
(%%ASCII_GZ_SIZE%%K gzipped characters)</a>.</li>
<li><a href="%%PACKAGE%%.dvi.gz">TeX dvi file
(%%DVI_GZ_SIZE%%K characters gzipped)</a>.</li>
<li><a href="%%PACKAGE%%.ps.gz">PostScript file
(%%PS_GZ_SIZE%%K characters gzipped)</a>.</li>
<li><a href="%%PACKAGE%%.pdf">PDF file
(%%PDF_SIZE%%K characters)</a>.</li>
<li><a href="%%PACKAGE%%.texi.tar.gz">Texinfo source
(%%TEXI_TGZ_SIZE%%K characters gzipped tar file)</a></li>
<li><a href="%%PACKAGE%%.info.tar.gz">Info document
(%%INFO_TGZ_SIZE%%K bytes gzipped tar file)</a>.</li>
<li><a href="%%PACKAGE%%.txt">ASCII text
(%%ASCII_SIZE%%K bytes)</a>.</li>
<li><a href="%%PACKAGE%%.txt.gz">ASCII text compressed
(%%ASCII_GZ_SIZE%%K bytes gzipped)</a>.</li>
<li><a href="%%PACKAGE%%.dvi.gz">TeX dvi file
(%%DVI_GZ_SIZE%%K bytes gzipped)</a>.</li>
<li><a href="%%PACKAGE%%.pdf">PDF file
(%%PDF_SIZE%%K bytes)</a>.</li>
<li><a href="%%PACKAGE%%.texi.tar.gz">Texinfo source
(%%TEXI_TGZ_SIZE%%K bytes gzipped tar file).</a></li>
</ul>
<p>(This page generated by the <a
href="%%SCRIPTURL%%">%%SCRIPTNAME%%</a> script.)
</p>
<p>You can <a href="https://shop.fsf.org/">buy printed copies of
some manuals</a> (among other items) from the Free Software Foundation;
this helps support FSF activities.</p>
<p>
<a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0!" height="31" width="88" /></a>
</p>
<p>(This page generated by the <a href="%%SCRIPTURL%%">%%SCRIPTNAME%%
script</a>.)</p>
<div class="copyright">
<p>
Return to the <a href="/home.html">GNU Project home page</a>.
</p>
<!-- If needed, change the copyright block at the bottom. In general,
all pages on the GNU web server should have the section about
verbatim copying. Please do NOT remove this without talking
with the webmasters first.
Please make sure the copyright date is consistent with the document
and that it is like this: "2001, 2002", not this: "2001-2002". -->
</div><!-- for id="content", starts in the include above -->
<!--#include virtual="/server/footer.html" -->
<div id="footer">
<div class="unprintable">
<p>
Please send FSF &amp; GNU inquiries to
<a href="mailto:gnu@gnu.org"><em>gnu@gnu.org</em></a>.
There are also <a href="/home.html#ContactInfo">other ways to contact</a>
the FSF.
<br />
Please send broken links and other corrections (or suggestions) to
<a href="mailto:webmasters@gnu.org"><em>webmasters@gnu.org</em></a>.
</p>
<p>
Copyright (C) 2004 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02111, USA
<br />
Verbatim copying and distribution of this entire article is
permitted in any medium, provided this notice is preserved.
</p>
<p>
Updated:
<!-- timestamp start -->
$Date: 2007/10/30 14:58:52 $ $Author: gray $
<!-- timestamp end -->
</p>
<p>Please send general FSF &amp; GNU inquiries to
<a href="mailto:gnu@gnu.org">&lt;gnu@gnu.org&gt;</a>.
There are also <a href="/contact/">other ways to contact</a>
the FSF. Broken links and other corrections or suggestions can be sent
to <a href="mailto:%%EMAIL%%">&lt;%%EMAIL%%&gt;</a>.</p>
</div>
<p>Copyright &copy; 2020, 2025 Free Software Foundation, Inc.</p>
<p>This page is licensed under a <a rel="license"
href="https://creativecommons.org/licenses/by-nd/3.0/us/">Creative
Commons Attribution-NoDerivs 3.0 United States License</a>.</p>
<!--#include virtual="/server/bottom-notes.html" -->
</div>
</div>
</body>
</html>

View File

@@ -1,5 +1,5 @@
@c This is part of the paxutils manual.
@c Copyright (C) 2006 Free Software Foundation, Inc.
@c Copyright (C) 2006--2025 Free Software Foundation, Inc.
@c This file is distributed under GFDL 1.1 or any later version
@c published by the Free Software Foundation.
@@ -13,7 +13,7 @@
@node Standard
@unnumberedsec Basic Tar Format
@UNREVISED
@UNREVISED{}
While an archive may contain many files, the archive itself is a
single ordinary file. Like any other file, an archive file can be
@@ -51,7 +51,10 @@ of the file. At the end of the archive file there are two 512-byte blocks
filled with binary zeros as an end-of-file marker. A reasonable system
should write such end-of-file marker at the end of an archive, but
must not assume that such a block exists when reading an archive. In
particular @GNUTAR{} always issues a warning if it does not encounter it.
particular, @GNUTAR{} does not treat missing end-of-file marker as an
error and silently ignores the fact. You can instruct it to issue
a warning, however, by using the @option{--warning=missing-zero-blocks}
option (@pxref{General Warnings, missing-zero-blocks}).
The blocks may be @dfn{blocked} for physical I/O operations.
Each record of @var{n} blocks (where @var{n} is set by the
@@ -87,6 +90,8 @@ The @code{name}, @code{linkname}, @code{magic}, @code{uname}, and
@code{gname} are null-terminated character strings. All other fields
are zero-filled octal numbers in ASCII. Each numeric field of width
@var{w} contains @var{w} minus 1 digits, and a null.
(In the extended @acronym{GNU} format, the numeric fields can take
other forms.)
The @code{name} field is the file name of the file, with directory names
(if any) preceding the file name, separated by slashes.
@@ -109,21 +114,20 @@ The @code{uid} and @code{gid} fields are the numeric user and group
not support numeric user or group @acronym{ID}s, these fields should
be ignored.
The @code{size} field is the size of the file in bytes; linked files
are archived with this field specified as zero.
The @code{size} field is the size of the file in bytes; for archive
members that are symbolic or hard links to another file, this field
is specified as zero.
The @code{mtime} field is the data modification time of the file at
the time it was archived. It is the ASCII representation of the octal
value of the last time the file's contents were modified, represented
as an integer number of
The @code{mtime} field represents the data modification time of the file at
the time it was archived. It represents the integer number of
seconds since January 1, 1970, 00:00 Coordinated Universal Time.
The @code{chksum} field is the ASCII representation of the octal value
of the simple sum of all bytes in the header block. Each 8-bit
The @code{chksum} field represents
the simple sum of all bytes in the header block. Each 8-bit
byte in the header is added to an unsigned integer, initialized to
zero, the precision of which shall be no less than seventeen bits.
When calculating the checksum, the @code{chksum} field is treated as
if it were all blanks.
if it were filled with spaces (ASCII 32).
The @code{typeflag} field specifies the type of file archived. If a
particular implementation does not recognize or permit the specified
@@ -266,7 +270,7 @@ IEEE Std 1003.2-1992, pages 380-388 (section 4.48) and pages 936-940
@node Extensions
@unnumberedsec @acronym{GNU} Extensions to the Archive Format
@UNREVISED
@UNREVISED{}
The @acronym{GNU} format uses additional file types to describe new types of
files in an archive. These are listed below.
@@ -310,6 +314,18 @@ of an archive should have this type.
@end table
For fields containing numbers or timestamps that are out of range for
the basic format, the @acronym{GNU} format uses a base-256
representation instead of an ASCII octal number. If the leading byte
is 0xff (255), all the bytes of the field (including the leading byte)
are concatenated in big-endian order, with the result being a negative
number expressed in two's complement form. If the leading byte is
0x80 (128), the non-leading bytes of the field are concatenated in
big-endian order, with the result being a positive number expressed in
binary form. Leading bytes other than 0xff, 0x80 and ASCII octal
digits are reserved for future use, as are base-256 representations of
values that would be in range for the basic format.
You may have trouble reading a @acronym{GNU} format archive on a
non-@acronym{GNU} system if the options @option{--incremental} (@option{-G}),
@option{--multi-volume} (@option{-M}), @option{--sparse} (@option{-S}), or @option{--label=@var{archive-label}} (@option{-V @var{archive-label}}) were

View File

@@ -1,26 +1,25 @@
;;; mastermenu.el --- Redefinition of texinfo-master-menu-list
;; Copyright (C) 2006, 2007 Free Software Foundation, Inc.
;; Copyright 2006-2025 Free Software Foundation, Inc.
;; Author: Sergey Poznyakoff
;; Maintainer: bug-tar@gnu.org
;; Keywords: maint, tex, docs
;; This file is part of GNU tar documentation suite
;; This file is part of GNU tar.
;; This program is free software; you can redistribute it and/or modify
;; GNU tar is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; the Free Software Foundation; either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; GNU tar is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software Foundation,
;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:

134
doc/recipes.texi Normal file
View File

@@ -0,0 +1,134 @@
@c This is part of the GNU tar manual.
@c Copyright (C) 2017--2025 Free Software Foundation, Inc.
@c This file is distributed under GFDL 1.3 or any later version
@c published by the Free Software Foundation.
This appendix provides several recipes for performing common tasks
using @GNUTAR{}.
@menu
* copy directory hierarchy::
* intermediate directories::
@end menu
@node copy directory hierarchy
@appendixsec Copying directory hierarchies
This is a traditional way to copy a directory hierarchy preserving
the dates, modes, owners and link-structure of all the files therein.
It was used back when the @command{cp} command lacked the @option{-a}
option:
@smallexample
$ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
@end smallexample
@noindent
You can avoid subshells by using @option{-C} option:
@smallexample
$ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
@end smallexample
@noindent
The same command using long option forms:
@smallexample
@group
$ @kbd{(cd sourcedir; tar --create --file=- . ) \
| (cd targetdir; tar --extract --file=-)}
@end group
@end smallexample
@noindent
or
@smallexample
@group
$ @kbd{tar --directory sourcedir --create --file=- . \
| tar --directory targetdir --extract --file=-}
@end group
@end smallexample
@node intermediate directories
@appendixsec Restoring Intermediate Directories
A common concern is how to extract permissions and ownerships of
intermediate directories when extracting only selected members from
the archive. To illustrate this, consider the following archive:
@example
@group
# tar tvf A.tar
drwxr-xr-x root/root 0 2017-11-16 14:39 foo/
dr-xr-x--- gray/user 0 2017-11-16 14:39 foo/bar/
-rw-r--r-- gray/user 10 2017-11-16 14:40 foo/bar/file
@end group
@end example
Suppose you extract only the file @file{foo/bar/file}, while being
@samp{root}:
@example
# @kbd{tar xvf A.tar foo/bar/file}
foo/bar/file
@end example
Now, let's inspect the content of the created directories:
@example
@group
# find foo -ls
427257 0 drwxr-xr-x 3 root root 16 Nov 17 16:10 foo
427258 0 drwxr-xr-x 2 root root 17 Nov 17 16:10 foo/bar
427259 0 -rw-r--r-- 1 gray user 10 Nov 6 14:40 foo/bar/file
@end group
@end example
The requested file is restored, including its ownership and
permissions. The intermediate directories, however, are created with
the default permissions, current timestamp and owned by the current
user. This is because by the time @command{tar} has reached the requested file,
it had already skipped the entries for its parent directories, so it
has no iformation about their ownership and modes.
To restore meta information about the intermediate directories,
you'll need to specify them explicitly in the command line and use the
@option{--no-recursive} option (@pxref{recurse}) to avoid extracting
their content.
To automate this process, @cite{Neal P. Murphy} proposed the following
shell script@footnote{The original version of the script can be
seen at @uref{http://lists.gnu.org/archive/html/bug-tar/2016-11/msg00024.html}}:
@example
@group
#! /bin/sh
(while read path
do
path=`dirname $path`
while [ -n "$path" -a "$path" != "." ]
do
echo $path
path=`dirname $path`
done
done < $2 | sort | uniq) |
tar -x --no-recursion -v -f $1 -T - -T $2
@end group
@end example
The script takes two arguments: the name of the archive file, and the
name of the file list file.
To complete our example, the file list will contain single line:
@example
foo/bar/file
@end example
Supposing its name is @file{file.list} and the script is named
@file{restore.sh}, you can invoke it as follows:
@example
# @kbd{sh restore.sh A.tar file.list}
@end example

View File

@@ -1,6 +1,5 @@
@c This is part of GNU tar manual.
@c Copyright (C) 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
@c 2003, 2004, 2006 Free Software Foundation, Inc.
@c Copyright 1992--2025 Free Software Foundation, Inc.
@c See file tar.texi for copying conditions.
@c This file contains support for 'renditions' by Fran@,{c}ois Pinard

View File

@@ -1,5 +1,5 @@
@c This is part of the paxutils manual.
@c Copyright (C) 2005, 2007 Free Software Foundation, Inc.
@c Copyright (C) 2005--2025 Free Software Foundation, Inc.
@c Written by Sergey Poznyakoff
@c This file is distributed under GFDL 1.1 or any later version
@c published by the Free Software Foundation.
@@ -11,11 +11,11 @@ used to determine which files were modified since the last backup.
@GNUTAR{} version @value{VERSION} supports three snapshot file
formats. The first format, called @dfn{format 0}, is the one used by
@GNUTAR{} versions up to 1.15.1. The second format, called @dfn{format
1} is an extended version of this format, that contains more metadata
and allows for further extensions. It was used by version
1.15.1. Starting from version 1.16 and up to @value{VERSION}, the
@dfn{format 2} is used.
@GNUTAR{} versions up to and including 1.15.1. The second format, called
@dfn{format 1} is an extended version of this format, that contains more
metadata and allows for further extensions. It was used by alpha release
version 1.15.90. For alpha version 1.15.91 and stable releases
version 1.16 up through @value{VERSION}, the @dfn{format 2} is used.
@GNUTAR{} is able to read all three formats, but will create
snapshots only in format 2.
@@ -33,7 +33,7 @@ metadata descriptions, one per line. Each description has the
following format:
@smallexample
@var{nfs}@var{dev} @var{inode} @var{name}
[@var{nfs}]@var{dev} @var{inode} @var{name}
@end smallexample
@noindent
@@ -42,7 +42,10 @@ where:
@table @var
@item nfs
A single plus character (@samp{+}), if this directory is located on
an @acronym{NFS}-mounted partition, or a single space otherwise;
an @acronym{NFS}-mounted partition, otherwise empty.
(That is, for non-NFS directories, the first character on the
description line contains the start of the @var{dev} field.)
@item dev
Device number of the directory;
@@ -91,7 +94,6 @@ as with @samp{format 0}.
@cindex format 2, snapshot file
@cindex snapshot file, format 2
@FIXME{}
@item
@samp{Format 2} snapshot file begins with a format identifier, as described for
version 1, e.g.:
@@ -105,7 +107,7 @@ records, separated by null (@acronym{ASCII} 0)
characters. Thus, in contrast to the previous formats, format 2
snapshot is a binary file.
First two records are decimal numbers, representing the
First two records are decimal integers, representing the
time of the last backup. First number is the number of seconds, the
second one is the number of nanoseconds, since the beginning of the
epoch. These are followed by arbitrary number of directory records.
@@ -113,17 +115,18 @@ epoch. These are followed by arbitrary number of directory records.
Each @dfn{directory record} contains a set of metadata describing a
particular directory. Parts of a directory record are delimited with
@acronym{ASCII} 0 characters. The following table describes each
part. The @dfn{Number} type in this table stands for a decimal number
in @acronym{ASCII} notation.
part. The @dfn{Number} type in this table stands for a decimal integer
in @acronym{ASCII} notation. (Negative values are preceded with a "-"
character, while positive values have no leading punctuation.)
@multitable @columnfractions 0.2 0.2 0.6
@multitable @columnfractions 0.25 0.15 0.6
@headitem Field @tab Type @tab Description
@item nfs @tab Character @tab @samp{1} if the directory is located on
an @acronym{NFS}-mounted partition, or @samp{0} otherwise;
@item mtime-sec @tab Number @tab Modification time, seconds;
@item mtime-nano @tab Number @tab Modification time, nanoseconds;
@item dev-no @tab Number @tab Device number;
@item i-no @tab Number @tab I-node number;
@item timestamp_sec @tab Number @tab Modification time, seconds;
@item timestamp_nsec @tab Number @tab Modification time, nanoseconds;
@item dev @tab Number @tab Device number;
@item ino @tab Number @tab I-node number;
@item name @tab String @tab Directory name; in contrast to the
previous versions it is not quoted;
@item contents @tab Dumpdir @tab Contents of the directory;
@@ -134,6 +137,28 @@ previous versions it is not quoted;
Dumpdirs stored in snapshot files contain only records of types
@samp{Y}, @samp{N} and @samp{D}.
@cindex snapshot file field ranges
@opindex show-snapshot-field-ranges
The specific range of values allowed in each of the @dfn{Number} fields
depends on the underlying C datatypes as determined when @command{tar}
is compiled. To see the specific ranges allowed for a particular
@command{tar} binary, you can use the
@option{--show-snapshot-field-ranges} option:
@smallexample
$ @kbd{tar --show-snapshot-field-ranges}
This tar's snapshot file field ranges are
(field name => [ min, max ]):
nfs => [ 0, 1 ],
timestamp_sec => [ -9223372036854775808, 9223372036854775807 ],
timestamp_nsec => [ 0, 999999999 ],
dev => [ 0, 18446744073709551615 ],
ino => [ 0, 18446744073709551615 ],
@end smallexample
(This example is from a GNU/Linux x86_64 system.)
@end enumerate
@c End of snapshot.texi

View File

@@ -1,5 +1,5 @@
@c This is part of the paxutils manual.
@c Copyright (C) 2006 Free Software Foundation, Inc.
@c Copyright (C) 2006--2025 Free Software Foundation, Inc.
@c This file is distributed under GFDL 1.1 or any later version
@c published by the Free Software Foundation.
@@ -143,7 +143,7 @@ format, it will also extract a file containing extension header
attributes. This file can be used to expand the file to its original
state. However, posix-aware @command{tar}s will usually ignore the
unknown variables, which makes restoring the file more
difficult. @xref{extracting sparse v.0.x, Extraction of sparse
difficult. @xref{extracting sparse v0x, Extraction of sparse
members in v.0.0 format}, for the detailed description of how to
restore such members using non-GNU @command{tar}s.
@end enumerate
@@ -175,7 +175,7 @@ The real name of the sparse file is stored in the variable
@code{GNU.sparse.name}. Thus, those @command{tar} implementations
that are not aware of GNU extensions will at least extract the files
into separate directories, giving the user a possibility to expand it
afterwards. @xref{extracting sparse v.0.x, Extraction of sparse
afterwards. @xref{extracting sparse v0x, Extraction of sparse
members in v.0.1 format}, for the detailed description of how to
restore such members using non-GNU @command{tar}s.
@@ -218,12 +218,12 @@ The real name of the sparse file is stored in the variable
variable @code{GNU.sparse.realsize}.
The sparse map itself is stored in the file data block, preceding the actual
file data. It consists of a series of octal numbers of arbitrary length, delimited
file data. It consists of a series of decimal numbers delimited
by newlines. The map is padded with nulls to the nearest block boundary.
The first number gives the number of entries in the map. Following are map entries,
each one consisting of two numbers giving the offset and size of the
data block it describes.
The first number gives the number of entries in the map. Following are
map entries, each one consisting of two numbers giving the offset and
size of the data block it describes.
The format is designed in such a way that non-posix aware @command{tar}s and @command{tar}s not
supporting @code{GNU.sparse.*} keywords will extract each sparse file

View File

@@ -1,29 +1,33 @@
@c This is part of the paxutils manual.
@c Copyright (C) 2007 Free Software Foundation, Inc.
@c Copyright (C) 2007--2025 Free Software Foundation, Inc.
@c This file is distributed under GFDL 1.1 or any later version
@c published by the Free Software Foundation.
@cindex Device numbers, changing
@cindex snapshot files, editing
@cindex snapshot files, fixing device numbers
Sometimes device numbers can change after upgrading your kernel
version or reconfiguring the hardware. Reportedly this is the case with
some newer @i{Linux} kernels, when using @acronym{LVM}. In majority of
Various situations can cause device numbers to change: upgrading your
kernel version, reconfiguring your hardware, loading kernel modules in a
different order, using virtual volumes that are assembled dynamically
(such as with @acronym{LVM} or @acronym{RAID}), hot-plugging drives
(e.g. external USB or Firewire drives), etc. In the majority of
cases this change is unnoticed by the users. However, it influences
@command{tar} incremental backups: the device number is stored in tar
snapshot files (@pxref{Snapshot Files}) and is used to determine whether
the file has changed since the last backup. If the device numbers
change for some reason, the next backup you run will be a full backup.
change for some reason, by default the next backup you run will be a
full backup.
@pindex tar-snapshot-edit
To minimize the impact in these cases, GNU @command{tar} comes with
the @command{tar-snapshot-edit} utility for inspecting and updating
device numbers in snapshot files. The utility, written by
Dustin J.@: Mitchell, is available from
device numbers in snapshot files. (The utility, written by
Dustin J.@: Mitchell, is also available from the
@uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tar-snapshot-edit.html,
@GNUTAR{} home page}.
@GNUTAR{} home page}.)
To obtain the device numbers used in the snapshot file, run
To obtain a summary of the device numbers found in the snapshot file, run
@smallexample
$ @kbd{tar-snapshot-edit @var{snapfile}}
@@ -31,10 +35,19 @@ $ @kbd{tar-snapshot-edit @var{snapfile}}
@noindent
where @var{snapfile} is the name of the snapshot file (you can supply as many
files as you wish in a single command line).
files as you wish in a single command line). You can then compare the
numbers across snapshot files, or against those currently in use on the
live filesystem (using @command{ls -l} or @command{stat}).
To update all occurrences of the given device number in the file, use
@option{-r} option. It takes a single argument of the form
Assuming the device numbers have indeed changed, it's often possible
to simply tell @GNUTAR{} to ignore the device number when processing the
incremental snapshot files for these backups, using the
@option{--no-check-device} option (@pxref{device numbers}).
Alternatively, you can use the @command{tar-edit-snapshot} script's
@option{-r} option to update all occurrences of the given device
number in the snapshot file(s). It takes a single argument
of the form
@samp{@var{olddev}-@var{newdev}}, where @var{olddev} is the device number
used in the snapshot file, and @var{newdev} is the corresponding new device
number. Both numbers may be specified in hex (e.g., @samp{0xfe01}),
@@ -49,9 +62,30 @@ backup file is obtained by appending @samp{~} to the original file name.
An example session:
@smallexample
$ @kbd{tar-snapshot-edit /var/backup/snap.a}
file version 2
/tmp/snap: Device 0x0306 occurs 634 times.
$ @kbd{tar-snapshot-edit -b -r 0x0306-0x4500 /var/backup/snap.a}
file version 2
$ @kbd{tar-snapshot-edit root_snap.0 boot_snap.0}
File: root_snap.0
Detected snapshot file version: 2
Device 0x0000 occurs 1 times.
Device 0x0003 occurs 1 times.
Device 0x0005 occurs 1 times.
Device 0x0013 occurs 1 times.
Device 0x6801 occurs 1 times.
Device 0x6803 occurs 6626 times.
Device 0xfb00 occurs 1 times.
File: boot_snap.0
Detected snapshot file version: 2
Device 0x6801 occurs 3 times.
$ @kbd{tar-snapshot-edit -b -r 0x6801-0x6901,0x6803-0x6903 root_snap.0 boot_snap.0}
File: root_snap.0
Detected snapshot file version: 2
Updated 6627 records.
File: boot_snap.0
Detected snapshot file version: 2
Updated 3 records.
@end smallexample

1336
doc/tar.1 Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,18 +1,19 @@
# Copyright (C) 2006, 2007 Free Software Foundation, Inc.
#
# GNU tar is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU tar is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# Copyright 2006-2025 Free Software Foundation, Inc.
# This file is part of GNU tar.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with GNU tar; if not, write to the Free Software
# Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1{s,/\*,@comment ,
b

View File

@@ -1,6 +1,5 @@
@c This is part of GNU tar manual.
@c Copyright (C) 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
@c 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
@c Copyright 1992--2025 Free Software Foundation, Inc.
@c See file tar.texi for copying conditions.
@macro GNUTAR

1
gnulib Submodule

Submodule gnulib added at 4619f63e6f

View File

@@ -1,37 +1,82 @@
# List of gnulib modules needed for GNU tar.
# A module name per line. Empty lines and comments are ignored.
alloca
# Copyright 2005-2025 Free Software Foundation, Inc.
# This file is part of GNU tar.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
areadlinkat-with-size
argmatch
argp
argp-version-etc
assert-h
attribute
backupfile
bool
c-ctype
c32rtomb
c32tolower
c32toupper
closeout
configmake
dirname
dup2
errno-h
error
exclude
extern-inline
exitfail
faccessat
fchmodat
fchownat
fcntl-h
fdopendir
fdutimensat
file-has-acl
fileblocks
flexmember
fnmatch-gnu
fprintftime
free-posix
fseeko
fstatat
full-write
futimens
getline
getopt-gnu
getpagesize
gettext
gettext-h
gettime
gitlog-to-changelog
hash
human
ialloc
idx
intprops
inttostr
inttypes
inttypes-h
largefile
lchown
limits-h
linkat
localcharset
manywarnings
mbrtoc32-regular
mcel-prefer
mkdirat
mkdtemp
mkfifoat
modechange
@@ -43,28 +88,39 @@ progname
quote
quotearg
readlinkat
reallocarray
renameat
root-uid
rpmatch
full-read
safe-read
same-inode
savedir
selinux-at
setenv
snprintf
stat-time
stdbool
stdint
std-gnu23
stddef-h
stdint-h
stpcpy
stdopen
strdup-posix
strerror
strtol
strtoul
strnlen
symlinkat
sys_stat-h
timespec
timespec-sub
unlinkat
unlinkdir
unlocked-io
utimensat
version-etc-fsf
verror
xalignalloc
xalloc
xalloc-die
xgetcwd
xstrtoumax
xvasprintf
year2038-recommended

9
lib/.gitignore vendored Normal file
View File

@@ -0,0 +1,9 @@
paxerror.c
paxexit-status.c
paxexit.c
paxlib.h
paxnames.c
rmt-command.h
rmt.h
rtapelib.c
system.h

View File

@@ -1,21 +1,21 @@
# Makefile for GNU tar library. -*- Makefile -*-
# Copyright (C) 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2003, 2004,
# 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
# Copyright 1994-2025 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# This file is part of GNU tar.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
noinst_LIBRARIES=libtar.a
rmt-command.h : Makefile
@@ -26,13 +26,32 @@ rmt-command.h : Makefile
$(AM_V_at)mv $@-t $@
BUILT_SOURCES = rmt-command.h
CLEANFILES = rmt-command.h rmt-command.h-t
INCLUDES = -I$(top_srcdir)/gnu -I../ -I../gnu
AM_CPPFLAGS = -I$(top_srcdir)/gnu -I../ -I../gnu
AM_CFLAGS = $(GNULIB_WARN_CFLAGS) $(WERROR_CFLAGS)
noinst_HEADERS = \
paxlib.h\
rmt.h\
system.h\
wordsplit.h\
xattr-at.h
noinst_HEADERS = system.h system-ioctl.h rmt.h paxlib.h stdopen.h
libtar_a_SOURCES = \
paxerror.c paxexit.c paxlib.h paxnames.c \
prepargs.c prepargs.h \
paxerror.c paxexit-status.c paxlib.h paxnames.c \
rtapelib.c \
rmt.h \
stdopen.c stdopen.h \
system.h system-ioctl.h
system.h \
wordsplit.c\
xattr-at.c
if !TAR_COND_XATTR_H
BUILT_SOURCES += attr/xattr.h
attr/xattr.h: attr-xattr.in.h $(top_builddir)/config.status
$(AM_V_at)$(MKDIR_P) attr
$(AM_V_GEN)rm -f $@-t $@ && \
cp $(srcdir)/attr-xattr.in.h attr/xattr.h
endif
MOSTLYCLEANFILES = attr/xattr.h
EXTRA_DIST = attr-xattr.in.h

60
lib/attr-xattr.in.h Normal file
View File

@@ -0,0 +1,60 @@
/* Replacement <attr/xattr.h> for platforms that lack it.
Copyright 2012-2025 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef TAR_ATTR_XATTR_H
#define TAR_ATTR_XATTR_H
#include <errno.h>
#ifndef ENOATTR
# define ENOATTR ENODATA /* No such attribute */
#endif
/* setting */
static int setxattr (const char *path, const char *name, const void
*value, size_t size, int flags)
{ errno = ENOTSUP; return -1; }
static int lsetxattr (const char *path, const char *name, const void
*value, size_t size, int flags)
{ errno = ENOTSUP; return -1; }
static int fsetxattr (int filedes, const char *name, const void *value,
size_t size, int flags)
{ errno = ENOTSUP; return -1; }
/* getting */
static ssize_t getxattr (const char *path, const char *name, void *value,
size_t size)
{ errno = ENOTSUP; return -1; }
static ssize_t lgetxattr (const char *path, const char *name, void
*value, size_t size)
{ errno = ENOTSUP; return -1; }
static ssize_t fgetxattr (int filedes, const char *name, void *value,
size_t size)
{ errno = ENOTSUP; return -1; }
/* listing */
static ssize_t listxattr (const char *path, char *list, size_t size)
{ errno = ENOTSUP; return -1; }
static ssize_t llistxattr (const char *path, char *list, size_t size)
{ errno = ENOTSUP; return -1; }
static ssize_t flistxattr (int filedes, char *list, size_t size)
{ errno = ENOTSUP; return -1; }
#endif

View File

@@ -1,95 +0,0 @@
/* Parse arguments from a string and prepend them to an argv.
Copyright 1999, 2000, 2001, 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA. */
/* Written by Paul Eggert <eggert@twinsun.com>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "prepargs.h"
#include <sys/types.h>
#include <xalloc.h>
#if HAVE_STRING_H
# include <string.h>
#endif
#include <ctype.h>
/* IN_CTYPE_DOMAIN (C) is nonzero if the unsigned char C can safely be given
as an argument to <ctype.h> macros like "isspace". */
#ifdef STDC_HEADERS
# define IN_CTYPE_DOMAIN(c) 1
#else
# define IN_CTYPE_DOMAIN(c) ((c) <= 0177)
#endif
#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
/* Find the white-space-separated options specified by OPTIONS, and
using BUF to store copies of these options, set ARGV[0], ARGV[1],
etc. to the option copies. Return the number N of options found.
Do not set ARGV[N]. If ARGV is null, do not store ARGV[0]
etc. Backslash can be used to escape whitespace (and backslashes). */
static int
prepend_args (char const *options, char *buf, char **argv)
{
char const *o = options;
char *b = buf;
int n = 0;
for (;;)
{
while (ISSPACE ((unsigned char) *o))
o++;
if (!*o)
return n;
if (argv)
argv[n] = b;
n++;
do
if ((*b++ = *o++) == '\\' && *o)
b[-1] = *o++;
while (*o && ! ISSPACE ((unsigned char) *o));
*b++ = '\0';
}
}
/* Prepend the whitespace-separated options in OPTIONS to the argument
vector of a main program with argument count *PARGC and argument
vector *PARGV. */
void
prepend_default_options (char const *options, int *pargc, char ***pargv)
{
if (options)
{
char *buf = xmalloc (strlen (options) + 1);
int prepended = prepend_args (options, buf, (char **) 0);
int argc = *pargc;
char * const *argv = *pargv;
char **pp = (char **) xmalloc ((prepended + argc + 1) * sizeof *pp);
*pargc = prepended + argc;
*pargv = pp;
*pp++ = *argv++;
pp += prepend_args (options, buf, pp);
while ((*pp++ = *argv++))
continue;
}
}

View File

@@ -1,3 +0,0 @@
/* Parse arguments from a string and prepend them to an argv. */
void prepend_default_options (char const *, int *, char ***);

View File

@@ -1,77 +0,0 @@
/* stdopen.c - ensure that the three standard file descriptors are in use
Copyright (C) 2005, 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Written by Paul Eggert and Jim Meyering. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "stdopen.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
/* Try to ensure that all of the standard file numbers (0, 1, 2)
are in use. Without this, each application would have to guard
every call to open, dup, fopen, etc. with tests to ensure they
don't use one of the special file numbers when opening a file.
Return false if at least one of the file descriptors is initially
closed and an attempt to reopen it fails. Otherwise, return true. */
bool
stdopen (void)
{
int fd;
bool ok = true;
for (fd = 0; fd <= 2; fd++)
{
if (fcntl (fd, F_GETFD) < 0)
{
if (errno != EBADF)
ok = false;
else
{
static const int contrary_mode[]
= { O_WRONLY, O_RDONLY, O_RDONLY };
int mode = contrary_mode[fd];
int new_fd;
/* Open /dev/null with the contrary mode so that the typical
read (stdin) or write (stdout, stderr) operation will fail.
With descriptor 0, we can do even better on systems that
have /dev/full, by opening that write-only instead of
/dev/null. The only drawback is that a write-provoked
failure comes with a misleading errno value, ENOSPC. */
if (mode == O_RDONLY
|| (new_fd = open ("/dev/full", mode) != fd))
new_fd = open ("/dev/null", mode);
if (new_fd != fd)
{
if (0 <= new_fd)
close (new_fd);
ok = false;
}
}
}
}
return ok;
}

View File

@@ -1,16 +0,0 @@
#ifndef STDOPEN_H
# define STDOPEN_H 1
# include <stdbool.h>
# ifdef __cplusplus
extern "C" {
# endif
bool stdopen (void);
# ifdef __cplusplus
}
# endif
#endif

2620
lib/wordsplit.c Normal file

File diff suppressed because it is too large Load Diff

266
lib/wordsplit.h Normal file
View File

@@ -0,0 +1,266 @@
/* wordsplit - a word splitter
Copyright (C) 2009-2018 Sergey Poznyakoff
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef __WORDSPLIT_H
#define __WORDSPLIT_H
#include <stddef.h>
#include <idx.h>
/* This wordsplit code has been tuned for GNU Tar.
Define _WORDSPLIT_EXTRAS before including wordsplit.h
to define extras that GNU Tar does not need. */
#ifdef _WORDSPLIT_EXTRAS
typedef struct wordsplit wordsplit_t;
#endif
/* Structure used to direct the splitting. Members marked with [Input]
can be defined before calling wordsplit(), those marked with [Output]
provide return values when the function returns. If neither mark is
used, the member is internal and must not be used by the caller.
In the comments below, the identifiers in parentheses indicate bits that
must be set (or unset, if starting with !) in ws_flags (if starting with
WRDSF_) or ws_options (if starting with WRDSO_) to initialize or use the
given member.
If not redefined explicitly, most of them are set to some reasonable
default value upon entry to wordsplit(). */
struct wordsplit
{
idx_t ws_wordc; /* [Output] Number of words in ws_wordv. */
char **ws_wordv; /* [Output] Array of parsed out words. */
idx_t ws_offs; /* [Input] (WRDSF_DOOFFS) Number of initial
elements in ws_wordv to fill with NULLs. */
idx_t ws_wordn; /* Number of elements ws_wordv can accommodate. */
unsigned ws_flags; /* [Input] Flags passed to wordsplit. */
unsigned ws_options; /* [Input] (WRDSF_OPTIONS)
Additional options. */
idx_t ws_maxwords; /* [Input] (WRDSO_MAXWORDS) Return at most that
many words */
idx_t ws_wordi; /* [Output] (WRDSF_INCREMENTAL) Total number of
words returned so far */
const char *ws_delim; /* [Input] (WRDSF_DELIM) Word delimiters. */
const char *ws_comment; /* [Input] (WRDSF_COMMENT) Comment characters. */
const char *ws_escape[2]; /* [Input] (WRDSF_ESCAPE) Characters to be escaped
with backslash. */
void (*ws_alloc_die) (struct wordsplit *wsp);
/* [Input] (WRDSF_ALLOC_DIE) Function called when
out of memory. Must not return. */
void (*ws_error) (const char *, ...)
_GL_ATTRIBUTE_FORMAT ((printf, 1, 2));
/* [Input] (WRDSF_ERROR) Function used for error
reporting */
void (*ws_debug) (const char *, ...)
_GL_ATTRIBUTE_FORMAT ((printf, 1, 2));
/* [Input] (WRDSF_DEBUG) Function used for debug
output. */
const char **ws_env; /* [Input] (WRDSF_ENV, !WRDSF_NOVAR) Array of
environment variables. */
char **ws_envbuf;
idx_t ws_envidx;
idx_t ws_envsiz;
int (*ws_getvar) (char **ret, const char *var, idx_t len, void *clos);
/* [Input] (WRDSF_GETVAR, !WRDSF_NOVAR) Looks up
the name VAR (LEN bytes long) in the table of
variables and if found returns in memory
location pointed to by RET the value of that
variable. Returns WRDSE_OK (0) on success,
and an error code (see WRDSE_* defines below)
on error. User-specific errors can be returned
by storing the error diagnostic string in RET
and returning WRDSE_USERERR.
Whatever is stored in RET, it must be allocated
using malloc(3). */
void *ws_closure; /* [Input] (WRDSF_CLOSURE) Passed as the CLOS
argument to ws_getvar and ws_command. */
int (*ws_command) (char **ret, const char *cmd, idx_t len, char **argv,
void *clos);
/* [Input] (!WRDSF_NOCMD) Returns in the memory
location pointed to by RET the expansion of
the command CMD (LEN bytes long). If WRDSO_ARGV
option is set, ARGV contains CMD split out to
words. Otherwise ARGV is NULL.
See ws_getvar for a discussion of possible
return values. */
const char *ws_input; /* Input string (the S argument to wordsplit. */
idx_t ws_len; /* Length of ws_input. */
idx_t ws_endp; /* Points past the last processed byte in
ws_input. */
int ws_errno; /* [Output] Error code, if an error occurred.
This is not the same as a POSIX errno value. */
char *ws_usererr; /* Points to textual description of
the error, if ws_errno is WRDSE_USERERR. Must
be allocated with malloc(3). */
struct wordsplit_node *ws_head, *ws_tail;
/* Doubly-linked list of parsed out nodes. */
idx_t ws_lvl; /* Invocation nesting level. */
};
/* Wordsplit flags. */
/* Append the words found to the array resulting from a previous
call. */
#define WRDSF_APPEND 0x00000001
/* Insert ws_offs initial NULLs in the array ws_wordv.
(These are not counted in the returned ws_wordc.) */
#define WRDSF_DOOFFS 0x00000002
/* Don't do command substitution. */
#define WRDSF_NOCMD 0x00000004
/* The parameter p resulted from a previous call to
wordsplit(), and wordsplit_free() was not called. Reuse the
allocated storage. */
#define WRDSF_REUSE 0x00000008
/* Print errors */
#define WRDSF_SHOWERR 0x00000010
/* Consider it an error if an undefined variable is expanded. */
#define WRDSF_UNDEF 0x00000020
/* Don't do variable expansion. */
#define WRDSF_NOVAR 0x00000040
/* Abort on ENOMEM error */
#define WRDSF_ENOMEMABRT 0x00000080
/* Trim off any leading and trailind whitespace */
#define WRDSF_WS 0x00000100
/* Handle single quotes */
#define WRDSF_SQUOTE 0x00000200
/* Handle double quotes */
#define WRDSF_DQUOTE 0x00000400
/* Handle single and double quotes */
#define WRDSF_QUOTE (WRDSF_SQUOTE|WRDSF_DQUOTE)
/* Replace each input sequence of repeated delimiters with a single
delimiter */
#define WRDSF_SQUEEZE_DELIMS 0x00000800
/* Return delimiters */
#define WRDSF_RETURN_DELIMS 0x00001000
/* Treat sed expressions as words */
#define WRDSF_SED_EXPR 0x00002000
/* ws_delim field is initialized */
#define WRDSF_DELIM 0x00004000
/* ws_comment field is initialized */
#define WRDSF_COMMENT 0x00008000
/* ws_alloc_die field is initialized */
#define WRDSF_ALLOC_DIE 0x00010000
/* ws_error field is initialized */
#define WRDSF_ERROR 0x00020000
/* ws_debug field is initialized */
#define WRDSF_DEBUG 0x00040000
/* ws_env field is initialized */
#define WRDSF_ENV 0x00080000
/* ws_getvar field is initialized */
#define WRDSF_GETVAR 0x00100000
/* enable debugging */
#define WRDSF_SHOWDBG 0x00200000
/* Don't split input into words. Useful for side effects. */
#define WRDSF_NOSPLIT 0x00400000
/* Keep undefined variables in place, instead of expanding them to
empty strings. */
#define WRDSF_KEEPUNDEF 0x00800000
/* Warn about undefined variables */
#define WRDSF_WARNUNDEF 0x01000000
/* Handle C escapes */
#define WRDSF_CESCAPES 0x02000000
/* ws_closure is set */
#define WRDSF_CLOSURE 0x04000000
/* ws_env is a Key/Value environment, i.e. the value of a variable is
stored in the element that follows its name. */
#define WRDSF_ENV_KV 0x08000000
/* ws_escape is set */
#define WRDSF_ESCAPE 0x10000000
/* Incremental mode */
#define WRDSF_INCREMENTAL 0x20000000
/* Perform pathname and tilde expansion */
#define WRDSF_PATHEXPAND 0x40000000
/* ws_options is initialized */
#define WRDSF_OPTIONS 0x80000000
#define WRDSF_DEFFLAGS \
(WRDSF_NOVAR | WRDSF_NOCMD | \
WRDSF_QUOTE | WRDSF_SQUEEZE_DELIMS | WRDSF_CESCAPES)
/* Remove the word that produces empty string after path expansion */
#define WRDSO_NULLGLOB 0x00000001
/* Print error message if path expansion produces empty string */
#define WRDSO_FAILGLOB 0x00000002
/* Allow a leading period to be matched by metacharacters. */
#define WRDSO_DOTGLOB 0x00000004
/* ws_command needs argv parameter */
#define WRDSO_ARGV 0x00000008
/* Keep backslash in unrecognized escape sequences in words */
#define WRDSO_BSKEEP_WORD 0x00000010
/* Handle octal escapes in words */
#define WRDSO_OESC_WORD 0x00000020
/* Handle hex escapes in words */
#define WRDSO_XESC_WORD 0x00000040
/* ws_maxwords field is initialized */
#define WRDSO_MAXWORDS 0x00000080
/* Keep backslash in unrecognized escape sequences in quoted strings */
#define WRDSO_BSKEEP_QUOTE 0x00000100
/* Handle octal escapes in quoted strings */
#define WRDSO_OESC_QUOTE 0x00000200
/* Handle hex escapes in quoted strings */
#define WRDSO_XESC_QUOTE 0x00000400
#define WRDSO_BSKEEP WRDSO_BSKEEP_WORD
#define WRDSO_OESC WRDSO_OESC_WORD
#define WRDSO_XESC WRDSO_XESC_WORD
/* Indices into ws_escape */
#define WRDSX_WORD 0
#define WRDSX_QUOTE 1
/* Error codes. */
#define WRDSE_OK 0
#define WRDSE_EOF WRDSE_OK
#define WRDSE_QUOTE 1
#define WRDSE_NOSPACE 2
#define WRDSE_USAGE 3
#define WRDSE_CBRACE 4
#define WRDSE_UNDEF 5
#define WRDSE_NOINPUT 6
#define WRDSE_PAREN 7
#define WRDSE_GLOBERR 8
#define WRDSE_USERERR 9
int wordsplit (char const *s, struct wordsplit *ws, unsigned flags);
void wordsplit_free (struct wordsplit *ws);
char const *wordsplit_strerror (struct wordsplit const *ws);
#ifdef _WORDSPLIT_EXTRAS
int wordsplit_len (const char *s, idx_t len, wordsplit_t *ws, unsigned flags);
void wordsplit_free_words (wordsplit_t *ws);
void wordsplit_free_envbuf (wordsplit_t *ws);
void wordsplit_get_words (wordsplit_t *ws, idx_t *wordc, char ***wordv);
int wordsplit_append (wordsplit_t *wsp, int argc, char **argv);
char wordsplit_c_unquote_char (char c);
char wordsplit_c_quote_char (char c);
idx_t wordsplit_c_quoted_length (const char *str, bool quote_hex, bool *quote);
void wordsplit_c_quote_copy (char *dst, const char *src, bool quote_hex);
void wordsplit_perror (wordsplit_t *ws);
void wordsplit_clearerr (wordsplit_t *ws);
#endif
#endif

114
lib/xattr-at.c Normal file
View File

@@ -0,0 +1,114 @@
/* openat-style fd-relative functions for operating with extended file
attributes.
Copyright 2012-2025 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include "xattr-at.h"
#include "openat.h"
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include "dirname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */
#include "save-cwd.h"
#include "openat-priv.h"
#ifdef HAVE_XATTRS
/* setxattrat */
#define AT_FUNC_NAME setxattrat
#define AT_FUNC_F1 setxattr
#define AT_FUNC_POST_FILE_PARAM_DECLS , const char *name, const void *value \
, size_t size, int flags
#define AT_FUNC_POST_FILE_ARGS , name, value, size, flags
#include "at-func.c"
#undef AT_FUNC_NAME
#undef AT_FUNC_F1
#undef AT_FUNC_POST_FILE_PARAM_DECLS
#undef AT_FUNC_POST_FILE_ARGS
/* lsetxattrat */
#define AT_FUNC_NAME lsetxattrat
#define AT_FUNC_F1 lsetxattr
#define AT_FUNC_POST_FILE_PARAM_DECLS , const char *name, const void *value \
, size_t size, int flags
#define AT_FUNC_POST_FILE_ARGS , name, value, size, flags
#include "at-func.c"
#undef AT_FUNC_NAME
#undef AT_FUNC_F1
#undef AT_FUNC_POST_FILE_PARAM_DECLS
#undef AT_FUNC_POST_FILE_ARGS
/* getxattrat */
#define AT_FUNC_NAME getxattrat
#define AT_FUNC_RESULT ssize_t
#define AT_FUNC_F1 getxattr
#define AT_FUNC_POST_FILE_PARAM_DECLS , const char *name, void *value \
, size_t size
#define AT_FUNC_POST_FILE_ARGS , name, value, size
#include "at-func.c"
#undef AT_FUNC_NAME
#undef AT_FUNC_F1
#undef AT_FUNC_RESULT
#undef AT_FUNC_POST_FILE_PARAM_DECLS
#undef AT_FUNC_POST_FILE_ARGS
/* lgetxattrat */
#define AT_FUNC_NAME lgetxattrat
#define AT_FUNC_RESULT ssize_t
#define AT_FUNC_F1 lgetxattr
#define AT_FUNC_POST_FILE_PARAM_DECLS , const char *name, void *value \
, size_t size
#define AT_FUNC_POST_FILE_ARGS , name, value, size
#include "at-func.c"
#undef AT_FUNC_NAME
#undef AT_FUNC_F1
#undef AT_FUNC_RESULT
#undef AT_FUNC_POST_FILE_PARAM_DECLS
#undef AT_FUNC_POST_FILE_ARGS
/* listxattrat */
#define AT_FUNC_NAME listxattrat
#define AT_FUNC_RESULT ssize_t
#define AT_FUNC_F1 listxattr
#define AT_FUNC_POST_FILE_PARAM_DECLS , char *list , size_t size
#define AT_FUNC_POST_FILE_ARGS , list , size
#include "at-func.c"
#undef AT_FUNC_NAME
#undef AT_FUNC_F1
#undef AT_FUNC_RESULT
#undef AT_FUNC_POST_FILE_PARAM_DECLS
#undef AT_FUNC_POST_FILE_ARGS
/* llistxattrat */
#define AT_FUNC_NAME llistxattrat
#define AT_FUNC_RESULT ssize_t
#define AT_FUNC_F1 llistxattr
#define AT_FUNC_POST_FILE_PARAM_DECLS , char *list , size_t size
#define AT_FUNC_POST_FILE_ARGS , list , size
#include "at-func.c"
#undef AT_FUNC_NAME
#undef AT_FUNC_F1
#undef AT_FUNC_RESULT
#undef AT_FUNC_POST_FILE_PARAM_DECLS
#undef AT_FUNC_POST_FILE_ARGS
#endif /* HAVE_XATTRS */

75
lib/xattr-at.h Normal file
View File

@@ -0,0 +1,75 @@
/* Prototypes for openat-style fd-relative functions for operating with
extended file attributes.
Copyright 2012-2025 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef XATTRS_AT_H
#define XATTRS_AT_H
#include <sys/types.h>
#if defined(HAVE_SYS_XATTR_H)
# include <sys/xattr.h>
#elif defined(HAVE_ATTR_XATTR_H)
# include <attr/xattr.h>
#endif
#include <errno.h>
#ifndef ENOATTR
# define ENOATTR ENODATA /* No such attribute */
#endif
/* These are the dir-fd-relative variants of the functions without the
"at" suffix. For example, setxattrat (AT_FDCWD, path, name, value, size,
flags &c) is usually equivalent to setxattr (file, name, value, size,
flags). For more info use the setxattr(2), getxattr(2) or listxattr(2)
manpages. */
/* dir-fd-relative setxattr. Operation sets the VALUE of the extended
attribute identified by NAME and associated with the given PATH in the
filesystem relatively to directory identified by DIR_FD. See the
setxattr(2) manpage for the description of all parameters. */
int setxattrat (int dir_fd, const char *path, const char *name,
const void *value, size_t size, int flags);
/* dir-fd-relative lsetxattr. This function is just like setxattrat,
except when DIR_FD and FILE specify a symlink: lsetxattrat operates on the
symlink, while the setxattrat operates on the referent of the symlink. */
int lsetxattrat (int dir_fd, const char *path, const char *name,
const void *value, size_t size, int flags);
/* dir-fd-relative getxattr. Operation gets the VALUE of the extended
attribute identified by NAME and associated with the given PATH in the
filesystem relatively to directory identified by DIR_FD. For more info
about all parameters see the getxattr(2) manpage. */
ssize_t getxattrat (int dir_fd, const char *path, const char *name,
void *value, size_t size);
/* dir-fd-relative lgetxattr. This function is just like getxattrat,
except when DIR_FD and FILE specify a symlink: lgetxattrat operates on the
symlink, while the getxattrat operates on the referent of the symlink. */
ssize_t lgetxattrat (int dir_fd, const char *path, const char *name,
void *value, size_t size);
/* dir-fd-relative listxattr. Obtain the list of extended attributes names. For
more info see the listxattr(2) manpage. */
ssize_t listxattrat (int dir_fd, const char *path, char *list, size_t size);
/* dir-fd-relative llistxattr. This function is just like listxattrat,
except when DIR_FD and FILE specify a symlink: llistxattr operates on the
symlink, while the listxattrat operates on the referent of the symlink. */
ssize_t llistxattrat (int dir_fd, const char *path, char *list, size_t size);
#endif /* XATTRS_AT_H */

1
paxutils Submodule

Submodule paxutils added at 063408cc6f

21
po/.gitignore vendored
View File

@@ -1,22 +1,23 @@
/Makefile.in.in
/Makevars.template
/Rules-quot
/boldquot.sed
/en@boldquot.header
/en@quot.header
/insert-header.sin
/quot.sed
/remove-potcdate.sed
/remove-potcdate.sin
*.gmo
*.mo
*.po
*~
.reference
LINGUAS
Makefile
Makefile.in
Makefile.in.in
Makevars
Makevars.template
POTFILES
Rules-quot
boldquot.sed
en@boldquot.header
en@quot.header
insert-header.sed
insert-header.sin
quot.sed
remove-potcdate.sed
remove-potcdate.sin
stamp-po
tar.pot

View File

@@ -1,22 +1,21 @@
# List of files which contain translatable strings.
# Copyright (C) 1996, 1999, 2000, 2003, 2004, 2005, 2007 Free Software
# Foundation, Inc.
# Copyright 1996-2025 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# This file is part of GNU tar.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Library files
gnu/argmatch.c
@@ -37,7 +36,6 @@ gnu/version-etc.c
gnu/xalloc-die.c
lib/paxerror.c
lib/paxexit.c
lib/paxnames.c
lib/rtapelib.c

View File

@@ -1,19 +1,21 @@
# Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
# Make GNU tar scripts.
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3, or (at your option)
## any later version.
# Copyright 2004-2025 Free Software Foundation, Inc.
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
# This file is part of GNU tar.
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
BACKUP_LIBEXEC_SCRIPTS_LIST=backup.sh dump-remind
BACKUP_SBIN_SCRIPTS_LIST=backup restore

View File

@@ -11,12 +11,12 @@ TAR=/bin/tar
# (Optional) Path to rsh binary or its equivalent. You may wish to
# set it to ssh as shown in the example below, to improve security.
# In this case you will have to use public key authentication.
RSH=/usr/local/bin/ssh
RSH=/usr/bin/ssh
# (Optional) Path to rsh binary on remote mashines. This will be
# (Optional) Path to rsh binary on remote machines. This will be
# passed via --rsh-command option to the remote invocation of
# tar
RSH_COMMAND=/usr/local/bin/ssh
RSH_COMMAND=/usr/bin/ssh
# Name of temporary file to hold volume numbers. This needs to be accessible
# by all the machines which have filesystems to be dumped.
@@ -43,7 +43,7 @@ BACKUP_DIRS='remote1:/etc remote1:/var/spool/crontab'
# DIRLIST=/etc/my-backup/dirlist
# List of individual files to be dumped.
# These should be accesible from the machine on which the dump is run.
# These should be accessible from the machine on which the dump is run.
BACKUP_FILES=''
# This list may also be kept in file $SYSCONFDIR/backup/files, the
# format of which is the same as described above. The location of
@@ -82,19 +82,19 @@ SLEEP_MESSAGE="`awk '
}' /dev/null`"
# Copyright (C) 2004, 2007 Free Software Foundation, Inc.
# Copyright 2004-2025 Free Software Foundation, Inc.
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3, or (at your option)
## any later version.
# This file is part of GNU tar.
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

View File

@@ -1,21 +1,22 @@
#! /bin/sh
# This program is part of GNU tar
# Copyright (C) 2004, 2005, 2006 Free Software Foundation
#
# This program is free software; you can redistribute it and/or modify
# Make backups.
# Copyright 2004-2006, 2013, 2019 Free Software Foundation
# This file is part of GNU tar.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 1, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Load library routines
SYSCONFDIR=${SYSCONFDIR-@sysconfdir@}
@@ -72,8 +73,9 @@ do
--l=*|--le=*|--lev=*|--leve=*|--level=*)
DUMP_LEVEL=$optarg
;;
-l?*) DUMP_LEVEL=`expr $option : '-l\(.*\)'`;;
-l|--l|--le|--lev|--leve|--level)
prev=$option
prev=--level
;;
--verb=*|--verbo=*|--verbos=*|--verbose=*)
VERBOSE=$optarg
@@ -81,14 +83,13 @@ do
-v|--verb|--verbo|--verbos|--verbose)
VERBOSE=100
;;
-v*) VERBOSE=`expr $option : "-v\(.*\)"`;;
-v*) VERBOSE=`expr $option : '-v\(.*\)'`;;
--t=*|--ti=*|--tim=*|--time=*)
TIME=$optarg
;;
-t) prev=--t;;
-t*) TIME=`expr $option : "-t\(.*\)"`;;
--t|--ti|--tim|--time)
prev=$option
-t?*) TIME=`expr $option : '-t\(.*\)'`;;
-t|--t|--ti|--tim|--time)
prev=--time
;;
-V|--v|--ve|--ver|--vers|--versi|--versio|--version)
echo "backup (@PACKAGE_NAME@) @VERSION@"
@@ -148,13 +149,16 @@ message 20 "Variables:"
message 20 "BACKUP_DIRS=$BACKUP_DIRS"
message 20 "BACKUP_FILES=$BACKUP_FILES"
# The buch of commands below is run in a subshell for which all output is
# piped through `tee' to the logfile. Doing this, instead of having
# The bunch of commands below is run in a subshell for which all output is
# piped through 'tee' to the logfile. Doing this, instead of having
# multiple pipelines all over the place, is cleaner and allows access to
# the exit value from various commands more easily.
(
message 1 "preparing tapes"
$MT_BEGIN "${TAPE_FILE}"
if ! $MT_BEGIN "${TAPE_FILE}"; then
echo >&2 "$0: tape initialization failed"
exit 1
fi
rm -f "${VOLNO_FILE}"
message 1 "processing backup directories"
@@ -187,10 +191,10 @@ message 20 "BACKUP_FILES=$BACKUP_FILES"
"--label='`print_level` backup of ${fs} on ${remotehost} at ${NOW}'" \
-C ${fs} .
# `rsh' doesn't exit with the exit status of the remote command. What
# 'rsh' doesn't exit with the exit status of the remote command. What
# stupid lossage. TODO: think of a reliable workaround.
if [ $? -ne 0 ] ; then
echo "Backup of ${1} failed." 1>&2
echo "$0: backup of ${1} failed." 1>&2
# I'm assuming that the tar will have written an empty
# file to the tape, otherwise I should do a cat here.
else
@@ -237,17 +241,17 @@ message 20 "BACKUP_FILES=$BACKUP_FILES"
else
echo "No miscellaneous files specified"
fi
message 1 "final cleanup"
$MT_REWIND "${TAPE_FILE}"
$MT_OFFLINE "${TAPE_FILE}"
echo "."
) 2>&1 | tee -a "${LOGFILE}"
RC=$?
if test "${ADMINISTRATOR}" != NONE; then
echo "Sending the dump log to ${ADMINISTRATOR}"
mail -s "Results of backup started ${startdate}" ${ADMINISTRATOR} < "${LOGFILE}"
fi
exit $RC
# EOF

View File

@@ -1,21 +1,22 @@
#! /bin/sh
# This program is part of GNU tar
# Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# Make backups.
# Copyright 2004-2025 Free Software Foundation, Inc.
# This file is part of GNU tar.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 1, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PROGNAME=`basename $0`
CONFIGPATH="$SYSCONFDIR/backup"
@@ -48,7 +49,7 @@ MT_REWIND=mt_rewind
MT_OFFLINE=mt_offline
MT_STATUS=mt_status
# Insure `mail' is in PATH.
# Insure 'mail' is in PATH.
PATH="/usr/ucb:${PATH}"
export PATH
# Put startdate in the subject line of mailed report, since if it happens
@@ -211,8 +212,8 @@ init_backup() {
TAR_PART1="${TAR_PART1} --info-script='${DUMP_REMIND_SCRIPT}'"
fi
# Set logfile name
# Logfile name should be in the form ``log-1993-03-18-level-0''
# They go in the directory `@sysconfdir@/log'.
# Logfile name should be in the form 'log-1993-03-18-level-0'
# They go in the directory '@sysconfdir@/log'.
# i.e. year-month-date. This format is useful for sorting by name, since
# logfiles are intentionally kept online for future reference.
LOGFILE="${LOGPATH}/log-`now`-level-${DUMP_LEVEL}"
@@ -305,12 +306,14 @@ backup_host() {
if [ "z${localhost}" != "z$rhost" ] ; then
$RSH "$rhost" ${TAR_PART1} -f "${localhost}:${TAPE_FILE}" $@
else
# Using `sh -c exec' causes nested quoting and shell substitution
# Using 'sh -c exec' causes nested quoting and shell substitution
# to be handled here in the same way rsh handles it.
CMD="exec ${TAR_PART1} -f \"${TAPE_FILE}\" $@"
message 10 "CMD: $CMD"
sh -c "$CMD"
message 10 "RC: $?"
RC=$?
message 10 "RC: $RC"
return $RC
fi
}
@@ -339,9 +342,9 @@ remote_run() {
license() {
cat - <<EOF
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software. You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
Copyright (C) 2013, 2025 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
EOF
}

View File

@@ -7,9 +7,25 @@
# This script should be run by tar with --info-script (-F) to inform
# interested parties that a tape for the next volume of the backup needs to
# be put in the tape drive.
#
# Include location of `sendmail' and GNU finger.
# Copyright 2004-2025 Free Software Foundation, Inc.
# This file is part of GNU tar.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Include location of 'sendmail' and GNU finger.
PATH="/usr/lib:/usr/local/gnubin:${PATH}"
export PATH
@@ -25,8 +41,8 @@ MT_OFFLINE
# which users are logged into consoles (and thus in the office and capable
# of changing tapes).
#
# Certain users (like `root') aren't real users, and shouldn't be notified.
# Neither should `zippy', `elvis', etc. (on the GNU machines) since they're
# Certain users (like 'root') aren't real users, and shouldn't be notified.
# Neither should 'zippy', 'elvis', etc. (on the GNU machines) since they're
# just test accounts.
recipients="`
finger .clients 2> /dev/null \

View File

@@ -1,21 +1,22 @@
#! /bin/sh
# This program is part of GNU tar
# Copyright (C) 2004, 2006 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# Restore backups.
# Copyright 2004-2025 Free Software Foundation, Inc.
# This file is part of GNU tar.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 1, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Load library routines
SYSCONFDIR=${SYSCONFDIR-@sysconfdir@}
@@ -60,8 +61,9 @@ do
--l=*|--le=*|--lev=*|--leve=*|--level=*)
DUMP_LEVEL=$optarg
;;
-l?*) DUMP_LEVEL=`expr $option : '-l\(.*\)'`;;
-l|--l|--le|--lev|--leve|--level)
prev=$option
prev=--level
;;
--verb=*|--verbo=*|--verbos=*|--verbose=*)
VERBOSE=$optarg
@@ -69,7 +71,7 @@ do
-v|--verb|--verbo|--verbos|--verbose)
VERBOSE=100
;;
-v*) VERBOSE=`expr $option : "-v\(.*\)"`;;
-v*) VERBOSE=`expr $option : '-v\(.*\)'`;;
-V|--v|--ve|--ver|--vers|--versi|--versio|--version)
echo "restore (@PACKAGE_NAME@) @VERSION@"
license
@@ -181,7 +183,7 @@ restore_files()
done
}
# Operation Overwiew:
# Operation Overview:
#
# 1. Determine the time of the last backup
# 2. Create list of incremental listings to process

View File

@@ -1,31 +1,66 @@
#! /usr/bin/perl -w
# Display and edit the 'dev' field in tar's snapshots
# Copyright (C) 2007 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# Copyright 2007-2025 Free Software Foundation, Inc.
# This file is part of GNU tar.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# Author: Dustin J. Mitchell <dustin@zmanda.com>
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# tar-snapshot-edit
#
# This script is capable of replacing values in the 'dev' field of an
# incremental backup 'snapshot' file. This is useful when the device
# used to store files in a tar archive changes, without the files
# themselves changing. This may happen when, for example, a device
# driver changes major or minor numbers.
#
# It can also run a check on all the field values found in the
# snapshot file, printing out a detailed message when it finds values
# that would cause an "Unexpected field value in snapshot file",
# "Numerical result out of range", or "Invalid argument" error
# if tar were run using that snapshot file as input. (See the
# comments included in the definition of the check_field_values
# routine for more detailed information regarding these checks.)
#
#
#
# Author: Dustin J. Mitchell <dustin@zmanda.com>
#
# Modified Aug 25, 2011 by Nathan Stratton Treadway <nathanst AT ontko.com>:
# * update Perl syntax to work correctly with more recent versions of
# Perl. (The original code worked with in the v5.8 timeframe but
# not with Perl v5.10.1 and later.)
# * added a "-c" option to check the snapshot file for invalid field values.
# * handle NFS indicator character ("+") in version 0 and 1 files
# * preserve the original header/version line when editing version 1
# or 2 files.
# * tweak output formatting
#
# Modified March 13, 2013 by Nathan Stratton Treadway <nathanst AT ontko.com>:
# * configure field ranges used for -c option based on the system
# architecture (in response to the December 2012 update to GNU tar
# enabling support for systems with signed dev_t values).
# * when printing the list of device ids found in the snapshot file
# (when run in the default mode), print the raw device id values
# instead of the hex-string version in those cases where they
# can't be converted successfully.
use Getopt::Std;
use Config;
my %snapshot_field_ranges; # used in check_field_values function
## reading
@@ -41,14 +76,15 @@ sub read_incr_db ($) {
$file_version = 0;
}
print "file version $file_version\n";
print "\nFile: $filename\n";
print " Detected snapshot file version: $file_version\n\n";
if ($file_version == 0) {
return read_incr_db_0($file, $header_str);
} elsif ($file_version == 1) {
return read_incr_db_1($file);
return read_incr_db_1($file, $header_str);
} elsif ($file_version == 2) {
return read_incr_db_2($file);
return read_incr_db_2($file, $header_str);
} else {
die "Unrecognized snapshot version in header '$header_str'";
}
@@ -62,48 +98,66 @@ sub read_incr_db_0 ($$) {
chop $hdr_timestamp_sec;
my $hdr_timestamp_nsec = ''; # not present in file format 0
my $nfs;
my @dirs;
while (<$file>) {
/^([0-9]*) ([0-9]*) (.*)\n$/ || die("Bad snapshot line $_");
/^(\+?)([0-9]*) ([0-9]*) (.*)\n$/ || die("Bad snapshot line $_");
push @dirs, { dev=>$1,
ino=>$2,
name=>$3 };
if ( $1 eq "+" ) {
$nfs="1";
} else {
$nfs="0";
}
push @dirs, { nfs=>$nfs,
dev=>$2,
ino=>$3,
name=>$4 };
}
close($file);
# file version, timestamp, timestamp, dir list
return [ 0, $hdr_timestamp_sec, $hdr_timestamp_nsec, \@dirs ];
# file version, timestamp, timestamp, dir list, file header line
return [ 0, $hdr_timestamp_sec, $hdr_timestamp_nsec, \@dirs, ""];
}
sub read_incr_db_1 ($) {
sub read_incr_db_1 ($$) {
my $file = shift;
my $header_str = shift;
my $timestamp = <$file>; # "sec nsec"
my ($hdr_timestamp_sec, $hdr_timestamp_nsec) = ($timestamp =~ /([0-9]*) ([0-9]*)/);
my $nfs;
my @dirs;
while (<$file>) {
/^([0-9]*) ([0-9]*) ([0-9]*) ([0-9]*) (.*)\n$/ || die("Bad snapshot line $_");
/^(\+?)([0-9]*) ([0-9]*) ([0-9]*) ([0-9]*) (.*)\n$/ || die("Bad snapshot line $_");
push @dirs, { timestamp_sec=>$1,
timestamp_nsec=>$2,
dev=>$3,
ino=>$4,
name=>$5 };
if ( $1 eq "+" ) {
$nfs="1";
} else {
$nfs="0";
}
push @dirs, { nfs=>$nfs,
timestamp_sec=>$2,
timestamp_nsec=>$3,
dev=>$4,
ino=>$5,
name=>$6 };
}
close($file);
# file version, timestamp, timestamp, dir list
return [ 1, $hdr_timestamp_sec, $hdr_timestamp_nsec, \@dirs ];
# file version, timestamp, timestamp, dir list, file header line
return [ 1, $hdr_timestamp_sec, $hdr_timestamp_nsec, \@dirs, $header_str ];
}
sub read_incr_db_2 ($) {
sub read_incr_db_2 ($$) {
my $file = shift;
my $header_str = shift;
$/="\0"; # $INPUT_RECORD_SEPARATOR
my $hdr_timestamp_sec = <$file>;
@@ -150,40 +204,257 @@ sub read_incr_db_2 ($) {
close($file);
$/ = "\n"; # reset to normal
# file version, timestamp, timestamp, dir list
return [ 2, $hdr_timestamp_sec, $hdr_timestamp_nsec, \@dirs ];
# file version, timestamp, timestamp, dir list, file header line
return [ 2, $hdr_timestamp_sec, $hdr_timestamp_nsec, \@dirs, $header_str];
}
## display
sub show_device_counts ($$) {
sub show_device_counts ($) {
my $info = shift;
my $filename = shift;
my %devices;
foreach my $dir (@{${@$info}[3]}) {
my $dev = ${%$dir}{'dev'};
foreach my $dir (@{$info->[3]}) {
my $dev = $dir->{'dev'};
$devices{$dev}++;
}
foreach $dev (sort keys %devices) {
printf "$filename: Device 0x%04x occurs $devices{$dev} times.\n", $dev;
my $devstr;
foreach $dev (sort {$a <=> $b} keys %devices) {
$devstr = sprintf ("0x%04x", $dev);
if ( $dev > 0xffffffff or $dev < 0 or hex($devstr) != $dev ) {
# sprintf "%x" will not return a useful value for device ids
# that are negative or which overflow the integer size on this
# instance of Perl, so we convert the hex string back to a
# number, and if it doesn't (numerically) equal the original
# device id value, we know the hex conversion hasn't worked.
#
# Unfortunately, since we're running in "-w" mode, Perl will
# also print a warning message if the hex() routine is called
# on anything larger than "0xffffffff", even in 64-bit Perl
# where such values are actually supported... so we have to
# avoid calling hex() at all if the device id is too large or
# negative. (If it's negative, the conversion to an unsigned
# integer for the "%x" specifier will mean the result will
# always trigger hex()'s warning on a 64-bit machine.)
#
# These situations don't seem to occur very often, so for now
# when they do occur, we simply print the original text value
# that was read from the snapshot file; it will look a bit
# funny next to the values that do print in hex, but that's
# preferable to printing values that aren't actually correct.
$devstr = $dev;
}
printf " Device %s occurs $devices{$dev} times.\n", $devstr;
}
}
## check field values
# initializes the global %snapshot_field_ranges hash, based on the "-a"
# command-line option if given, otherwise based on the "archname" of
# the current system.
#
# Each value in the hash is a two-element array containing the minimum
# and maximum allowed values, respectively, for that field in the snapshot
# file. GNU tar's allowed values for each architecture are determined
# in the incremen.c source file, where the TYPE_MIN and TYPE_MAX
# pre-processor expressions are used to determine the range that can be
# expressed by the C data type used for each field; the values in the
# array defined below should match those calculations. (For tar v1.27
# and later, the valid ranges for a particular tar binary can easily
# be determined using the "tar --show-snapshot-field-ranges" command.)
sub choose_architecture ($) {
my $opt_a = shift;
my $arch = $opt_a ? $opt_a : $Config{'archname'};
# These ranges apply to Linux 2.4/2.6 on iX86 systems, but are used
# by default on unrecognized/unsupported systems, too.
%iX86_linux_field_ranges = (
timestamp_sec => [ -2147483648, 2147483647 ], # min/max of time_t
timestamp_nsec => [ 0, 999999999 ], # 0 to BILLION-1
nfs => [ 0, 1 ],
dev => [ 0, 18446744073709551615 ], # min/max of dev_t
ino => [ 0, 4294967295 ], # min/max of ino_t
);
if ( $arch =~ m/^i[\dxX]86-linux/i ) {
%snapshot_field_ranges = %iX86_linux_field_ranges;
print "Checking snapshot field values using \"iX86-linux\" ranges.\n\n";
} elsif ( $arch =~ m/^x86_64-linux/i ) {
%snapshot_field_ranges = (
timestamp_sec => [ -9223372036854775808, 9223372036854775807 ],
timestamp_nsec => [ 0, 999999999 ],
nfs => [ 0, 1 ],
dev => [ 0, 18446744073709551615 ],
ino => [ 0, 18446744073709551615 ],
);
print "Checking snapshot field values using \"x86_64-linux\" ranges.\n\n";
} elsif ( $arch =~ m/^IA64.ARCHREV_0/i ) {
# HP/UX running on Itanium/ia64 architecture
%snapshot_field_ranges = (
timestamp_sec => [ -2147483648, 2147483647 ],
timestamp_nsec => [ 0, 999999999 ],
nfs => [ 0, 1 ],
dev => [ -2147483648, 2147483647 ],
ino => [ 0, 4294967295 ],
);
print "Checking snapshot field values using \"IA64.ARCHREV_0\" (HP/UX) ranges.\n\n";
} else {
%snapshot_field_ranges = %iX86_linux_field_ranges;
print "Unrecognized architecture \"$arch\"; defaulting to \"iX86-linux\".\n";
print "(Use -a option to override.)\n" unless $opt_a;
print "\n";
}
if ( ref(1) ne "" ) {
print "(\"bignum\" mode is in effect; skipping 64-bit-integer check.)\n\n"
} else {
# find the largest max value in the current set of ranges
my $maxmax = 0;
for $v (values %snapshot_field_ranges ) {
$maxmax = $v->[1] if ($v->[1] > $maxmax);
}
# "~0" translates into a platform-native integer with all bits turned
# on -- that is, the largest value that can be represented as
# an integer. We print a warning if our $maxmax value is greater
# than that largest integer, since in that case Perl will switch
# to using floats for those large max values. The wording of
# the message assumes that the only way this situation can exist
# is that the platform uses 32-bit integers but some of the
# snapshot-file fields have 64-bit values.
if ( ~0 < $maxmax ) {
print <<EOF
Note: this version of Perl uses 32-bit integers, which means that it
will switch to using floating-point numbers when checking the ranges
for 64-bit snapshot-file fields. This normally will work fine, but
might fail to detect cases where the value in the input field value is
only slightly out of range. (For example, a "9223372036854775808"
might not be recognized as being larger than 9223372036854775807.)
If you suspect you are experiencing this problem, you can try running
the program using the "-Mbignum" option, as in
\$ perl $0 -Mbignum -c [FILES]
(but doing so will make the program run *much* slower).
EOF
}
}
}
# returns a warning message if $field_value isn't a valid string
# representation of an integer, or if the resulting integer is out of range
# defined by the two-element array retrieved using up the $field_name key in
# the global %snapshot_field_ranges hash.
sub validate_integer_field ($$) {
my $field_value = shift;
my $field_name = shift;
my ($min, $max) = @{$snapshot_field_ranges{$field_name}};
my $msg = "";
if ( not $field_value =~ /^-?\d+$/ ) {
$msg = " $field_name value contains invalid characters: \"$field_value\"\n";
} else {
if ( $field_value < $min ) {
$msg = " $field_name value too low: \"$field_value\" < $min \n";
} elsif ( $field_value > $max ) {
$msg = " $field_name value too high: \"$field_value\" > $max \n";
}
}
return $msg;
}
# This routine loops through each directory entry in the $info data
# structure and prints a warning message if tar would abort with an
# "Unexpected field value in snapshot file", "Numerical result out of
# range", or "Invalid argument" error upon reading this snapshot file.
#
# (Note that the "Unexpected field value in snapshot file" error message
# was introduced along with the change to snapshot file format "2",
# starting with tar v1.16 [or, more precisely, v1.15.91], while the
# other two were introduced in v1.27.)
#
# The checks here are intended to match those found in the incremen.c
# source file. See the choose_architecture() function (above) for more
# information on how to configure the range of values considered valid
# by this script.
#
# (Note: the checks here are taken from the code that processes
# version 2 snapshot files, but to keep things simple we apply those
# same checks to files having earlier versions -- but only for
# the fields that actually exist in those input files.)
sub check_field_values ($) {
my $info = shift;
my $msg;
my $error_found = 0;
print " Checking field values in snapshot file...\n";
$snapver = $info->[0];
$msg = "";
$msg .= validate_integer_field($info->[1], 'timestamp_sec');
if ($snapver >= 1) {
$msg .= validate_integer_field($info->[2], 'timestamp_nsec');
}
if ( $msg ne "" ) {
$error_found = 1;
print "\n snapshot file header:\n";
print $msg;
}
foreach my $dir (@{$info->[3]}) {
$msg = "";
$msg .= validate_integer_field($dir->{'nfs'}, 'nfs');
if ($snapver >= 1) {
$msg .= validate_integer_field($dir->{'timestamp_sec'}, 'timestamp_sec');
$msg .= validate_integer_field($dir->{'timestamp_nsec'}, 'timestamp_nsec');
}
$msg .= validate_integer_field($dir->{'dev'}, 'dev');
$msg .= validate_integer_field($dir->{'ino'}, 'ino');
if ( $msg ne "" ) {
$error_found = 1;
print "\n directory: $dir->{'name'}\n";
print $msg;
}
}
print "\n Snapshot field value check complete" ,
$error_found ? "" : ", no errors found" ,
".\n";
}
## editing
sub replace_device_number ($@) {
my $info = shift(@_);
my @repl = @_;
foreach my $dir (@{${@$info}[3]}) {
foreach $x (@repl) {
if (${%$dir}{'dev'} eq $$x[0]) {
${%$dir}{'dev'} = $$x[1];
last;
}
my $count = 0;
foreach my $dir (@{$info->[3]}) {
foreach $x (@repl) {
if ($dir->{'dev'} eq $$x[0]) {
$dir->{'dev'} = $$x[1];
$count++;
last;
}
}
}
print " Updated $count records.\n"
}
## writing
@@ -215,10 +486,13 @@ sub write_incr_db_0 ($$) {
my $timestamp_sec = $info->[1];
print $file "$timestamp_sec\n";
foreach my $dir (@{${@$info}[3]}) {
print $file "${%$dir}{'dev'} ";
print $file "${%$dir}{'ino'} ";
print $file "${%$dir}{'name'}\n";
foreach my $dir (@{$info->[3]}) {
if ($dir->{'nfs'}) {
print $file '+'
}
print $file "$dir->{'dev'} ";
print $file "$dir->{'ino'} ";
print $file "$dir->{'name'}\n";
}
}
@@ -227,18 +501,21 @@ sub write_incr_db_1 ($$) {
my $info = shift;
my $file = shift;
print $file "GNU tar-1.15-1\n";
print $file $info->[4];
my $timestamp_sec = $info->[1];
my $timestamp_nsec = $info->[2];
print $file "$timestamp_sec $timestamp_nsec\n";
foreach my $dir (@{${@$info}[3]}) {
print $file "${%$dir}{'timestamp_sec'} ";
print $file "${%$dir}{'timestamp_nsec'} ";
print $file "${%$dir}{'dev'} ";
print $file "${%$dir}{'ino'} ";
print $file "${%$dir}{'name'}\n";
foreach my $dir (@{$info->[3]}) {
if ($dir->{'nfs'}) {
print $file '+'
}
print $file "$dir->{'timestamp_sec'} ";
print $file "$dir->{'timestamp_nsec'} ";
print $file "$dir->{'dev'} ";
print $file "$dir->{'ino'} ";
print $file "$dir->{'name'}\n";
}
}
@@ -247,21 +524,21 @@ sub write_incr_db_2 ($$) {
my $info = shift;
my $file = shift;
print $file "GNU tar-1.16-2\n";
print $file $info->[4];
my $timestamp_sec = $info->[1];
my $timestamp_nsec = $info->[2];
print $file $timestamp_sec . "\0";
print $file $timestamp_nsec . "\0";
foreach my $dir (@{${@$info}[3]}) {
print $file ${%$dir}{'nfs'} . "\0";
print $file ${%$dir}{'timestamp_sec'} . "\0";
print $file ${%$dir}{'timestamp_nsec'} . "\0";
print $file ${%$dir}{'dev'} . "\0";
print $file ${%$dir}{'ino'} . "\0";
print $file ${%$dir}{'name'} . "\0";
foreach my $dirent (@{${%$dir}{'dirents'}}) {
foreach my $dir (@{$info->[3]}) {
print $file $dir->{'nfs'} . "\0";
print $file $dir->{'timestamp_sec'} . "\0";
print $file $dir->{'timestamp_nsec'} . "\0";
print $file $dir->{'dev'} . "\0";
print $file $dir->{'ino'} . "\0";
print $file $dir->{'name'} . "\0";
foreach my $dirent (@{$dir->{'dirents'}}) {
print $file $dirent . "\0";
}
print $file "\0";
@@ -271,9 +548,10 @@ sub write_incr_db_2 ($$) {
## main
sub main {
our ($opt_b, $opt_r, $opt_h);
getopts('br:h');
HELP_MESSAGE() if ($opt_h || $#ARGV == -1 || ($opt_b && !$opt_r));
our ($opt_b, $opt_r, $opt_h, $opt_c, $opt_a);
getopts('br:hca:');
HELP_MESSAGE() if ($opt_h || $#ARGV == -1 || ($opt_b && !$opt_r) ||
($opt_a && !$opt_c) || ($opt_r && $opt_c) );
my @repl;
if ($opt_r) {
@@ -283,31 +561,61 @@ sub main {
}
}
choose_architecture($opt_a) if ($opt_c);
foreach my $snapfile (@ARGV) {
my $info = read_incr_db($snapfile);
if ($opt_r ) {
if ($opt_r) {
if ($opt_b) {
rename($snapfile, $snapfile . "~") || die "Could not rename '$snapfile' to backup";
}
replace_device_number($info, @repl);
write_incr_db($info, $snapfile);
} elsif ($opt_c) {
check_field_values($info);
} else {
show_device_counts($info, $snapfile);
show_device_counts($info);
}
}
}
sub HELP_MESSAGE {
print "Usage: tar-snapshot-edit.pl [-r 'DEV1-DEV2[,DEV3-DEV4...]' [-b]] SNAPFILE [SNAPFILE [..]]\n";
print "\n";
print " Without -r, summarize the 'device' values in each SNAPFILE.\n";
print "\n";
print " With -r, replace occurrences of DEV1 with DEV2 in each SNAPFILE.\n";
print " DEV1 and DEV2 may be specified in hex (e.g., 0xfe01), decimal (e.g.,\n";
print " 65025), or MAJ:MIN (e.g., 254:1). To replace multiple occurrences,\n";
print " separate them with commas. If -b is also specified, backup\n";
print " files (ending with '~') will be created.\n";
print <<EOF;
Usage:
tar-snapshot-edit SNAPFILE [SNAPFILE [...]]
tar-snapshot-edit -r 'DEV1-DEV2[,DEV3-DEV4...]' [-b] SNAPFILE [SNAPFILE [...]]
tar-snapshot-edit -c [-aARCH] SNAPFILE [SNAPFILE [...]]
With no options specified: print a summary of the 'device' values
found in each SNAPFILE.
With -r: replace occurrences of DEV1 with DEV2 in each SNAPFILE.
DEV1 and DEV2 may be specified in hex (e.g., 0xfe01), decimal (e.g.,
65025), or MAJ:MIN (e.g., 254:1). To replace multiple occurrences,
separate them with commas. If -b is also specified, backup files
(ending with '~') will be created.
With -c: Check the field values in each SNAPFILE and print warning
messages if any invalid values are found. (An invalid value is one
that would cause \"tar\" to abort with an error message such as
Unexpected field value in snapshot file
Numerical result out of range
or
Invalid argument
as it processed the snapshot file.)
Normally the program automatically chooses the valid ranges for
the fields based on the current system's architecture, but the
-a option can be used to override the selection, e.g. in order
to validate a snapshot file generated on a some other system.
(Currently only three architectures are supported, "iX86-linux",
"x86_64-linux", and "IA64.ARCHREV_0" [HP/UX running on Itanium/ia64],
and if the current system isn't recognized, then the iX86-linux
values are used by default.)
EOF
exit 1;
}

View File

@@ -3,6 +3,23 @@
# concatenates a GNU tar multi-volume archive into a single tar archive.
# Author: Bruno Haible <bruno@clisp.org>, Sergey Poznyakoff <gray@gnu.org.ua>
# Copyright 2004-2025 Free Software Foundation, Inc.
# This file is part of GNU tar.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# dump_type FILE [N]
# Print type character from block N (default 0) of tar archive FILE
dump_type() {

View File

@@ -1,34 +1,36 @@
/* xsparse - expands compressed sparse file images extracted from GNU tar
archives.
Copyright (C) 2006, 2007, 2010 Free Software Foundation, Inc.
Copyright 2006-2025 Free Software Foundation, Inc.
Written by Sergey Poznyakoff
This file is part of GNU tar.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Written by Sergey Poznyakoff */
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <limits.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
/* Bound on length of the string representing an off_t.
See INT_STRLEN_BOUND in intprops.h for explanation */
@@ -43,10 +45,10 @@ struct sp_array
off_t numbytes;
};
char *progname;
int verbose;
static char *progname;
static bool verbose;
void
static void
die (int code, char *fmt, ...)
{
va_list ap;
@@ -59,58 +61,42 @@ die (int code, char *fmt, ...)
exit (code);
}
void *
static void *
emalloc (size_t size)
{
char *p = malloc (size);
if (!p)
if (!p && size)
die (1, "not enough memory");
return p;
}
off_t
static off_t
string_to_off (char *p, char **endp)
{
off_t v = 0;
for (; *p; p++)
{
int digit = *p - '0';
off_t x = v * 10;
if (9 < (unsigned) digit)
{
if (endp)
{
*endp = p;
break;
}
die (1, "number parse error near %s", p);
}
else if (x / 10 != v)
die (1, "number out of allowed range, near %s", p);
v = x + digit;
if (v < 0)
die (1, "negative number");
}
if (endp)
*endp = p;
errno = 0;
intmax_t i = strtoimax (p, endp, 10);
off_t v = i;
if (i < 0 || v != i || errno == ERANGE)
die (1, "number out of allowed range, near %s", p);
if (errno || p == *endp)
die (1, "number parse error near %s", p);
return v;
}
size_t
string_to_size (char *p, char **endp)
static size_t
string_to_size (char *p, char **endp, size_t maxsize)
{
off_t v = string_to_off (p, endp);
size_t ret = v;
if (ret != v)
if (! (ret == v && ret <= maxsize))
die (1, "number too big");
return ret;
}
size_t sparse_map_size;
struct sp_array *sparse_map;
static size_t sparse_map_size;
static struct sp_array *sparse_map;
void
static void
get_line (char *s, int size, FILE *stream)
{
char *p = fgets (s, size, stream);
@@ -120,11 +106,11 @@ get_line (char *s, int size, FILE *stream)
die (1, "unexpected end of file");
len = strlen (p);
if (s[len - 1] != '\n')
die (1, "buffer overflow");
s[len - 1] = 0;
die (1, "invalid or too-long data");
s[len - 1] = '\0';
}
int
static bool
get_var (FILE *fp, char **name, char **value)
{
static char *buffer;
@@ -137,12 +123,12 @@ get_var (FILE *fp, char **name, char **value)
size_t len, s;
if (!fgets (buffer, bufsize, fp))
return 0;
return false;
len = strlen (buffer);
if (len == 0)
return 0;
return false;
s = string_to_size (buffer, &p);
s = string_to_size (buffer, &p, SIZE_MAX - 1);
if (*p != ' ')
die (1, "malformed header: expected space but found %s", p);
if (buffer[len-1] != '\n')
@@ -159,30 +145,29 @@ get_var (FILE *fp, char **name, char **value)
}
p++;
}
while (memcmp (p, "GNU.sparse.", 11));
while (strncmp (p, "GNU.sparse.", 11) != 0);
p += 11;
q = strchr (p, '=');
if (!q)
die (1, "malformed header: expected `=' not found");
die (1, "malformed header: expected '=' not found");
*q++ = 0;
q[strlen (q) - 1] = 0;
*name = p;
*value = q;
return 1;
return true;
}
char *outname;
off_t outsize;
unsigned version_major;
unsigned version_minor;
static char *outname;
static off_t outsize;
static off_t version_major;
static off_t version_minor;
void
static void
read_xheader (char *name)
{
char *kw, *val;
FILE *fp = fopen (name, "r");
char *expect = NULL;
size_t i = 0;
if (verbose)
@@ -193,10 +178,6 @@ read_xheader (char *name)
if (verbose)
printf ("Found variable GNU.sparse.%s = %s\n", kw, val);
if (expect && strcmp (kw, expect))
die (1, "bad keyword sequence: expected `%s' but found `%s'",
expect, kw);
expect = NULL;
if (strcmp (kw, "name") == 0)
{
outname = emalloc (strlen (val) + 1);
@@ -204,11 +185,11 @@ read_xheader (char *name)
}
else if (strcmp (kw, "major") == 0)
{
version_major = string_to_size (val, NULL);
version_major = string_to_off (val, NULL);
}
else if (strcmp (kw, "minor") == 0)
{
version_minor = string_to_size (val, NULL);
version_minor = string_to_off (val, NULL);
}
else if (strcmp (kw, "realsize") == 0
|| strcmp (kw, "size") == 0)
@@ -217,17 +198,27 @@ read_xheader (char *name)
}
else if (strcmp (kw, "numblocks") == 0)
{
sparse_map_size = string_to_size (val, NULL);
sparse_map = emalloc (sparse_map_size * sizeof *sparse_map);
sparse_map_size = string_to_size (val, NULL,
SIZE_MAX / sizeof *sparse_map);
if (sparse_map_size)
{
sparse_map = emalloc (sparse_map_size * sizeof *sparse_map);
sparse_map[0].offset = -1;
}
}
else if (strcmp (kw, "offset") == 0)
{
if (sparse_map_size <= i)
die (1, "bad GNU.sparse.map: spurious offset");
sparse_map[i].offset = string_to_off (val, NULL);
expect = "numbytes";
}
else if (strcmp (kw, "numbytes") == 0)
{
if (sparse_map_size <= i || sparse_map[i].offset < 0)
die (1, "bad GNU.sparse.map: spurious numbytes");
sparse_map[i++].numbytes = string_to_off (val, NULL);
if (i < sparse_map_size)
sparse_map[i].offset = -1;
}
else if (strcmp (kw, "map") == 0)
{
@@ -235,13 +226,13 @@ read_xheader (char *name)
{
sparse_map[i].offset = string_to_off (val, &val);
if (*val != ',')
die (1, "bad GNU.sparse.map: expected `,' but found `%c'",
die (1, "bad GNU.sparse.map: expected ',' but found '%c'",
*val);
sparse_map[i].numbytes = string_to_off (val+1, &val);
if (*val != ',')
{
if (!(*val == 0 && i == sparse_map_size-1))
die (1, "bad GNU.sparse.map: expected `,' but found `%c'",
die (1, "bad GNU.sparse.map: expected ',' but found '%c'",
*val);
}
else
@@ -251,16 +242,15 @@ read_xheader (char *name)
die (1, "bad GNU.sparse.map: garbage at the end");
}
}
if (expect)
die (1, "bad keyword sequence: expected `%s' not found", expect);
if (version_major == 0 && sparse_map_size == 0)
die (1, "size of the sparse map unknown");
if (i != sparse_map_size)
die (1, "not all sparse entries supplied");
fclose (fp);
if (ferror (fp) || fclose (fp) < 0)
die (1, "read error: %s", name);
}
void
static void
read_map (FILE *ifp)
{
size_t i;
@@ -270,7 +260,7 @@ read_map (FILE *ifp)
printf ("Reading v.1.0 sparse map\n");
get_line (nbuf, sizeof nbuf, ifp);
sparse_map_size = string_to_size (nbuf, NULL);
sparse_map_size = string_to_size (nbuf, NULL, SIZE_MAX / sizeof *sparse_map);
sparse_map = emalloc (sparse_map_size * sizeof *sparse_map);
for (i = 0; i < sparse_map_size; i++)
@@ -281,52 +271,51 @@ read_map (FILE *ifp)
sparse_map[i].numbytes = string_to_off (nbuf, NULL);
}
fseeko (ifp, ((ftell (ifp) + BLOCKSIZE - 1) / BLOCKSIZE) * BLOCKSIZE,
SEEK_SET);
off_t ifp_offset = ftello (ifp);
if (ifp_offset < 0)
die (1, "ftello");
if (ifp_offset % BLOCKSIZE != 0
&& fseeko (ifp, BLOCKSIZE - ifp_offset % BLOCKSIZE, SEEK_CUR) < 0)
die (1, "fseeko");
}
void
static void
expand_sparse (FILE *sfp, int ofd)
{
size_t i;
off_t max_numbytes = 0;
size_t maxbytes;
char *buffer;
for (i = 0; i < sparse_map_size; i++)
if (max_numbytes < sparse_map[i].numbytes)
max_numbytes = sparse_map[i].numbytes;
maxbytes = max_numbytes < SIZE_MAX ? max_numbytes : SIZE_MAX;
for (buffer = malloc (maxbytes); !buffer; maxbytes /= 2)
if (maxbytes == 0)
die (1, "not enough memory");
for (i = 0; i < sparse_map_size; i++)
{
off_t size = sparse_map[i].numbytes;
if (size == 0)
ftruncate (ofd, sparse_map[i].offset);
{
if (0 <= ofd && ftruncate (ofd, sparse_map[i].offset) < 0)
die (1, "ftruncate error (%d)", errno);
}
else
{
lseek (ofd, sparse_map[i].offset, SEEK_SET);
if (0 <= ofd && lseek (ofd, sparse_map[i].offset, SEEK_SET) < 0)
die (1, "lseek error (%d)", errno);
while (size)
{
size_t rdsize = (size < maxbytes) ? size : maxbytes;
char buffer[BUFSIZ];
size_t rdsize = size < BUFSIZ ? size : BUFSIZ;
if (rdsize != fread (buffer, 1, rdsize, sfp))
die (1, "read error (%d)", errno);
if (rdsize != write (ofd, buffer, rdsize))
die (1, "write error (%d)", errno);
if (0 <= ofd)
{
ssize_t written = write (ofd, buffer, rdsize);
if (written != rdsize)
die (1, "write error (%d)", written < 0 ? errno : 0);
}
size -= rdsize;
}
}
}
free (buffer);
}
void
static void
usage (int code)
{
printf ("Usage: %s [OPTIONS] infile [outfile]\n", progname);
@@ -341,58 +330,26 @@ usage (int code)
exit (code);
}
void
static void
guess_outname (char *name)
{
char *p;
char *s;
if (name[0] == '.' && name[1] == '/')
name += 2;
p = name + strlen (name) - 1;
s = NULL;
for (; p > name && *p != '/'; p--)
;
if (*p == '/')
s = p + 1;
if (p != name)
{
for (p--; p > name && *p != '/'; p--)
;
}
if (*p != '/')
{
if (s)
outname = s;
else
{
outname = emalloc (4 + strlen (name));
strcpy (outname, "../");
strcpy (outname + 3, name);
}
}
else
{
size_t len = p - name + 1;
outname = emalloc (len + strlen (s) + 1);
memcpy (outname, name, len);
strcpy (outname + len, s);
}
char *base = strrchr (name, '/');
base = base ? base + 1 : name;
size_t dirlen = base - name, baselen = strlen (base);
static char const parentdir[] = "../";
int parentdirlen = sizeof parentdir - 1;
outname = emalloc (dirlen + parentdirlen + baselen + 1);
memcpy (outname, name, dirlen);
memcpy (outname + dirlen, parentdir, parentdirlen);
memcpy (outname + dirlen + parentdirlen, base, baselen + 1);
}
int
main (int argc, char **argv)
{
int c;
int dry_run = 0;
bool dry_run = false;
char *xheader_file = NULL;
char *inname;
FILE *ifp;
struct stat st;
int ofd;
progname = argv[0];
while ((c = getopt (argc, argv, "hnvx:")) != EOF)
@@ -408,9 +365,9 @@ main (int argc, char **argv)
break;
case 'n':
dry_run = 1;
dry_run = true;
case 'v':
verbose++;
verbose = true;
break;
default:
@@ -427,15 +384,16 @@ main (int argc, char **argv)
if (xheader_file)
read_xheader (xheader_file);
inname = argv[0];
char *inname = argv[0];
if (argv[1])
outname = argv[1];
if (stat (inname, &st))
struct stat st;
if (stat (inname, &st) < 0)
die (1, "cannot stat %s (%d)", inname, errno);
ifp = fopen (inname, "r");
if (ifp == NULL)
FILE *ifp = fopen (inname, "r");
if (!ifp)
die (1, "cannot open file %s (%d)", inname, errno);
if (!xheader_file || version_major == 1)
@@ -444,12 +402,26 @@ main (int argc, char **argv)
if (!outname)
guess_outname (inname);
ofd = open (outname, O_RDWR|O_CREAT|O_TRUNC, st.st_mode);
if (ofd == -1)
die (1, "cannot open file %s (%d)", outname, errno);
if (verbose)
printf ("Expanding file '%s' to '%s'\n", inname, outname);
int ofd = -1;
if (!dry_run)
{
ofd = open (outname, O_RDWR | O_CREAT | O_TRUNC, st.st_mode);
if (ofd < 0)
die (1, "cannot open file %s (%d)", outname, errno);
}
expand_sparse (ifp, ofd);
if (ferror (ifp) || fclose (ifp) < 0)
die (1, "input error: %s", inname);
if (close (ofd) < 0)
die (1, "output error: %s", outname);
if (verbose)
printf ("Expanding file `%s' to `%s'\n", inname, outname);
printf ("Done\n");
if (dry_run)
{
@@ -457,17 +429,9 @@ main (int argc, char **argv)
return 0;
}
expand_sparse (ifp, ofd);
fclose (ifp);
close (ofd);
if (verbose)
printf ("Done\n");
if (outsize)
{
if (stat (outname, &st))
if (stat (outname, &st) < 0)
die (1, "cannot stat output file %s (%d)", outname, errno);
if (st.st_size != outsize)
die (1, "expanded file has wrong size");

View File

@@ -1,26 +1,25 @@
# Makefile for GNU tar sources.
# Copyright (C) 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2003, 2006,
# 2007, 2009 Free Software Foundation, Inc.
# Copyright 1994-2025 Free Software Foundation, Inc.
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3, or (at your option)
## any later version.
# This file is part of GNU tar.
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
bin_PROGRAMS = tar
noinst_HEADERS = arith.h common.h tar.h
noinst_HEADERS = arith.h common.h tar.h xattrs.h
tar_SOURCES = \
buffer.c\
checkpoint.c\
@@ -28,10 +27,12 @@ tar_SOURCES = \
create.c\
delete.c\
exit.c\
exclist.c\
extract.c\
xheader.c\
incremen.c\
list.c\
map.c\
misc.c\
names.c\
sparse.c\
@@ -42,10 +43,14 @@ tar_SOURCES = \
unlink.c\
update.c\
utf8.c\
warning.c
warning.c\
xattrs.c
INCLUDES = -I$(top_srcdir)/gnu -I../ -I../gnu -I$(top_srcdir)/lib -I../lib
AM_CPPFLAGS = -I$(top_srcdir)/gnu -I../ -I../gnu -I$(top_srcdir)/lib -I../lib
AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
LDADD = ../lib/libtar.a ../gnu/libgnu.a $(LIBINTL) $(LIBICONV)
tar_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_EACCESS)
tar_LDADD = $(LIBS) ../lib/libtar.a ../gnu/libgnu.a\
$(LIB_ACL) $(QCOPY_ACL_LIB) $(CLOCK_TIME_LIB) $(EUIDACCESS_LIBGEN)\
$(GETRANDOM_LIB) $(HARD_LOCALE_LIB) $(FILE_HAS_ACL_LIB) $(MBRTOWC_LIB)\
$(LIB_SELINUX) $(SETLOCALE_NULL_LIB) \
$(LIBINTL) $(LIBICONV)

View File

@@ -1,19 +1,20 @@
/* Long integers, for GNU tar.
Copyright 1999, 2007 Free Software Foundation, Inc.
Copyright 1999-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
This file is part of GNU tar.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Handle large integers for calculating big tape lengths and the
like. In practice, double precision does for now. On the vast

File diff suppressed because it is too large Load Diff

View File

@@ -1,23 +1,34 @@
/* Checkpoint management for tar.
Copyright (C) 2007 Free Software Foundation, Inc.
Copyright 2007-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
This file is part of GNU tar.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>. */
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <system.h>
#include "common.h"
#include <wordsplit.h>
#include <flexmember.h>
#include <fprintftime.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <signal.h>
enum checkpoint_opcode
{
cop_dot,
@@ -25,7 +36,9 @@ enum checkpoint_opcode
cop_echo,
cop_ttyout,
cop_sleep,
cop_exec
cop_exec,
cop_totals,
cop_wait
};
struct checkpoint_action
@@ -36,158 +49,317 @@ struct checkpoint_action
{
time_t time;
char *command;
int signal;
} v;
char commandbuf[FLEXIBLE_ARRAY_MEMBER];
};
/* Checkpointing counter */
static unsigned checkpoint;
static intmax_t checkpoint;
/* List of checkpoint actions */
static struct checkpoint_action *checkpoint_action, *checkpoint_action_tail;
static struct checkpoint_action *checkpoint_action,
**checkpoint_action_tail = &checkpoint_action;
/* State of the checkpoint system */
static enum {
CHKP_INIT, /* Needs initialization */
CHKP_COMPILE, /* Actions are being compiled */
CHKP_RUN /* Actions are being run */
} checkpoint_state;
/* Blocked signals */
static sigset_t sigs;
static struct checkpoint_action *
alloc_action (enum checkpoint_opcode opcode)
alloc_action (enum checkpoint_opcode opcode, char const *quoted_string)
{
struct checkpoint_action *p = xzalloc (sizeof *p);
if (checkpoint_action_tail)
checkpoint_action_tail->next = p;
else
checkpoint_action = p;
checkpoint_action_tail = p;
idx_t quoted_size = quoted_string ? strlen (quoted_string) + 1 : 0;
struct checkpoint_action *p = xmalloc (FLEXSIZEOF (struct checkpoint_action,
commandbuf, quoted_size));
*checkpoint_action_tail = p;
checkpoint_action_tail = &p->next;
p->next = NULL;
p->opcode = opcode;
return p;
}
static char *
copy_string_unquote (const char *str)
{
char *output = xstrdup (str);
size_t len = strlen (output);
if ((*output == '"' || *output == '\'')
&& output[len-1] == *output)
if (quoted_string)
{
memmove (output, output+1, len-2);
output[len-2] = 0;
p->v.command = memcpy (p->commandbuf, quoted_string, quoted_size);
unquote_string (p->v.command);
}
unquote_string (output);
return output;
return p;
}
void
checkpoint_compile_action (const char *str)
{
struct checkpoint_action *act;
if (checkpoint_state == CHKP_INIT)
{
sigemptyset (&sigs);
checkpoint_state = CHKP_COMPILE;
}
if (strcmp (str, ".") == 0 || strcmp (str, "dot") == 0)
alloc_action (cop_dot);
alloc_action (cop_dot, NULL);
else if (strcmp (str, "bell") == 0)
alloc_action (cop_bell);
alloc_action (cop_bell, NULL);
else if (strcmp (str, "echo") == 0)
alloc_action (cop_echo);
alloc_action (cop_echo, NULL)->v.command = NULL;
else if (strncmp (str, "echo=", 5) == 0)
{
act = alloc_action (cop_echo);
act->v.command = copy_string_unquote (str + 5);
}
alloc_action (cop_echo, str + 5);
else if (strncmp (str, "exec=", 5) == 0)
{
act = alloc_action (cop_exec);
act->v.command = copy_string_unquote (str + 5);
}
alloc_action (cop_exec, str + 5);
else if (strncmp (str, "ttyout=", 7) == 0)
{
act = alloc_action (cop_ttyout);
act->v.command = copy_string_unquote (str + 7);
}
alloc_action (cop_ttyout, str + 7);
else if (strncmp (str, "sleep=", 6) == 0)
{
char const *arg = str + 6;
char *p;
time_t n = strtoul (str+6, &p, 10);
if (*p)
FATAL_ERROR ((0, 0, _("%s: not a valid timeout"), str));
act = alloc_action (cop_sleep);
act->v.time = n;
alloc_action (cop_sleep, NULL)->v.time
= stoint (arg, &p, NULL, 0, TYPE_MAXIMUM (time_t));
if ((p == arg) | *p)
paxfatal (0, _("%s: not a valid timeout"), str);
}
else if (strcmp (str, "totals") == 0)
alloc_action (cop_totals, NULL);
else if (strncmp (str, "wait=", 5) == 0)
{
int sig = decode_signal (str + 5);
alloc_action (cop_wait, NULL)->v.signal = sig;
sigaddset (&sigs, sig);
}
else
FATAL_ERROR ((0, 0, _("%s: unknown checkpoint action"), str));
paxfatal (0, _("%s: unknown checkpoint action"), str);
}
void
checkpoint_finish_compile ()
checkpoint_finish_compile (void)
{
if (checkpoint_option)
if (checkpoint_state == CHKP_INIT
&& checkpoint_option
&& !checkpoint_action)
{
if (!checkpoint_action)
/* Provide a historical default */
checkpoint_compile_action ("echo");
/* Provide a historical default */
checkpoint_compile_action ("echo");
}
else if (checkpoint_action)
/* Otherwise, set default checkpoint rate */
checkpoint_option = DEFAULT_CHECKPOINT;
if (checkpoint_state == CHKP_COMPILE)
{
sigprocmask (SIG_BLOCK, &sigs, NULL);
if (!checkpoint_option)
/* set default checkpoint rate */
checkpoint_option = DEFAULT_CHECKPOINT;
checkpoint_state = CHKP_RUN;
}
}
static intmax_t
getwidth (FILE *fp)
{
char const *columns;
#ifdef TIOCGWINSZ
struct winsize ws;
if (ioctl (fileno (fp), TIOCGWINSZ, &ws) == 0 && 0 < ws.ws_col)
return ws.ws_col;
#endif
columns = getenv ("COLUMNS");
if (columns)
{
char *end;
intmax_t col = stoint (columns, &end, NULL, 0, INTMAX_MAX);
if (! (*end | !col))
return col;
}
return 80;
}
static char *
expand_checkpoint_string (const char *input, bool do_write, unsigned cpn)
getarg (char const *input, char const **endp, char **argbuf, idx_t *arglen)
{
const char *opstr = do_write ? gettext ("write") : gettext ("read");
size_t opstrlen = strlen (opstr);
char uintbuf[UINTMAX_STRSIZE_BOUND];
char *cps = STRINGIFY_BIGINT (cpn, uintbuf);
size_t cpslen = strlen (cps);
const char *ip;
char *op;
char *output;
size_t outlen = strlen (input); /* Initial guess */
/* Fix the initial length guess */
for (ip = input; (ip = strchr (ip, '%')) != NULL; )
if (input[0] == '{')
{
switch (ip[1])
char *p = strchr (input + 1, '}');
if (p)
{
case 'u':
outlen += cpslen - 2;
break;
case 's':
outlen += opstrlen - 2;
idx_t n = p - input;
if (n > *arglen)
*argbuf = xpalloc (*argbuf, arglen, n - *arglen, -1, 1);
n--;
*endp = p + 1;
(*argbuf)[n] = 0;
return memcpy (*argbuf, input + 1, n);
}
ip++;
}
output = xmalloc (outlen + 1);
for (ip = input, op = output; *ip; )
*endp = input;
return NULL;
}
static bool tty_cleanup;
static const char *def_format =
"%{%Y-%m-%d %H:%M:%S}t: %ds, %{read,wrote}T%*\r";
static intmax_t
format_checkpoint_string (FILE *fp, intmax_t len,
const char *input, bool do_write,
intmax_t cpn)
{
const char *opstr = do_write ? gettext ("write") : gettext ("read");
const char *ip;
static char *argbuf = NULL;
static idx_t arglen = 0;
char *arg = NULL;
if (!input)
{
if (do_write)
/* TRANSLATORS: This is a "checkpoint of write operation",
*not* "Writing a checkpoint". */
input = gettext ("Write checkpoint %u");
else
/* TRANSLATORS: This is a "checkpoint of read operation",
*not* "Reading a checkpoint". */
input = gettext ("Read checkpoint %u");
}
for (ip = input; *ip; ip++)
{
if (*ip == '%')
{
switch (*++ip)
if (*++ip == '{')
{
arg = getarg (ip, &ip, &argbuf, &arglen);
if (!arg)
{
fputc ('%', fp);
fputc (*ip, fp);
len = add_printf (len, 2);
continue;
}
}
switch (*ip)
{
case 'c':
len = add_printf (len,
format_checkpoint_string (fp, len, def_format,
do_write, cpn));
break;
case 'u':
op = stpcpy (op, cps);
len = add_printf (len, fprintf (fp, "%jd", cpn));
break;
case 's':
op = stpcpy (op, opstr);
fputs (opstr, fp);
len = add_printf (len, strlen (opstr));
break;
case 'd':
len = add_printf (len,
fprintf (fp, "%.0f",
compute_duration_ns () / BILLION));
break;
case 'T':
{
static char const *const checkpoint_total_format[]
= { "R", "W", "D" };
char const *const *fmt = checkpoint_total_format, *fmtbuf[3];
struct wordsplit ws;
compute_duration_ns ();
if (arg)
{
ws.ws_delim = ",";
if (wordsplit (arg, &ws,
(WRDSF_NOVAR | WRDSF_NOCMD
| WRDSF_QUOTE | WRDSF_DELIM))
!= WRDSE_OK)
paxerror (0, _("cannot split string '%s': %s"),
arg, wordsplit_strerror (&ws));
else if (3 < ws.ws_wordc)
paxerror (0, _("too many words in '%s'"), arg);
else
{
int i;
for (i = 0; i < ws.ws_wordc; i++)
fmtbuf[i] = ws.ws_wordv[i];
for (; i < 3; i++)
fmtbuf[i] = NULL;
fmt = fmtbuf;
}
}
len = add_printf (len, format_total_stats (fp, fmt, ',', 0));
if (arg)
wordsplit_free (&ws);
}
break;
case 't':
{
struct timespec ts = current_timespec ();
const char *fmt = arg ? arg : "%c";
struct tm *tm = localtime (&ts.tv_sec);
len = add_printf (len,
(tm ? fprintftime (fp, fmt, tm, 0, ts.tv_nsec)
: fprintf (fp, "????""-??""-?? ??:??:??")));
}
break;
case '*':
if (0 <= len)
{
intmax_t w;
if (!arg)
w = getwidth (fp);
else
{
char *end;
w = stoint (arg, &end, NULL, 0, INTMAX_MAX);
if ((end == arg) | *end)
w = 80;
}
for (; w > len; len++)
fputc (' ', fp);
}
break;
default:
*op++ = '%';
*op++ = *ip;
fputc ('%', fp);
fputc (*ip, fp);
len = add_printf (len, 2);
break;
}
ip++;
arg = NULL;
}
else
*op++ = *ip++;
{
fputc (*ip, fp);
if (*ip == '\r')
{
len = 0;
tty_cleanup = true;
}
else
len = add_printf (len, 1);
}
}
*op = 0;
return output;
fflush (fp);
return len;
}
static FILE *tty = NULL;
static void
run_checkpoint_actions (bool do_write)
{
struct checkpoint_action *p;
FILE *tty = NULL;
for (p = checkpoint_action; p; p = p->next)
{
@@ -210,26 +382,10 @@ run_checkpoint_actions (bool do_write)
case cop_echo:
{
char *tmp;
const char *str = p->v.command;
if (!str)
{
if (do_write)
/* TRANSLATORS: This is a ``checkpoint of write operation'',
*not* ``Writing a checkpoint''.
E.g. in Spanish ``Punto de comprobaci@'on de escritura'',
*not* ``Escribiendo un punto de comprobaci@'on'' */
str = gettext ("Write checkpoint %u");
else
/* TRANSLATORS: This is a ``checkpoint of read operation'',
*not* ``Reading a checkpoint''.
E.g. in Spanish ``Punto de comprobaci@'on de lectura'',
*not* ``Leyendo un punto de comprobaci@'on'' */
str = gettext ("Read checkpoint %u");
}
tmp = expand_checkpoint_string (str, do_write, checkpoint);
WARN ((0, 0, "%s", tmp));
free (tmp);
int n = fprintf (stderr, "%s: ", program_name);
format_checkpoint_string (stderr, n, p->v.command, do_write,
checkpoint);
fputc ('\n', stderr);
}
break;
@@ -237,13 +393,8 @@ run_checkpoint_actions (bool do_write)
if (!tty)
tty = fopen ("/dev/tty", "w");
if (tty)
{
char *tmp = expand_checkpoint_string (p->v.command, do_write,
checkpoint);
fprintf (tty, "%s", tmp);
fflush (tty);
free (tmp);
}
format_checkpoint_string (tty, 0, p->v.command, do_write,
checkpoint);
break;
case cop_sleep:
@@ -255,10 +406,44 @@ run_checkpoint_actions (bool do_write)
archive_name_cursor[0],
checkpoint);
break;
case cop_totals:
compute_duration_ns ();
print_total_stats ();
break;
case cop_wait:
{
int n;
sigwait (&sigs, &n);
}
}
}
}
void
checkpoint_flush_actions (void)
{
struct checkpoint_action *p;
for (p = checkpoint_action; p; p = p->next)
{
switch (p->opcode)
{
case cop_ttyout:
if (tty && tty_cleanup)
{
intmax_t w = getwidth (tty);
while (w--)
fputc (' ', tty);
fputc ('\r', tty);
fflush (tty);
}
break;
default:
/* nothing */;
}
}
if (tty)
fclose (tty);
}
void
@@ -267,3 +452,14 @@ checkpoint_run (bool do_write)
if (checkpoint_option && !(++checkpoint % checkpoint_option))
run_checkpoint_actions (do_write);
}
void
checkpoint_finish (void)
{
if (checkpoint_option)
{
checkpoint_flush_actions ();
if (tty)
fclose (tty);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,34 +1,40 @@
/* Diff files from a tar archive.
Copyright (C) 1988, 1992, 1993, 1994, 1996, 1997, 1999, 2000, 2001,
2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
Copyright 1988-2025 Free Software Foundation, Inc.
Written by John Gilmore, on 1987-04-30.
This file is part of GNU tar.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Written by John Gilmore, on 1987-04-30. */
#include <system.h>
#include <system-ioctl.h>
#if HAVE_LINUX_FD_H
# include <linux/fd.h>
#endif
#if HAVE_SYS_MTIO_H
# include <sys/ioctl.h>
# include <sys/mtio.h>
#endif
#include "common.h"
#include <alignalloc.h>
#include <quotearg.h>
#include <rmt.h>
#include <same-inode.h>
#include <stdarg.h>
/* Nonzero if we are verifying at the moment. */
@@ -44,12 +50,13 @@ static char *diff_buffer;
void
diff_init (void)
{
void *ptr;
diff_buffer = page_aligned_alloc (&ptr, record_size);
diff_buffer = xalignalloc (getpagesize (), record_size);
if (listed_incremental_option)
read_directory_file ();
}
enum { QUOTE_ARG, QUOTE_NAME };
/* Sigh about something that differs by writing a MESSAGE to stdlis,
given MESSAGE is nonzero. Also set the exit status if not already. */
void
@@ -59,7 +66,7 @@ report_difference (struct tar_stat_info *st, const char *fmt, ...)
{
va_list ap;
fprintf (stdlis, "%s: ", quotearg_colon (st->file_name));
fprintf (stdlis, "%s: ", quote_n_colon (QUOTE_NAME, st->file_name));
va_start (ap, fmt);
vfprintf (stdlis, fmt, ap);
va_end (ap);
@@ -70,21 +77,20 @@ report_difference (struct tar_stat_info *st, const char *fmt, ...)
}
/* Take a buffer returned by read_and_process and do nothing with it. */
static int
process_noop (size_t size __attribute__ ((unused)),
char *data __attribute__ ((unused)))
static bool
process_noop (MAYBE_UNUSED idx_t size, MAYBE_UNUSED char *data)
{
return 1;
return true;
}
static int
process_rawdata (size_t bytes, char *buffer)
static bool
process_rawdata (idx_t bytes, char *buffer)
{
size_t status = safe_read (diff_handle, diff_buffer, bytes);
idx_t status = blocking_read (diff_handle, diff_buffer, bytes);
if (status != bytes)
if (status < bytes)
{
if (status == SAFE_READ_ERROR)
if (errno)
{
read_error (current_stat_info.file_name);
report_difference (&current_stat_info, NULL);
@@ -92,53 +98,48 @@ process_rawdata (size_t bytes, char *buffer)
else
{
report_difference (&current_stat_info,
ngettext ("Could only read %lu of %lu byte",
"Could only read %lu of %lu bytes",
ngettext ("Could read only %td of %td byte",
"Could read only %td of %td bytes",
bytes),
(unsigned long) status, (unsigned long) bytes);
status, bytes);
}
return 0;
return false;
}
if (memcmp (buffer, diff_buffer, bytes))
if (memcmp (buffer, diff_buffer, bytes) != 0)
{
report_difference (&current_stat_info, _("Contents differ"));
return 0;
return false;
}
return 1;
return true;
}
/* Some other routine wants SIZE bytes in the archive. For each chunk
of the archive, call PROCESSOR with the size of the chunk, and the
address of the chunk it can work with. The PROCESSOR should return
nonzero for success. Once it returns error, continue skipping
without calling PROCESSOR anymore. */
/* Some other routine wants ST->stat.st_size bytes in the archive.
For each chunk of the archive, call PROCESSOR with the size of the chunk,
and the address of the chunk it can work with. PROCESSOR should return
true for success. Once it fails, continue skipping without calling
PROCESSOR anymore. */
static void
read_and_process (struct tar_stat_info *st, int (*processor) (size_t, char *))
read_and_process (struct tar_stat_info *st, bool (*processor) (idx_t, char *))
{
union block *data_block;
size_t data_size;
off_t size = st->stat.st_size;
mv_begin_read (st);
while (size)
for (off_t size = st->stat.st_size; size; )
{
data_block = find_next_block ();
union block *data_block = find_next_block ();
if (! data_block)
{
ERROR ((0, 0, _("Unexpected EOF in archive")));
paxerror (0, _("Unexpected EOF in archive"));
return;
}
data_size = available_space_after (data_block);
idx_t data_size = available_space_after (data_block);
if (data_size > size)
data_size = size;
if (!(*processor) (data_size, data_block->buffer))
if (!processor (data_size, charptr (data_block)))
processor = process_noop;
set_next_block_after ((union block *)
(data_block->buffer + data_size - 1));
set_next_block_after (charptr (data_block) + data_size - 1);
size -= data_size;
mv_size_left (size);
}
@@ -147,23 +148,18 @@ read_and_process (struct tar_stat_info *st, int (*processor) (size_t, char *))
/* Call either stat or lstat over STAT_DATA, depending on
--dereference (-h), for a file which should exist. Diagnose any
problem. Return nonzero for success, zero otherwise. */
static int
problem. Return true for success, false otherwise. */
static bool
get_stat_data (char const *file_name, struct stat *stat_data)
{
int status = deref_stat (file_name, stat_data);
if (status != 0)
if (deref_stat (file_name, stat_data) < 0)
{
if (errno == ENOENT)
stat_warn (file_name);
else
stat_error (file_name);
(errno == ENOENT ? stat_warn : stat_error) (file_name);
report_difference (&current_stat_info, NULL);
return 0;
return false;
}
return 1;
return true;
}
@@ -227,23 +223,21 @@ diff_file (void)
}
else
{
int status;
if (current_stat_info.is_sparse)
sparse_diff_file (diff_handle, &current_stat_info);
else
read_and_process (&current_stat_info, process_rawdata);
if (atime_preserve_option == replace_atime_preserve)
if (atime_preserve_option == replace_atime_preserve
&& stat_data.st_size != 0)
{
struct timespec atime = get_stat_atime (&stat_data);
if (set_file_atime (diff_handle, chdir_fd, file_name, atime)
!= 0)
< 0)
utime_error (file_name);
}
status = close (diff_handle);
if (status != 0)
if (close (diff_handle) < 0)
close_error (file_name);
}
}
@@ -258,21 +252,22 @@ diff_link (void)
if (get_stat_data (current_stat_info.file_name, &file_data)
&& get_stat_data (current_stat_info.link_name, &link_data)
&& !sys_compare_links (&file_data, &link_data))
&& !psame_inode (&file_data, &link_data))
report_difference (&current_stat_info,
_("Not linked to %s"),
quote (current_stat_info.link_name));
quote_n_colon (QUOTE_ARG,
current_stat_info.link_name));
}
#ifdef HAVE_READLINK
static void
diff_symlink (void)
{
size_t len = strlen (current_stat_info.link_name);
char *linkbuf = alloca (len + 1);
char buf[1024];
idx_t len = strlen (current_stat_info.link_name);
char *linkbuf = len < sizeof buf ? buf : xmalloc (len + 1);
int status = readlinkat (chdir_fd, current_stat_info.file_name,
linkbuf, len + 1);
ssize_t status = readlinkat (chdir_fd, current_stat_info.file_name,
linkbuf, len + 1);
if (status < 0)
{
@@ -283,10 +278,12 @@ diff_symlink (void)
report_difference (&current_stat_info, NULL);
}
else if (status != len
|| strncmp (current_stat_info.link_name, linkbuf, len) != 0)
|| memcmp (current_stat_info.link_name, linkbuf, len) != 0)
report_difference (&current_stat_info, _("Symlink differs"));
if (linkbuf != buf)
free (linkbuf);
}
#endif
static void
diff_special (void)
@@ -322,82 +319,91 @@ diff_special (void)
report_difference (&current_stat_info, _("Mode differs"));
}
static int
/* Return zero if and only if A and B should be considered equal.
for the purposes of dump directory comparison. */
static char
dumpdir_cmp (const char *a, const char *b)
{
size_t len;
while (*a)
switch (*a)
{
case 'Y':
case 'N':
if (!strchr ("YN", *b))
/* If the null-terminated strings A and B are equal, other
than possibly A's first byte being 'Y' where B's is 'N' or
vice versa, advance A and B past the strings.
Otherwise, return 1. */
if (! (*b == 'Y' || *b == 'N'))
return 1;
if (strcmp(a + 1, b + 1))
return 1;
len = strlen (a) + 1;
a += len;
b += len;
break;
a++, b++;
FALLTHROUGH;
case 'D':
if (strcmp(a, b))
/* If the null-terminated strings A and B are equal, advance A
and B past them. Otherwise, return 1. */
while (*a)
if (*a++ != *b++)
return 1;
if (*b)
return 1;
len = strlen (a) + 1;
a += len;
b += len;
a++, b++;
break;
case 'R':
case 'T':
case 'X':
return *b;
default:
unreachable ();
}
return *b;
}
static void
diff_dumpdir (void)
diff_dumpdir (struct tar_stat_info *dir)
{
const char *dumpdir_buffer;
dev_t dev = 0;
struct stat stat_data;
if (deref_stat (current_stat_info.file_name, &stat_data) != 0)
if (dir->fd == 0)
{
if (errno == ENOENT)
stat_warn (current_stat_info.file_name);
void (*diag) (char const *) = NULL;
int fd = subfile_open (dir->parent, dir->orig_file_name, open_read_flags);
if (fd < 0)
diag = open_diag;
else if (fstat (fd, &dir->stat) < 0)
{
diag = stat_diag;
close (fd);
}
else
stat_error (current_stat_info.file_name);
dir->fd = fd;
if (diag)
{
file_removed_diag (dir->orig_file_name, false, diag);
return;
}
}
else
dev = stat_data.st_dev;
dumpdir_buffer = directory_contents (scan_directory (&current_stat_info));
dumpdir_buffer = directory_contents (scan_directory (dir));
if (dumpdir_buffer)
{
if (dumpdir_cmp (current_stat_info.dumpdir, dumpdir_buffer))
report_difference (&current_stat_info, _("Contents differ"));
if (dumpdir_cmp (dir->dumpdir, dumpdir_buffer) != 0)
report_difference (dir, _("Contents differ"));
}
else
read_and_process (&current_stat_info, process_noop);
read_and_process (dir, process_noop);
}
static void
diff_multivol (void)
{
struct stat stat_data;
int fd, status;
off_t offset;
if (current_stat_info.had_trailing_slash)
{
diff_dir ();
return;
}
struct stat stat_data;
if (!get_stat_data (current_stat_info.file_name, &stat_data))
return;
@@ -408,8 +414,11 @@ diff_multivol (void)
return;
}
offset = OFF_FROM_HEADER (current_header->oldgnu_header.offset);
if (stat_data.st_size != current_stat_info.stat.st_size + offset)
off_t offset = OFF_FROM_HEADER (current_header->oldgnu_header.offset);
off_t file_size;
if (offset < 0
|| ckd_add (&file_size, current_stat_info.stat.st_size, offset)
|| stat_data.st_size != file_size)
{
report_difference (&current_stat_info, _("Size differs"));
skip_member ();
@@ -417,7 +426,7 @@ diff_multivol (void)
}
fd = openat (chdir_fd, current_stat_info.file_name, open_read_flags);
int fd = openat (chdir_fd, current_stat_info.file_name, open_read_flags);
if (fd < 0)
{
@@ -431,13 +440,11 @@ diff_multivol (void)
{
seek_error_details (current_stat_info.file_name, offset);
report_difference (&current_stat_info, NULL);
return;
}
else
read_and_process (&current_stat_info, process_rawdata);
read_and_process (&current_stat_info, process_rawdata);
status = close (fd);
if (status != 0)
if (close (fd) < 0)
close_error (current_stat_info.file_name);
}
@@ -460,11 +467,10 @@ diff_archive (void)
switch (current_header->header.typeflag)
{
default:
ERROR ((0, 0, _("%s: Unknown file type `%c', diffed as normal file"),
quotearg_colon (current_stat_info.file_name),
current_header->header.typeflag));
/* Fall through. */
paxerror (0, _("%s: Unknown file type '%c', diffed as normal file"),
quotearg_colon (current_stat_info.file_name),
current_header->header.typeflag);
FALLTHROUGH;
case AREGTYPE:
case REGTYPE:
case GNUTYPE_SPARSE:
@@ -482,11 +488,9 @@ diff_archive (void)
diff_link ();
break;
#ifdef HAVE_READLINK
case SYMTYPE:
diff_symlink ();
break;
#endif
case CHRTYPE:
case BLKTYPE:
@@ -497,7 +501,7 @@ diff_archive (void)
case GNUTYPE_DUMPDIR:
case DIRTYPE:
if (is_dumpdir (&current_stat_info))
diff_dumpdir ();
diff_dumpdir (&current_stat_info);
diff_dir ();
break;
@@ -512,13 +516,22 @@ diff_archive (void)
void
verify_volume (void)
{
bool may_fail = false;
if (removed_prefixes_p ())
{
WARN((0, 0,
_("Archive contains file names with leading prefixes removed.")));
WARN((0, 0,
_("Verification may fail to locate original files.")));
paxwarn (0,
_("Archive contains file names with leading prefixes removed."));
may_fail = true;
}
if (transform_program_p ())
{
paxwarn (0, _("Archive contains transformed file names."));
may_fail = true;
}
if (may_fail)
paxwarn (0, _("Verification may fail to locate original files."));
clear_directory_table ();
if (!diff_buffer)
diff_init ();
@@ -540,31 +553,12 @@ verify_volume (void)
ioctl (archive, FDFLUSH);
#endif
#ifdef MTIOCTOP
{
struct mtop operation;
int status;
operation.mt_op = MTBSF;
operation.mt_count = 1;
if (status = rmtioctl (archive, MTIOCTOP, (char *) &operation), status < 0)
{
if (errno != EIO
|| (status = rmtioctl (archive, MTIOCTOP, (char *) &operation),
status < 0))
{
#endif
if (rmtlseek (archive, (off_t) 0, SEEK_SET) != 0)
{
/* Lseek failed. Try a different method. */
seek_warn (archive_name_array[0]);
return;
}
#ifdef MTIOCTOP
}
}
}
#endif
if (!mtioseek (true, -1) && rmtlseek (archive, 0, SEEK_SET) < 0)
{
/* Lseek failed. Try a different method. */
seek_warn (archive_name_array[0]);
return;
}
access_mode = ACCESS_READ;
now_verifying = 1;
@@ -578,7 +572,7 @@ verify_volume (void)
if (status == HEADER_FAILURE)
{
int counter = 0;
intmax_t counter = 0;
do
{
@@ -589,10 +583,11 @@ verify_volume (void)
}
while (status == HEADER_FAILURE);
ERROR ((0, 0,
ngettext ("VERIFY FAILURE: %d invalid header detected",
"VERIFY FAILURE: %d invalid headers detected",
counter), counter));
paxerror (0,
ngettext ("VERIFY FAILURE: %jd invalid header detected",
"VERIFY FAILURE: %jd invalid headers detected",
counter),
counter);
}
if (status == HEADER_END_OF_FILE)
break;
@@ -601,18 +596,18 @@ verify_volume (void)
set_next_block_after (current_header);
if (!ignore_zeros_option)
{
char buf[UINTMAX_STRSIZE_BOUND];
status = read_header (&current_header, &current_stat_info,
read_header_auto);
if (status == HEADER_ZERO_BLOCK)
break;
WARNOPT (WARN_ALONE_ZERO_BLOCK,
(0, 0, _("A lone zero block at %s"),
STRINGIFY_BIGINT (current_block_ordinal (), buf)));
warnopt (WARN_ALONE_ZERO_BLOCK,
0, _("A lone zero block at %jd"),
intmax (current_block_ordinal ()));
}
continue;
}
decode_header (current_header, &current_stat_info, &current_format, true);
diff_archive ();
tar_stat_destroy (&current_stat_info);
}

View File

@@ -1,57 +0,0 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(tar.h)
PROGS="tar"
AC_SUBST(PROGS)dnl
AC_PROG_CC
AC_PROG_CPP
AC_GCC_TRADITIONAL
AC_PROG_INSTALL
AC_PROG_YACC
AC_AIX
AC_MINIX
AC_ISC_POSIX
AC_CONST
AC_RETSIGTYPE
AC_SIZE_T
AC_MAJOR_HEADER
AC_DIR_HEADER
# The 3-argument open happens to go along with the O_* defines,
# which are easier to check for.
AC_HEADER_CHECK(fcntl.h, open_header=fcntl.h, open_header=sys/file.h)
AC_COMPILE_CHECK(3-argument open,
[#include <$open_header>], [int x = O_RDONLY;], , AC_DEFINE(EMUL_OPEN3))
AC_REMOTE_TAPE
AC_RSH
AC_STDC_HEADERS
AC_UNISTD_H
echo checking for getgrgid declaration
AC_HEADER_EGREP(getgrgid, grp.h, AC_DEFINE(HAVE_GETGRGID))
echo checking for getpwuid declaration
AC_HEADER_EGREP(getpwuid, pwd.h, AC_DEFINE(HAVE_GETPWUID))
AC_HAVE_HEADERS(string.h limits.h)
echo checking default archive
# This might guess wrong, but it's not very important.
for dev in rmt8 rmt0 rmt0h rct0 rst0 tape rct/c7d0s2
do
if test -n "`ls /dev/$dev 2>/dev/null`"; then
DEF_AR_FILE=/dev/$dev
break
fi
done
if test -z "$DEF_AR_FILE"; then
DEF_AR_FILE=-
fi
AC_SUBST(DEF_AR_FILE)dnl
AC_HAVE_FUNCS(strstr valloc mkdir mknod rename ftruncate ftime getcwd)
AC_VPRINTF
AC_ALLOCA
echo checking for BSD
( test -f /vmunix || test -f /sdmach || test -f /../../mach ) && AC_DEFINE(BSD42)
echo checking for HP-UX
test "`(uname -s) 2> /dev/null`" = 'HP-UX' && MALLOC=malloc.o
AC_SUBST(MALLOC)
AC_XENIX_DIR
AC_HAVE_LIBRARY(socket, [LIBS="$LIBS -lsocket"])
AC_HAVE_LIBRARY(nsl, [LIBS="$LIBS -lnsl"])
AC_OUTPUT(Makefile)

File diff suppressed because it is too large Load Diff

View File

@@ -1,41 +1,31 @@
/* Delete entries from a tar archive.
Copyright (C) 1988, 1992, 1994, 1996, 1997, 2000, 2001, 2003, 2004,
2005, 2006, 2010 Free Software Foundation, Inc.
Copyright 1988-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
This file is part of GNU tar.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <system.h>
#include <system-ioctl.h>
#include "common.h"
#include <rmt.h>
static union block *new_record;
static int new_blocks;
static idx_t new_blocks;
static bool acting_as_filter;
/* FIXME: This module should not directly handle the following
variables, instead, the interface should be cleaned up. */
extern union block *record_start;
extern union block *record_end;
extern union block *current_block;
extern union block *recent_long_name;
extern union block *recent_long_link;
extern off_t records_read;
/* The number of records skipped at the start of the archive, when
passing over members that are not deleted. */
off_t records_skipped;
@@ -50,47 +40,37 @@ move_archive (off_t count)
if (count == 0)
return;
#ifdef MTIOCTOP
{
struct mtop operation;
if (count < 0
? (operation.mt_op = MTBSR,
operation.mt_count = -count,
operation.mt_count == -count)
: (operation.mt_op = MTFSR,
operation.mt_count = count,
operation.mt_count == count))
{
if (0 <= rmtioctl (archive, MTIOCTOP, (char *) &operation))
return;
if (errno == EIO
&& 0 <= rmtioctl (archive, MTIOCTOP, (char *) &operation))
return;
}
}
#endif /* MTIOCTOP */
{
off_t position0 = rmtlseek (archive, (off_t) 0, SEEK_CUR);
off_t increment = record_size * (off_t) count;
off_t position = position0 + increment;
if (increment / count != record_size
|| (position < position0) != (increment < 0)
|| (position = position < 0 ? 0 : position,
rmtlseek (archive, position, SEEK_SET) != position))
seek_error_details (archive_name_array[0], position);
if (mtioseek (false, count))
return;
}
off_t position0 = rmtlseek (archive, 0, SEEK_CUR), position = 0;
if (0 <= position0)
{
/* Pretend the starting position is at the first record
boundary after POSITION0. This is useful at EOF after
a short read. */
idx_t short_size = position0 % record_size;
idx_t start_offset = short_size ? record_size - short_size : 0;
off_t increment, move_start;
if (ckd_mul (&increment, record_size, count)
|| ckd_add (&move_start, position0, start_offset)
|| ckd_add (&position, move_start, increment)
|| position < 0)
{
paxerror (EOVERFLOW, "lseek: %s", archive_name_array[0]);
return;
}
else if (rmtlseek (archive, position, SEEK_SET) == position)
return;
}
if (!_isrmt (archive))
seek_error_details (archive_name_array[0], position);
}
/* Write out the record which has been filled. If MOVE_BACK_FLAG,
backspace to where we started. */
static void
write_record (int move_back_flag)
write_record (bool move_back_flag)
{
union block *save_record = record_start;
record_start = new_record;
@@ -121,22 +101,21 @@ write_record (int move_back_flag)
}
static void
write_recent_blocks (union block *h, size_t blocks)
write_recent_blocks (union block *h, idx_t blocks)
{
size_t i;
for (i = 0; i < blocks; i++)
for (idx_t i = 0; i < blocks; i++)
{
new_record[new_blocks++] = h[i];
if (new_blocks == blocking_factor)
write_record (1);
write_record (true);
}
}
static void
write_recent_bytes (char *data, size_t bytes)
write_recent_bytes (char *data, idx_t bytes)
{
size_t blocks = bytes / BLOCKSIZE;
size_t rest = bytes - blocks * BLOCKSIZE;
idx_t blocks = bytes >> LG_BLOCKSIZE;
idx_t rest = bytes & (BLOCKSIZE - 1);
write_recent_blocks ((union block *)data, blocks);
memcpy (new_record[new_blocks].buffer, data + blocks * BLOCKSIZE, rest);
@@ -144,7 +123,25 @@ write_recent_bytes (char *data, size_t bytes)
memset (new_record[new_blocks].buffer + rest, 0, BLOCKSIZE - rest);
new_blocks++;
if (new_blocks == blocking_factor)
write_record (1);
write_record (true);
}
static void
flush_file (void)
{
set_next_block_after (current_header);
off_t size = current_stat_info.stat.st_size;
off_t blocks_to_skip = (size >> LG_BLOCKSIZE) + !!(size & (BLOCKSIZE - 1));
while (record_end - current_block <= blocks_to_skip)
{
blocks_to_skip -= (record_end - current_block);
flush_archive ();
if (record_end == current_block)
/* Hit EOF */
return;
}
current_block += blocks_to_skip;
}
void
@@ -155,19 +152,19 @@ delete_archive_members (void)
/* FIXME: Should clean the routine before cleaning these variables :-( */
struct name *name;
off_t blocks_to_skip = 0;
off_t blocks_to_keep = 0;
int kept_blocks_in_record;
ptrdiff_t kept_blocks_in_record;
name_gather ();
open_archive (ACCESS_UPDATE);
acting_as_filter = strcmp (archive_name_array[0], "-") == 0;
/* Skip to the first member that matches the name list. */
do
{
enum read_header status = read_header (&current_header,
&current_stat_info,
read_header_x_raw);
&current_stat_info,
read_header_x_raw);
switch (status)
{
@@ -175,19 +172,18 @@ delete_archive_members (void)
abort ();
case HEADER_SUCCESS:
if ((name = name_scan (current_stat_info.file_name)) == NULL)
if ((name = name_scan (current_stat_info.file_name, false)) == NULL)
{
skip_member ();
skim_member (acting_as_filter);
break;
}
name->found_count++;
if (!ISFOUND(name))
if (!isfound (name))
{
skip_member ();
skim_member (acting_as_filter);
break;
}
/* Fall through. */
FALLTHROUGH;
case HEADER_SUCCESS_EXTENDED:
logical_status = status;
break;
@@ -198,7 +194,7 @@ delete_archive_members (void)
set_next_block_after (current_header);
break;
}
/* Fall through. */
FALLTHROUGH;
case HEADER_END_OF_FILE:
logical_status = HEADER_END_OF_FILE;
break;
@@ -208,15 +204,13 @@ delete_archive_members (void)
switch (previous_status)
{
case HEADER_STILL_UNREAD:
WARN ((0, 0, _("This does not look like a tar archive")));
/* Fall through. */
paxwarn (0, _("This does not look like a tar archive"));
FALLTHROUGH;
case HEADER_SUCCESS:
case HEADER_SUCCESS_EXTENDED:
case HEADER_ZERO_BLOCK:
ERROR ((0, 0, _("Skipping to next header")));
/* Fall through. */
paxerror (0, _("Skipping to next header"));
FALLTHROUGH;
case HEADER_FAILURE:
break;
@@ -246,15 +240,12 @@ delete_archive_members (void)
if (logical_status == HEADER_SUCCESS)
{
/* FIXME: Pheew! This is crufty code! */
logical_status = HEADER_STILL_UNREAD;
goto flush_file;
flush_file ();
}
/* FIXME: Solaris 2.4 Sun cc (the ANSI one, not the old K&R) says:
"delete.c", line 223: warning: loop not entered at top
Reported by Bruno Haible. */
while (1)
/* Skip matching members and move the rest up the archive. */
while (logical_status != HEADER_END_OF_FILE)
{
enum read_header status;
@@ -262,105 +253,109 @@ delete_archive_members (void)
if (current_block == record_end)
flush_archive ();
status = read_header (&current_header, &current_stat_info,
read_header_auto);
read_header_auto);
xheader_decode (&current_stat_info);
if (status == HEADER_ZERO_BLOCK && ignore_zeros_option)
switch (status)
{
case HEADER_STILL_UNREAD:
case HEADER_SUCCESS_EXTENDED:
abort ();
case HEADER_SUCCESS:
/* Found another header. */
xheader_decode (&current_stat_info);
if ((name = name_scan (current_stat_info.file_name, false)) != NULL)
{
name->found_count++;
if (isfound (name))
{
flush_file ();
break;
}
}
/* Copy header. */
if (current_stat_info.xhdr.size)
{
write_recent_bytes (current_stat_info.xhdr.buffer,
current_stat_info.xhdr.size);
}
else
{
write_recent_blocks (recent_long_name,
recent_long_name_blocks);
write_recent_blocks (recent_long_link,
recent_long_link_blocks);
}
new_record[new_blocks] = *current_header;
new_blocks++;
blocks_to_keep
= ((current_stat_info.stat.st_size >> LG_BLOCKSIZE)
+ !!(current_stat_info.stat.st_size & (BLOCKSIZE - 1)));
set_next_block_after (current_header);
continue;
}
if (status == HEADER_END_OF_FILE || status == HEADER_ZERO_BLOCK)
{
if (new_blocks == blocking_factor)
write_record (true);
/* Copy data. */
kept_blocks_in_record = record_end - current_block;
if (kept_blocks_in_record > blocks_to_keep)
kept_blocks_in_record = blocks_to_keep;
while (blocks_to_keep)
{
ptrdiff_t count;
if (current_block == record_end)
{
flush_read ();
current_block = record_start;
kept_blocks_in_record = blocking_factor;
if (kept_blocks_in_record > blocks_to_keep)
kept_blocks_in_record = blocks_to_keep;
}
count = kept_blocks_in_record;
if (blocking_factor - new_blocks < count)
count = blocking_factor - new_blocks;
if (! count)
abort ();
memcpy (new_record + new_blocks, current_block,
count * BLOCKSIZE);
new_blocks += count;
current_block += count;
blocks_to_keep -= count;
kept_blocks_in_record -= count;
if (new_blocks == blocking_factor)
write_record (true);
}
break;
case HEADER_ZERO_BLOCK:
if (ignore_zeros_option)
set_next_block_after (current_header);
else
logical_status = HEADER_END_OF_FILE;
break;
case HEADER_END_OF_FILE:
logical_status = HEADER_END_OF_FILE;
break;
}
if (status == HEADER_FAILURE)
{
ERROR ((0, 0, _("Deleting non-header from archive")));
case HEADER_FAILURE:
paxerror (0, _("Deleting non-header from archive"));
set_next_block_after (current_header);
continue;
}
/* Found another header. */
if ((name = name_scan (current_stat_info.file_name)) != NULL)
{
name->found_count++;
if (ISFOUND(name))
{
flush_file:
set_next_block_after (current_header);
blocks_to_skip = (current_stat_info.stat.st_size
+ BLOCKSIZE - 1) / BLOCKSIZE;
while (record_end - current_block <= blocks_to_skip)
{
blocks_to_skip -= (record_end - current_block);
flush_archive ();
}
current_block += blocks_to_skip;
blocks_to_skip = 0;
continue;
}
}
/* Copy header. */
if (current_stat_info.xhdr.size)
{
write_recent_bytes (current_stat_info.xhdr.buffer,
current_stat_info.xhdr.size);
}
else
{
write_recent_blocks (recent_long_name, recent_long_name_blocks);
write_recent_blocks (recent_long_link, recent_long_link_blocks);
}
new_record[new_blocks] = *current_header;
new_blocks++;
blocks_to_keep
= (current_stat_info.stat.st_size + BLOCKSIZE - 1) / BLOCKSIZE;
set_next_block_after (current_header);
if (new_blocks == blocking_factor)
write_record (1);
/* Copy data. */
kept_blocks_in_record = record_end - current_block;
if (kept_blocks_in_record > blocks_to_keep)
kept_blocks_in_record = blocks_to_keep;
while (blocks_to_keep)
{
int count;
if (current_block == record_end)
{
flush_read ();
current_block = record_start;
kept_blocks_in_record = blocking_factor;
if (kept_blocks_in_record > blocks_to_keep)
kept_blocks_in_record = blocks_to_keep;
}
count = kept_blocks_in_record;
if (blocking_factor - new_blocks < count)
count = blocking_factor - new_blocks;
if (! count)
abort ();
memcpy (new_record + new_blocks, current_block, count * BLOCKSIZE);
new_blocks += count;
current_block += count;
blocks_to_keep -= count;
kept_blocks_in_record -= count;
if (new_blocks == blocking_factor)
write_record (1);
break;
default:
abort ();
}
tar_stat_destroy (&current_stat_info);
}
if (logical_status == HEADER_END_OF_FILE)
@@ -368,11 +363,11 @@ delete_archive_members (void)
/* Write the end of tape. FIXME: we can't use write_eot here,
as it gets confused when the input is at end of file. */
int total_zero_blocks = 0;
idx_t total_zero_blocks = 0;
do
{
int zero_blocks = blocking_factor - new_blocks;
idx_t zero_blocks = blocking_factor - new_blocks;
memset (new_record + new_blocks, 0, BLOCKSIZE * zero_blocks);
total_zero_blocks += zero_blocks;
write_record (total_zero_blocks < 2);
@@ -382,7 +377,7 @@ delete_archive_members (void)
if (! acting_as_filter && ! _isrmt (archive))
{
if (sys_truncate (archive))
if (sys_truncate (archive) < 0)
truncate_warn (archive_name_array[0]);
}
}

327
src/exclist.c Normal file
View File

@@ -0,0 +1,327 @@
/* Per-directory exclusion files for tar.
Copyright 2014-2025 Free Software Foundation, Inc.
This file is part of GNU tar.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <system.h>
#include <c-ctype.h>
#include <quotearg.h>
#include <flexmember.h>
#include <fnmatch.h>
#include <wordsplit.h>
#include "common.h"
typedef void (*add_fn) (struct exclude *, char const *, int, void *);
struct vcs_ignore_file
{
char const *filename;
int flags;
add_fn addfn;
void *(*initfn) (void *);
void *data;
};
static struct vcs_ignore_file *get_vcs_ignore_file (const char *name);
struct excfile
{
struct excfile *next;
int flags;
char name[FLEXIBLE_ARRAY_MEMBER];
};
static struct excfile *excfile_head, *excfile_tail;
void
excfile_add (const char *name, int flags)
{
struct excfile *p = xmalloc (FLEXNSIZEOF (struct excfile, name,
strlen (name) + 1));
p->next = NULL;
p->flags = flags;
strcpy (p->name, name);
if (excfile_tail)
excfile_tail->next = p;
else
excfile_head = p;
excfile_tail = p;
}
struct exclist
{
struct exclist *next, *prev;
int flags;
struct exclude *excluded;
};
void
info_attach_exclist (struct tar_stat_info *dir)
{
struct exclist *head = NULL, *tail = NULL;
if (dir->exclude_list)
return;
for (struct excfile *file = excfile_head; file; file = file->next)
{
if (faccessat (dir->fd, file->name, F_OK, 0) == 0)
{
int fd = subfile_open (dir, file->name, O_RDONLY);
if (fd < 0)
{
open_error (file->name);
continue;
}
FILE *fp = fdopen (fd, "r");
if (!fp)
{
paxerror (errno, _("%s: fdopen failed"), file->name);
close (fd);
continue;
}
struct exclude *ex = new_exclude ();
struct vcs_ignore_file *vcsfile = get_vcs_ignore_file (file->name);
if (vcsfile->initfn)
vcsfile->data = vcsfile->initfn (vcsfile->data);
if (add_exclude_fp (vcsfile->addfn, ex, fp,
FNM_FILE_NAME|EXCLUDE_WILDCARDS|EXCLUDE_ANCHORED,
'\n',
vcsfile->data))
paxfatal (errno, "%s", quotearg_colon (file->name));
fclose (fp);
struct exclist *ent = xmalloc (sizeof *ent);
ent->excluded = ex;
ent->flags = file->flags;
ent->prev = tail;
ent->next = NULL;
if (tail)
tail->next = ent;
else
head = ent;
tail = ent;
}
}
dir->exclude_list = head;
}
void
info_free_exclist (struct tar_stat_info *dir)
{
struct exclist *ep = dir->exclude_list;
while (ep)
{
struct exclist *next = ep->next;
free_exclude (ep->excluded);
free (ep);
ep = next;
}
dir->exclude_list = NULL;
}
/* Return nonzero if file NAME is excluded. */
bool
excluded_name (char const *name, struct tar_stat_info *st)
{
struct exclist *ep;
const char *rname = NULL;
char *bname = NULL;
bool result;
int nr = 0;
name += FILE_SYSTEM_PREFIX_LEN (name);
/* Try global exclusion list first */
if (excluded_file_name (excluded, name))
return true;
if (!st)
return false;
for (result = false; st && !result; st = st->parent, nr = EXCL_NON_RECURSIVE)
{
for (ep = st->exclude_list; ep; ep = ep->next)
{
if (ep->flags & nr)
continue;
if ((result = excluded_file_name (ep->excluded, name)))
break;
if (!rname)
{
rname = name;
/* Skip leading ./ */
while (*rname == '.' && ISSLASH (rname[1]))
rname += 2;
}
if ((result = excluded_file_name (ep->excluded, rname)))
break;
if (!bname)
bname = base_name (name);
if ((result = excluded_file_name (ep->excluded, bname)))
break;
}
}
free (bname);
return result;
}
static void
cvs_addfn (struct exclude *ex, char const *pattern, int options,
MAYBE_UNUSED void *data)
{
struct wordsplit ws;
options |= EXCLUDE_ALLOC;
if (wordsplit (pattern, &ws,
WRDSF_NOVAR | WRDSF_NOCMD | WRDSF_SQUEEZE_DELIMS)
!= WRDSE_OK)
return;
for (idx_t i = 0; i < ws.ws_wordc; i++)
add_exclude (ex, ws.ws_wordv[i], options);
wordsplit_free (&ws);
}
static void
git_addfn (struct exclude *ex, char const *pattern, int options,
MAYBE_UNUSED void *data)
{
while (c_isspace (*pattern))
++pattern;
if (*pattern == 0 || *pattern == '#')
return;
if (*pattern == '\\' && pattern[1] == '#')
++pattern;
add_exclude (ex, pattern, options);
}
static void
bzr_addfn (struct exclude *ex, char const *pattern, int options,
MAYBE_UNUSED void *data)
{
while (c_isspace (*pattern))
++pattern;
if (*pattern == 0 || *pattern == '#')
return;
if (*pattern == '!')
{
if (*++pattern == '!')
++pattern;
else
options |= EXCLUDE_INCLUDE;
}
/* FIXME: According to the docs, globbing patterns are rsync-style,
and regexps are perl-style. */
if (strncmp (pattern, "RE:", 3) == 0)
{
pattern += 3;
options &= ~EXCLUDE_WILDCARDS;
options |= EXCLUDE_REGEX;
}
add_exclude (ex, pattern, options);
}
static void *
hg_initfn (void *data)
{
static int hg_options;
int *hgopt = data ? data : &hg_options;
*hgopt = EXCLUDE_REGEX;
return hgopt;
}
static void
hg_addfn (struct exclude *ex, char const *pattern, int options, void *data)
{
int *hgopt = data;
while (c_isspace (*pattern))
++pattern;
if (*pattern == 0 || *pattern == '#')
return;
if (strncmp (pattern, "syntax:", 7) == 0)
{
for (pattern += 7; c_isspace (*pattern); ++pattern)
;
if (strcmp (pattern, "regexp") == 0)
/* FIXME: Regexps must be perl-style */
*hgopt = EXCLUDE_REGEX;
else if (strcmp (pattern, "glob") == 0)
*hgopt = EXCLUDE_WILDCARDS;
/* Ignore unknown syntax */
return;
}
idx_t len = strlen (pattern);
if (pattern[len-1] == '/')
{
char *p;
--len;
p = xmalloc (len+1);
memcpy (p, pattern, len);
p[len] = 0;
pattern = p;
exclude_add_pattern_buffer (ex, p);
options |= FNM_LEADING_DIR|EXCLUDE_ALLOC;
}
add_exclude (ex, pattern,
((*hgopt == EXCLUDE_REGEX)
? (options & ~EXCLUDE_WILDCARDS)
: (options & ~EXCLUDE_REGEX)) | *hgopt);
}
static struct vcs_ignore_file vcs_ignore_files[] = {
{ ".cvsignore", EXCL_NON_RECURSIVE, cvs_addfn, NULL, NULL },
{ ".gitignore", 0, git_addfn, NULL, NULL },
{ ".bzrignore", 0, bzr_addfn, NULL, NULL },
{ ".hgignore", 0, hg_addfn, hg_initfn, NULL },
{ NULL, 0, git_addfn, NULL, NULL }
};
static struct vcs_ignore_file *
get_vcs_ignore_file (const char *name)
{
struct vcs_ignore_file *p;
for (p = vcs_ignore_files; p->filename; p++)
if (strcmp (p->filename, name) == 0)
break;
return p;
}
void
exclude_vcs_ignores (void)
{
struct vcs_ignore_file *p;
for (p = vcs_ignore_files; p->filename; p++)
excfile_add (p->filename, p->flags);
}

View File

@@ -1,19 +1,21 @@
/* This file is part of GNU tar.
Copyright (C) 2009 Free Software Foundation, Inc.
/* Exit from GNU tar.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
Copyright 2009-2025 Free Software Foundation, Inc.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
This file is part of GNU tar.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <system.h>
#include "common.h"

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

263
src/map.c Normal file
View File

@@ -0,0 +1,263 @@
/* Owner/group mapping for tar
Copyright 2015-2025 Free Software Foundation, Inc.
This file is part of GNU tar.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <system.h>
#include "common.h"
#include "wordsplit.h"
#include <hash.h>
#include <pwd.h>
struct mapentry
{
uintmax_t orig_id;
uintmax_t new_id;
char *new_name;
};
static size_t
map_hash (void const *entry, size_t nbuckets)
{
struct mapentry const *map = entry;
return map->orig_id % nbuckets;
}
static bool
map_compare (void const *entry1, void const *entry2)
{
struct mapentry const *map1 = entry1;
struct mapentry const *map2 = entry2;
return map1->orig_id == map2->orig_id;
}
static bool
parse_id (uintmax_t *retval,
char const *arg, char const *what, uintmax_t maxval,
char const *file, intmax_t line)
{
char *p;
bool overflow;
*retval = stoint (arg, &p, &overflow, 0, maxval);
if ((p == arg) | *p)
{
error (0, 0, _("%s:%jd: invalid %s: %s"), file, line, what, arg);
return false;
}
if (overflow)
{
error (0, 0, _("%s:%jd: %s out of range: %s"), file, line, what, arg);
return false;
}
return true;
}
static void
map_read (Hash_table **ptab, char const *file,
uintmax_t (*name_to_id) (char const *), char const *what,
uintmax_t maxval)
{
FILE *fp;
char *buf = NULL;
size_t bufsize = 0;
ssize_t n;
struct wordsplit ws;
int wsopt;
intmax_t line;
bool err = false;
fp = fopen (file, "r");
if (!fp)
open_fatal (file);
ws.ws_comment = "#";
wsopt = WRDSF_COMMENT | WRDSF_NOVAR | WRDSF_NOCMD | WRDSF_SQUEEZE_DELIMS
| WRDSF_QUOTE;
line = 0;
while ((n = getline (&buf, &bufsize, fp)) > 0)
{
struct mapentry *ent;
uintmax_t orig_id, new_id;
char *name = NULL;
char *colon;
++line;
if (wordsplit (buf, &ws, wsopt) != WRDSE_OK)
paxfatal (0, _("%s:%jd: cannot split line: %s"),
file, line, wordsplit_strerror (&ws));
wsopt |= WRDSF_REUSE;
if (ws.ws_wordc == 0)
continue;
if (ws.ws_wordc != 2)
{
error (0, 0, _("%s:%jd: malformed line"), file, line);
err = true;
continue;
}
if (ws.ws_wordv[0][0] == '+')
{
if (!parse_id (&orig_id, ws.ws_wordv[0]+1, what, maxval, file, line))
{
err = true;
continue;
}
}
else if (name_to_id)
{
orig_id = name_to_id (ws.ws_wordv[0]);
if (orig_id == UINTMAX_MAX)
{
error (0, 0, _("%s:%jd: can't obtain %s of %s"),
file, line, what, ws.ws_wordv[0]);
err = true;
continue;
}
}
colon = strchr (ws.ws_wordv[1], ':');
if (colon)
{
if (colon > ws.ws_wordv[1])
name = ws.ws_wordv[1];
*colon++ = 0;
if (!parse_id (&new_id, colon, what, maxval, file, line))
{
err = true;
continue;
}
}
else if (ws.ws_wordv[1][0] == '+')
{
if (!parse_id (&new_id, ws.ws_wordv[1], what, maxval, file, line))
{
err = true;
continue;
}
}
else
{
name = ws.ws_wordv[1];
new_id = name_to_id (ws.ws_wordv[1]);
if (new_id == UINTMAX_MAX)
{
error (0, 0, _("%s:%jd: can't obtain %s of %s"),
file, line, what, ws.ws_wordv[1]);
err = true;
continue;
}
}
ent = xmalloc (sizeof (*ent));
ent->orig_id = orig_id;
ent->new_id = new_id;
ent->new_name = name ? xstrdup (name) : NULL;
if (!((*ptab
|| (*ptab = hash_initialize (0, 0, map_hash, map_compare, 0)))
&& hash_insert (*ptab, ent)))
xalloc_die ();
}
if (wsopt & WRDSF_REUSE)
wordsplit_free (&ws);
fclose (fp);
if (err)
paxfatal (0, _("errors reading map file"));
}
/* UID translation */
static Hash_table *owner_map;
static uintmax_t
name_to_uid (char const *name)
{
struct passwd *pw = getpwnam (name);
return pw ? pw->pw_uid : UINTMAX_MAX;
}
void
owner_map_read (char const *file)
{
map_read (&owner_map, file, name_to_uid, "UID", TYPE_MAXIMUM (uid_t));
}
void
owner_map_translate (uid_t uid, uid_t *new_uid, char const **new_name)
{
if (owner_map)
{
struct mapentry ent, *res;
ent.orig_id = uid;
res = hash_lookup (owner_map, &ent);
if (res)
{
*new_uid = res->new_id;
*new_name = res->new_name;
return;
}
}
uid_t minus_1 = -1;
if (owner_option != minus_1)
*new_uid = owner_option;
if (owner_name_option)
*new_name = owner_name_option;
}
/* GID translation */
static Hash_table *group_map;
static uintmax_t
name_to_gid (char const *name)
{
struct group *gr = getgrnam (name);
return gr ? gr->gr_gid : UINTMAX_MAX;
}
void
group_map_read (char const *file)
{
map_read (&group_map, file, name_to_gid, "GID", TYPE_MAXIMUM (gid_t));
}
void
group_map_translate (gid_t gid, gid_t *new_gid, char const **new_name)
{
if (group_map)
{
struct mapentry ent, *res;
ent.orig_id = gid;
res = hash_lookup (group_map, &ent);
if (res)
{
*new_gid = res->new_id;
*new_name = res->new_name;
return;
}
}
gid_t minus_1 = -1;
if (group_option != minus_1)
*new_gid = group_option;
if (group_name_option)
*new_name = group_name_option;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
/* This file is part of GNU tar.
Copyright (C) 2007, 2009 Free Software Foundation, Inc.
Copyright 2007-2025 Free Software Foundation, Inc.
Written by Sergey Poznyakoff.
@@ -21,15 +21,19 @@
struct compression_suffix
{
const char *suffix;
size_t length;
const char *program;
char suffix[sizeof "tbz2"]; /* "tbz2" is tied for longest. */
char program[max (max (max (sizeof GZIP_PROGRAM, sizeof COMPRESS_PROGRAM),
max (sizeof BZIP2_PROGRAM, sizeof LZIP_PROGRAM)),
max (max (sizeof LZMA_PROGRAM, sizeof LZOP_PROGRAM),
max (sizeof XZ_PROGRAM, sizeof ZSTD_PROGRAM)))];
};
static struct compression_suffix compression_suffixes[] = {
static struct compression_suffix const compression_suffixes[] = {
#define __CAT2__(a,b) a ## b
#define S(s,p) #s, sizeof (#s) - 1, __CAT2__(p,_PROGRAM)
#define S(s, p) #s, __CAT2__(p,_PROGRAM)
{ "tar", "" },
{ S(gz, GZIP) },
{ S(z, GZIP) },
{ S(tgz, GZIP) },
{ S(taz, GZIP) },
{ S(Z, COMPRESS) },
@@ -42,41 +46,86 @@ static struct compression_suffix compression_suffixes[] = {
{ S(lzma, LZMA) },
{ S(tlz, LZMA) },
{ S(lzo, LZOP) },
{ S(tzo, LZOP) },
{ S(xz, XZ) },
{ S(txz, XZ) }, /* Slackware */
{ S(zst, ZSTD) },
{ S(tzst, ZSTD) },
#undef S
#undef __CAT2__
};
static int nsuffixes = sizeof (compression_suffixes) /
sizeof (compression_suffixes[0]);
static const char *
find_compression_program (const char *name, const char *defprog)
/* Extract the suffix from archive file NAME, and return a pointer to
compression_suffix associated with it or NULL if none is found.
No matter what is the return value, if RET_LEN is not NULL, store
there the length of NAME with that suffix stripped, or 0 if NAME has
no suffix. */
static struct compression_suffix const *
find_compression_suffix (char const *name, idx_t *ret_len)
{
char *suf = strrchr (name, '.');
char const *suf = strrchr (name, '.');
if (suf)
if (suf && suf[1] != 0 && suf[1] != '/')
{
int i;
size_t len;
if (ret_len)
*ret_len = suf - name;
suf++;
len = strlen (suf);
for (i = 0; i < nsuffixes; i++)
{
if (compression_suffixes[i].length == len
&& memcmp (compression_suffixes[i].suffix, suf, len) == 0)
return compression_suffixes[i].program;
}
for (struct compression_suffix const *p = compression_suffixes;
p < (compression_suffixes
+ sizeof compression_suffixes / sizeof *compression_suffixes);
p++)
if (strcmp (p->suffix, suf) == 0)
return p;
}
return defprog;
else if (ret_len)
*ret_len = 0;
return NULL;
}
/* Select compression program using the suffix of the archive file NAME.
Use DEFPROG, if there is no suffix, or if no program is associated with
the suffix. In the latter case, if VERBOSE is true, issue a warning.
*/
void
set_compression_program_by_suffix (const char *name, const char *defprog)
set_compression_program_by_suffix (const char *name, const char *defprog,
bool verbose)
{
const char *program = find_compression_program (name, defprog);
if (program)
use_compress_program_option = program;
idx_t len;
struct compression_suffix const *p = find_compression_suffix (name, &len);
if (p)
use_compress_program_option = p->program[0] ? p->program : NULL;
else
{
use_compress_program_option = defprog;
if (len > 0 && verbose)
paxwarn (0,
_("no compression program is defined for suffix '%s';"
" assuming %s"),
name + len,
defprog ? defprog : "uncompressed archive");
}
}
char *
strip_compression_suffix (const char *name)
{
char *s = NULL;
idx_t len;
struct compression_suffix const *p = find_compression_suffix (name, &len);
if (p)
{
/* Strip an additional ".tar" suffix, but only if the just-stripped
"outer" suffix did not begin with "t". */
if (len > 4 && strncmp (name + len - 4, ".tar", 4) == 0
&& p->suffix[0] != 't')
len -= 4;
if (len == 0)
return NULL;
s = xmalloc (len + 1);
memcpy (s, name, len);
s[len] = 0;
}
return s;
}

View File

@@ -1,7 +1,6 @@
/* System-dependent calls for tar.
Copyright (C) 2003, 2004, 2005, 2006, 2007,
2008, 2010 Free Software Foundation, Inc.
Copyright 2003-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
@@ -14,17 +13,70 @@
Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <system.h>
#if HAVE_SYS_MTIO_H
# include <sys/ioctl.h>
# include <sys/mtio.h>
#endif
#include "common.h"
#include <priv-set.h>
#include <rmt.h>
#include <same-inode.h>
#include <signal.h>
#include <wordsplit.h>
#include <poll.h>
#include <parse-datetime.h>
#if MSDOS
bool dev_null_output;
static _Noreturn void
xexec (const char *cmd)
{
char *argv[4];
argv[0] = (char *) "/bin/sh";
argv[1] = (char *) "-c";
argv[2] = (char *) cmd;
argv[3] = NULL;
execv ("/bin/sh", argv);
exec_fatal (cmd);
}
/* True if the archive is seekable via ioctl and MTIOCTOP,
or if it is not known whether it is seekable.
False if it is known to be not seekable. */
static bool mtioseekable_archive;
bool
mtioseek (bool count_files, off_t count)
{
if (mtioseekable_archive)
{
#ifdef MTIOCTOP
struct mtop operation;
operation.mt_op = (count_files
? (count < 0 ? MTBSF : MTFSF)
: (count < 0 ? MTBSR : MTFSR));
if (! (count < 0
? ckd_sub (&operation.mt_count, 0, count)
: ckd_add (&operation.mt_count, count, 0))
&& (0 <= rmtioctl (archive, MTIOCTOP, &operation)
|| (errno == EIO
&& 0 <= rmtioctl (archive, MTIOCTOP, &operation))))
return true;
#endif
mtioseekable_archive = false;
}
return false;
}
#if !HAVE_WAITPID /* MingW, MSVC 14. */
bool
sys_get_archive_stat (void)
@@ -38,11 +90,6 @@ sys_file_is_archive (struct tar_stat_info *p)
return false;
}
void
sys_save_archive_dev_ino (void)
{
}
void
sys_detect_dev_null_output (void)
{
@@ -79,82 +126,86 @@ sys_compare_gid (struct stat *a, struct stat *b)
return true;
}
void
sys_compare_links (struct stat *link_data, struct stat *stat_data)
{
return true;
}
int
sys_truncate (int fd)
{
return write (fd, "", 0);
}
size_t
idx_t
sys_write_archive_buffer (void)
{
return full_write (archive, record_start->buffer, record_size);
return full_write (archive, charptr (record_start), record_size);
}
/* Set ARCHIVE for writing, then compressing an archive. */
void
sys_child_open_for_compress (void)
{
FATAL_ERROR ((0, 0, _("Cannot use compressed or remote archives")));
paxfatal (0, _("Cannot use compressed or remote archives"));
}
/* Set ARCHIVE for uncompressing, then reading an archive. */
void
sys_child_open_for_uncompress (void)
{
FATAL_ERROR ((0, 0, _("Cannot use compressed or remote archives")));
paxfatal (0, _("Cannot use compressed or remote archives"));
}
bool
sys_exec_setmtime_script (const char *script_name,
int dirfd,
const char *file_name,
const char *fmt,
struct timespec *ts)
{
paxfatal (0, _("--set-mtime-command not implemented on this platform"));
}
#else
extern union block *record_start; /* FIXME */
static struct stat archive_stat; /* stat block for archive file */
bool
sys_get_archive_stat (void)
{
return fstat (archive, &archive_stat) == 0;
bool remote = _isrmt (archive);
mtioseekable_archive = true;
if (!remote && 0 <= archive && fstat (archive, &archive_stat) == 0)
{
if (!S_ISCHR (archive_stat.st_mode))
mtioseekable_archive = false;
return true;
}
else
{
/* FIXME: This memset should not be needed. It is present only
because other parts of tar may incorrectly access
archive_stat even if it's not the archive status. */
memset (&archive_stat, 0, sizeof archive_stat);
return remote;
}
}
bool
sys_file_is_archive (struct tar_stat_info *p)
{
return (ar_dev && p->stat.st_dev == ar_dev && p->stat.st_ino == ar_ino);
return (!dev_null_output && !_isrmt (archive)
&& psame_inode (&p->stat, &archive_stat));
}
/* Save archive file inode and device numbers */
void
sys_save_archive_dev_ino (void)
{
if (!_isrmt (archive) && S_ISREG (archive_stat.st_mode))
{
ar_dev = archive_stat.st_dev;
ar_ino = archive_stat.st_ino;
}
else
ar_dev = 0;
}
static char const dev_null[] = "/dev/null";
/* Detect if outputting to "/dev/null". */
void
sys_detect_dev_null_output (void)
{
static char const dev_null[] = "/dev/null";
struct stat dev_null_stat;
static struct stat dev_null_stat;
dev_null_output = (strcmp (archive_name_array[0], dev_null) == 0
|| (! _isrmt (archive)
&& S_ISCHR (archive_stat.st_mode)
&& stat (dev_null, &dev_null_stat) == 0
&& archive_stat.st_dev == dev_null_stat.st_dev
&& archive_stat.st_ino == dev_null_stat.st_ino));
&& (dev_null_stat.st_ino != 0
|| stat (dev_null, &dev_null_stat) == 0)
&& psame_inode (&archive_stat, &dev_null_stat)));
}
void
@@ -164,7 +215,7 @@ sys_wait_for_child (pid_t child_pid, bool eof)
{
int wait_status;
while (waitpid (child_pid, &wait_status, 0) == -1)
while (waitpid (child_pid, &wait_status, 0) < 0)
if (errno != EINTR)
{
waitpid_error (use_compress_program_option);
@@ -175,11 +226,11 @@ sys_wait_for_child (pid_t child_pid, bool eof)
{
int sig = WTERMSIG (wait_status);
if (!(!eof && sig == SIGPIPE))
FATAL_ERROR ((0, 0, _("Child died with signal %d"), sig));
paxfatal (0, _("Child died with signal %d"), sig);
}
else if (WEXITSTATUS (wait_status) != 0)
FATAL_ERROR ((0, 0, _("Child returned status %d"),
WEXITSTATUS (wait_status)));
paxfatal (0, _("Child returned status %d"),
WEXITSTATUS (wait_status));
}
}
@@ -194,13 +245,13 @@ sys_spawn_shell (void)
if (child == 0)
{
priv_set_restore_linkdir ();
execlp (shell, "-sh", "-i", (char *) 0);
execlp (shell, "-sh", "-i", NULL);
exec_fatal (shell);
}
else
{
int wait_status;
while (waitpid (child, &wait_status, 0) == -1)
while (waitpid (child, &wait_status, 0) < 0)
if (errno != EINTR)
{
waitpid_error (shell);
@@ -221,41 +272,39 @@ sys_compare_gid (struct stat *a, struct stat *b)
return a->st_gid == b->st_gid;
}
bool
sys_compare_links (struct stat *link_data, struct stat *stat_data)
{
return stat_data->st_dev == link_data->st_dev
&& stat_data->st_ino == link_data->st_ino;
}
int
sys_truncate (int fd)
{
off_t pos = lseek (fd, (off_t) 0, SEEK_CUR);
off_t pos = lseek (fd, 0, SEEK_CUR);
return pos < 0 ? -1 : ftruncate (fd, pos);
}
/* Return nonzero if NAME is the name of a regular file, or if the file
/* Return true if NAME is the name of a regular file, or if the file
does not exist (so it would be created as a regular file). */
static int
static bool
is_regular_file (const char *name)
{
struct stat stbuf;
if (stat (name, &stbuf) == 0)
return S_ISREG (stbuf.st_mode);
return !!S_ISREG (stbuf.st_mode);
else
return errno == ENOENT;
}
size_t
idx_t
sys_write_archive_buffer (void)
{
return rmtwrite (archive, record_start->buffer, record_size);
return rmtwrite (archive, charptr (record_start), record_size);
}
#define PREAD 0 /* read file descriptor from pipe() */
#define PWRITE 1 /* write file descriptor from pipe() */
/* Read and write file descriptors from a pipe(pipefd) call. */
enum { PREAD, PWRITE };
/* Work around GCC bug 109839. */
#if 13 <= __GNUC__
# pragma GCC diagnostic ignored "-Wanalyzer-fd-leak"
#endif
/* Duplicate file descriptor FROM into becoming INTO.
INTO is closed first and has to be the next available slot. */
@@ -264,37 +313,20 @@ xdup2 (int from, int into)
{
if (from != into)
{
int status = close (into);
if (status != 0 && errno != EBADF)
{
int e = errno;
FATAL_ERROR ((0, e, _("Cannot close")));
}
status = dup (from);
if (status != into)
{
if (status < 0)
{
int e = errno;
FATAL_ERROR ((0, e, _("Cannot dup")));
}
abort ();
}
if (dup2 (from, into) < 0)
paxfatal (errno, _("Cannot dup2"));
xclose (from);
}
}
static void wait_for_grandchild (pid_t pid) __attribute__ ((__noreturn__));
/* Propagate any failure of the grandchild back to the parent. */
static void
static _Noreturn void
wait_for_grandchild (pid_t pid)
{
int wait_status;
int exit_code = 0;
while (waitpid (pid, &wait_status, 0) == -1)
while (waitpid (pid, &wait_status, 0) < 0)
if (errno != EINTR)
{
waitpid_error (use_compress_program_option);
@@ -318,6 +350,7 @@ sys_child_open_for_compress (void)
pid_t grandchild_pid;
pid_t child_pid;
signal (SIGPIPE, SIG_IGN);
xpipe (parent_pipe);
child_pid = xfork ();
@@ -365,8 +398,7 @@ sys_child_open_for_compress (void)
xdup2 (archive, STDOUT_FILENO);
}
priv_set_restore_linkdir ();
execlp (use_compress_program_option, use_compress_program_option, NULL);
exec_fatal (use_compress_program_option);
xexec (use_compress_program_option);
}
/* We do need a grandchild tar. */
@@ -383,9 +415,7 @@ sys_child_open_for_compress (void)
xdup2 (child_pipe[PWRITE], STDOUT_FILENO);
xclose (child_pipe[PREAD]);
priv_set_restore_linkdir ();
execlp (use_compress_program_option, use_compress_program_option,
(char *) 0);
exec_fatal (use_compress_program_option);
xexec (use_compress_program_option);
}
/* The child tar is still here! */
@@ -408,20 +438,20 @@ sys_child_open_for_compress (void)
while (1)
{
size_t status = 0;
ptrdiff_t status = 0;
char *cursor;
size_t length;
idx_t length;
/* Assemble a record. */
for (length = 0, cursor = record_start->buffer;
for (length = 0, cursor = charptr (record_start);
length < record_size;
length += status, cursor += status)
{
size_t size = record_size - length;
idx_t size = record_size - length;
status = safe_read (STDIN_FILENO, cursor, size);
if (status == SAFE_READ_ERROR)
if (status < 0)
read_fatal (use_compress_program_option);
if (status == 0)
break;
@@ -437,7 +467,7 @@ sys_child_open_for_compress (void)
if (length > 0)
{
memset (record_start->buffer + length, 0, record_size - length);
memset (charptr (record_start) + length, 0, record_size - length);
status = sys_write_archive_buffer ();
if (status != record_size)
archive_write_error (status);
@@ -455,6 +485,40 @@ sys_child_open_for_compress (void)
wait_for_grandchild (grandchild_pid);
}
static void
run_decompress_program (void)
{
int i;
const char *p, *prog = NULL;
struct wordsplit ws;
int wsflags = (WRDSF_DEFFLAGS | WRDSF_ENV | WRDSF_DOOFFS) & ~WRDSF_NOVAR;
ws.ws_env = (const char **) environ;
ws.ws_offs = 1;
for (p = first_decompress_program (&i); p; p = next_decompress_program (&i))
{
if (prog)
{
warnopt (WARN_DECOMPRESS_PROGRAM, errno, _("cannot run %s"), prog);
warnopt (WARN_DECOMPRESS_PROGRAM, 0, _("trying %s"), p);
}
if (wordsplit (p, &ws, wsflags) != WRDSE_OK)
paxfatal (0, _("cannot split string '%s': %s"),
p, wordsplit_strerror (&ws));
wsflags |= WRDSF_REUSE;
memmove (ws.ws_wordv, ws.ws_wordv + ws.ws_offs,
ws.ws_wordc * sizeof *ws.ws_wordv);
ws.ws_wordv[ws.ws_wordc] = (char *) "-d";
prog = p;
execvp (ws.ws_wordv[0], ws.ws_wordv);
ws.ws_wordv[ws.ws_wordc] = NULL;
}
if (!prog)
paxfatal (0, _("unable to run decompression program"));
exec_fatal (prog);
}
/* Set ARCHIVE for uncompressing, then reading an archive. */
pid_t
sys_child_open_for_uncompress (void)
@@ -493,7 +557,7 @@ sys_child_open_for_uncompress (void)
&& !_remdev (archive_name_array[0])
&& is_regular_file (archive_name_array[0]))
{
/* We don't need a grandchild tar. Open the archive and lauch the
/* We don't need a grandchild tar. Open the archive and launch the
uncompressor. */
archive = open (archive_name_array[0], O_RDONLY | O_BINARY, MODE_RW);
@@ -501,9 +565,7 @@ sys_child_open_for_uncompress (void)
open_fatal (archive_name_array[0]);
xdup2 (archive, STDIN_FILENO);
priv_set_restore_linkdir ();
execlp (use_compress_program_option, use_compress_program_option,
"-d", (char *) 0);
exec_fatal (use_compress_program_option);
run_decompress_program ();
}
/* We do need a grandchild tar. */
@@ -520,9 +582,7 @@ sys_child_open_for_uncompress (void)
xdup2 (child_pipe[PREAD], STDIN_FILENO);
xclose (child_pipe[PWRITE]);
priv_set_restore_linkdir ();
execlp (use_compress_program_option, use_compress_program_option,
"-d", (char *) 0);
exec_fatal (use_compress_program_option);
run_decompress_program ();
}
/* The child tar is still here! */
@@ -543,34 +603,26 @@ sys_child_open_for_uncompress (void)
/* Let's read the archive and pipe it into stdout. */
while (1)
while (true)
{
char *cursor;
size_t maximum;
size_t count;
size_t status;
clear_read_error_count ();
error_loop:
status = rmtread (archive, record_start->buffer, record_size);
if (status == SAFE_READ_ERROR)
{
archive_read_error ();
goto error_loop;
}
if (status == 0)
ptrdiff_t n;
while ((n = rmtread (archive, charptr (record_start), record_size)) < 0)
archive_read_error ();
if (n == 0)
break;
cursor = record_start->buffer;
maximum = status;
while (maximum)
char *cursor = charptr (record_start);
do
{
count = maximum < BLOCKSIZE ? maximum : BLOCKSIZE;
idx_t count = min (n, BLOCKSIZE);
if (full_write (STDOUT_FILENO, cursor, count) != count)
write_error (use_compress_program_option);
cursor += count;
maximum -= count;
n -= count;
}
while (n);
}
xclose (STDOUT_FILENO);
@@ -583,11 +635,8 @@ sys_child_open_for_uncompress (void)
static void
dec_to_env (char const *envar, uintmax_t num)
{
char buf[UINTMAX_STRSIZE_BOUND];
char *numstr;
numstr = STRINGIFY_BIGINT (num, buf);
if (setenv (envar, numstr, 1) != 0)
char numstr[UINTMAX_STRSIZE_BOUND];
if (setenv (envar, umaxtostr (num, numstr), 1) < 0)
xalloc_die ();
}
@@ -595,17 +644,19 @@ static void
time_to_env (char const *envar, struct timespec t)
{
char buf[TIMESPEC_STRSIZE_BOUND];
if (setenv (envar, code_timespec (t, buf), 1) != 0)
if (setenv (envar, code_timespec (t, buf), 1) < 0)
xalloc_die ();
}
static void
oct_to_env (char const *envar, unsigned long num)
oct_to_env (char const *envar, mode_t m)
{
char buf[1+1+(sizeof(unsigned long)*CHAR_BIT+2)/3];
snprintf (buf, sizeof buf, "0%lo", num);
if (setenv (envar, buf, 1) != 0)
char buf[sizeof "0" + (UINTMAX_WIDTH + 2) / 3];
uintmax_t um = m;
if (EXPR_SIGNED (m) && sizeof m < sizeof um)
um &= ~ (UINTMAX_MAX << TYPE_WIDTH (m));
sprintf (buf, "%#"PRIoMAX, um);
if (setenv (envar, buf, 1) < 0)
xalloc_die ();
}
@@ -614,7 +665,7 @@ str_to_env (char const *envar, char const *str)
{
if (str)
{
if (setenv (envar, str, 1) != 0)
if (setenv (envar, str, 1) < 0)
xalloc_die ();
}
else
@@ -627,7 +678,7 @@ chr_to_env (char const *envar, char c)
char buf[2];
buf[0] = c;
buf[1] = 0;
if (setenv (envar, buf, 1) != 0)
if (setenv (envar, buf, 1) < 0)
xalloc_die ();
}
@@ -679,13 +730,12 @@ stat_to_env (char *name, char type, struct tar_stat_info *st)
}
static pid_t global_pid;
static RETSIGTYPE (*pipe_handler) (int sig);
static void (*pipe_handler) (int sig);
int
sys_exec_command (char *file_name, int typechar, struct tar_stat_info *st)
sys_exec_command (char *file_name, char typechar, struct tar_stat_info *st)
{
int p[2];
char *argv[4];
xpipe (p);
pipe_handler = signal (SIGPIPE, SIG_IGN);
@@ -703,15 +753,8 @@ sys_exec_command (char *file_name, int typechar, struct tar_stat_info *st)
stat_to_env (file_name, typechar, st);
argv[0] = "/bin/sh";
argv[1] = "-c";
argv[2] = to_command_option;
argv[3] = NULL;
priv_set_restore_linkdir ();
execv ("/bin/sh", argv);
exec_fatal (file_name);
xexec (to_command_option);
}
void
@@ -723,7 +766,7 @@ sys_wait_command (void)
return;
signal (SIGPIPE, pipe_handler);
while (waitpid (global_pid, &status, 0) == -1)
while (waitpid (global_pid, &status, 0) < 0)
if (errno != EINTR)
{
global_pid = -1;
@@ -734,54 +777,65 @@ sys_wait_command (void)
if (WIFEXITED (status))
{
if (!ignore_command_error_option && WEXITSTATUS (status))
ERROR ((0, 0, _("%lu: Child returned status %d"),
(unsigned long) global_pid, WEXITSTATUS (status)));
paxerror (0, _("%jd: Child returned status %d"),
intmax (global_pid), WEXITSTATUS (status));
}
else if (WIFSIGNALED (status))
{
WARN ((0, 0, _("%lu: Child terminated on signal %d"),
(unsigned long) global_pid, WTERMSIG (status)));
paxwarn (0, _("%jd: Child terminated on signal %d"),
intmax (global_pid), WTERMSIG (status));
}
else
ERROR ((0, 0, _("%lu: Child terminated on unknown reason"),
(unsigned long) global_pid));
paxerror (0, _("%jd: Child terminated on unknown reason"),
intmax (global_pid));
global_pid = -1;
}
int
sys_exec_info_script (const char **archive_name, int volume_number)
sys_exec_info_script (const char **archive_name, intmax_t volume_number)
{
pid_t pid;
char *argv[4];
char uintbuf[UINTMAX_STRSIZE_BOUND];
int p[2];
static RETSIGTYPE (*saved_handler) (int sig);
static void (*saved_handler) (int sig);
xpipe (p);
saved_handler = signal (SIGPIPE, SIG_IGN);
pid = xfork ();
pid_t pid = xfork ();
if (pid != 0)
{
/* Master */
int rc;
int status;
char *buf = NULL;
size_t size = 0;
FILE *fp;
xclose (p[PWRITE]);
fp = fdopen (p[PREAD], "r");
rc = getline (&buf, &size, fp);
fclose (fp);
FILE *fp = fdopen (p[PREAD], "r");
if (!fp)
{
signal (SIGPIPE, saved_handler);
call_arg_error ("fdopen", info_script_option);
return -1;
}
ssize_t rc = getline (&buf, &size, fp);
if (rc < 0)
{
signal (SIGPIPE, saved_handler);
read_error (info_script_option);
return -1;
}
*archive_name = buf;
buf[rc - 1] = '\0';
if (fclose (fp) < 0)
{
signal (SIGPIPE, saved_handler);
close_error (info_script_option);
return -1;
}
if (rc > 0 && buf[rc-1] == '\n')
buf[--rc] = 0;
while (waitpid (pid, &status, 0) == -1)
while (waitpid (pid, &status, 0) < 0)
if (errno != EINTR)
{
signal (SIGPIPE, saved_handler);
@@ -790,55 +844,32 @@ sys_exec_info_script (const char **archive_name, int volume_number)
}
signal (SIGPIPE, saved_handler);
if (WIFEXITED (status))
{
if (WEXITSTATUS (status) == 0 && rc > 0)
*archive_name = buf;
else
free (buf);
return WEXITSTATUS (status);
}
free (buf);
return -1;
return WIFEXITED (status) ? WEXITSTATUS (status) : -1;
}
/* Child */
setenv ("TAR_VERSION", PACKAGE_VERSION, 1);
setenv ("TAR_ARCHIVE", *archive_name, 1);
setenv ("TAR_VOLUME", STRINGIFY_BIGINT (volume_number, uintbuf), 1);
setenv ("TAR_BLOCKING_FACTOR",
STRINGIFY_BIGINT (blocking_factor, uintbuf), 1);
str_to_env ("TAR_VERSION", PACKAGE_VERSION);
str_to_env ("TAR_ARCHIVE", *archive_name);
dec_to_env ("TAR_VOLUME", volume_number);
dec_to_env ("TAR_BLOCKING_FACTOR", blocking_factor);
setenv ("TAR_SUBCOMMAND", subcommand_string (subcommand_option), 1);
setenv ("TAR_FORMAT",
archive_format_string (current_format == DEFAULT_FORMAT ?
archive_format : current_format), 1);
setenv ("TAR_FD", STRINGIFY_BIGINT (p[PWRITE], uintbuf), 1);
dec_to_env ("TAR_FD", p[PWRITE]);
xclose (p[PREAD]);
argv[0] = "/bin/sh";
argv[1] = "-c";
argv[2] = (char *) info_script_option;
argv[3] = NULL;
priv_set_restore_linkdir ();
execv (argv[0], argv);
exec_fatal (info_script_option);
xexec (info_script_option);
}
void
sys_exec_checkpoint_script (const char *script_name,
const char *archive_name,
int checkpoint_number)
intmax_t checkpoint_number)
{
pid_t pid;
char *argv[4];
char uintbuf[UINTMAX_STRSIZE_BOUND];
pid = xfork ();
pid_t pid = xfork ();
if (pid != 0)
{
@@ -846,7 +877,7 @@ sys_exec_checkpoint_script (const char *script_name,
int status;
while (waitpid (pid, &status, 0) == -1)
while (waitpid (pid, &status, 0) < 0)
if (errno != EINTR)
{
waitpid_error (script_name);
@@ -857,24 +888,175 @@ sys_exec_checkpoint_script (const char *script_name,
}
/* Child */
setenv ("TAR_VERSION", PACKAGE_VERSION, 1);
setenv ("TAR_ARCHIVE", archive_name, 1);
setenv ("TAR_CHECKPOINT", STRINGIFY_BIGINT (checkpoint_number, uintbuf), 1);
setenv ("TAR_BLOCKING_FACTOR",
STRINGIFY_BIGINT (blocking_factor, uintbuf), 1);
setenv ("TAR_SUBCOMMAND", subcommand_string (subcommand_option), 1);
setenv ("TAR_FORMAT",
archive_format_string (current_format == DEFAULT_FORMAT ?
archive_format : current_format), 1);
argv[0] = "/bin/sh";
argv[1] = "-c";
argv[2] = (char *) script_name;
argv[3] = NULL;
str_to_env ("TAR_VERSION", PACKAGE_VERSION);
str_to_env ("TAR_ARCHIVE", archive_name);
dec_to_env ("TAR_CHECKPOINT", checkpoint_number);
dec_to_env ("TAR_BLOCKING_FACTOR", blocking_factor);
str_to_env ("TAR_SUBCOMMAND", subcommand_string (subcommand_option));
str_to_env ("TAR_FORMAT",
archive_format_string (current_format == DEFAULT_FORMAT
? archive_format : current_format));
priv_set_restore_linkdir ();
execv (argv[0], argv);
xexec (script_name);
}
exec_fatal (script_name);
bool
sys_exec_setmtime_script (const char *script_name,
int dirfd,
const char *file_name,
const char *fmt,
struct timespec *ts)
{
pid_t pid;
int p[2];
bool stop = false;
struct pollfd pfd;
char *buffer = NULL;
idx_t buflen = 0;
idx_t bufsize = 0;
char *cp;
bool rc = true;
if (pipe (p) < 0)
paxfatal (errno, _("pipe failed"));
if ((pid = xfork ()) == 0)
{
char *command = xmalloc (strlen (script_name) + strlen (file_name) + 2);
strcpy (command, script_name);
strcat (command, " ");
strcat (command, file_name);
if (dirfd != AT_FDCWD && fchdir (dirfd) < 0)
paxfatal (errno, _("chdir failed"));
close (p[0]);
if (dup2 (p[1], STDOUT_FILENO) < 0)
paxfatal (errno, _("dup2 failed"));
if (p[1] != STDOUT_FILENO)
close (p[1]);
close (STDIN_FILENO);
if (open (dev_null, O_RDONLY) != STDIN_FILENO)
open_error (dev_null);
priv_set_restore_linkdir ();
/* FIXME: This mishandles shell metacharacters in the file name.
Come to think of it, isn't every use of xexec suspect? */
xexec (command);
}
close (p[1]);
pfd.fd = p[0];
pfd.events = POLLIN;
while (1)
{
int n = poll (&pfd, 1, -1);
if (n < 0)
{
if (errno != EINTR)
{
paxerror (errno, _("poll failed"));
stop = true;
break;
}
}
if (n == 0)
break;
if (pfd.revents & POLLIN)
{
if (buflen == bufsize)
buffer = xpalloc (buffer, &bufsize, 1, -1, 1);
ssize_t nread = read (pfd.fd, buffer + buflen, bufsize - buflen);
if (nread < 0)
{
paxerror (errno, _("error reading output of %s"), script_name);
stop = true;
break;
}
if (nread == 0)
break;
buflen += n;
}
else if (pfd.revents & POLLHUP)
break;
}
close (pfd.fd);
if (stop)
kill (SIGKILL, pid);
sys_wait_for_child (pid, false);
if (stop)
{
free (buffer);
return false;
}
if (buflen == 0)
{
paxerror (0, _("empty output from \"%s %s\""), script_name, file_name);
return false;
}
cp = memchr (buffer, '\n', buflen);
if (cp)
*cp = 0;
else
{
if (buflen == bufsize)
buffer = xirealloc (buffer, ++bufsize);
buffer[buflen] = 0;
}
if (fmt)
{
struct tm tm;
time_t t;
cp = strptime (buffer, fmt, &tm);
if (cp == NULL)
{
paxerror (0, _("output from \"%s %s\" does not satisfy format string:"
" %s"),
script_name, file_name, buffer);
rc = false;
}
else if (*cp != 0)
{
paxwarn (0, _("unconsumed output from \"%s %s\": %s"),
script_name, file_name, cp);
rc = false;
}
else
{
tm.tm_wday = -1;
t = mktime (&tm);
if (tm.tm_wday < 0)
{
paxerror (errno, _("mktime failed"));
rc = false;
}
else
{
ts->tv_sec = t;
ts->tv_nsec = 0;
}
}
}
else if (! parse_datetime (ts, buffer, NULL))
{
paxerror (0, _("unparsable output from \"%s %s\": %s"),
script_name, file_name, buffer);
rc = false;
}
free (buffer);
return rc;
}
#endif /* not MSDOS */

2377
src/tar.c

File diff suppressed because it is too large Load Diff

188
src/tar.h
View File

@@ -1,21 +1,21 @@
/* GNU tar Archive Format description.
Copyright (C) 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
2000, 2001, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
Copyright 1988-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
This file is part of GNU tar.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* tar Header Block, from POSIX 1003.1-1990. */
@@ -48,41 +48,48 @@ struct posix_header
#define TVERSLEN 2
/* Values used in typeflag field. */
#define REGTYPE '0' /* regular file */
#define AREGTYPE '\0' /* regular file */
#define LNKTYPE '1' /* link */
#define SYMTYPE '2' /* reserved */
#define CHRTYPE '3' /* character special */
#define BLKTYPE '4' /* block special */
#define DIRTYPE '5' /* directory */
#define FIFOTYPE '6' /* FIFO special */
#define CONTTYPE '7' /* reserved */
enum
{
#define XHDTYPE 'x' /* Extended header referring to the
REGTYPE = '0', /* regular file */
AREGTYPE = '\0', /* regular file */
LNKTYPE = '1', /* link */
SYMTYPE = '2', /* reserved */
CHRTYPE = '3', /* character special */
BLKTYPE = '4', /* block special */
DIRTYPE = '5', /* directory */
FIFOTYPE = '6', /* FIFO special */
CONTTYPE = '7', /* reserved */
XHDTYPE = 'x', /* Extended header referring to the
next file in the archive */
#define XGLTYPE 'g' /* Global extended header */
XGLTYPE = 'g' /* Global extended header */
};
/* Bits used in the mode field, values in octal. */
#define TSUID 04000 /* set UID on execution */
#define TSGID 02000 /* set GID on execution */
#define TSVTX 01000 /* reserved */
enum
{
TSUID = 04000, /* set UID on execution */
TSGID = 02000, /* set GID on execution */
TSVTX = 01000, /* reserved */
/* file permissions */
#define TUREAD 00400 /* read by owner */
#define TUWRITE 00200 /* write by owner */
#define TUEXEC 00100 /* execute/search by owner */
#define TGREAD 00040 /* read by group */
#define TGWRITE 00020 /* write by group */
#define TGEXEC 00010 /* execute/search by group */
#define TOREAD 00004 /* read by other */
#define TOWRITE 00002 /* write by other */
#define TOEXEC 00001 /* execute/search by other */
TUREAD = 00400, /* read by owner */
TUWRITE = 00200, /* write by owner */
TUEXEC = 00100, /* execute/search by owner */
TGREAD = 00040, /* read by group */
TGWRITE = 00020, /* write by group */
TGEXEC = 00010, /* execute/search by group */
TOREAD = 00004, /* read by other */
TOWRITE = 00002, /* write by other */
TOEXEC = 00001 /* execute/search by other */
};
/* tar Header Block, GNU extensions. */
/* In GNU tar, SYMTYPE is for to symbolic links, and CONTTYPE is for
contiguous files, so maybe disobeying the `reserved' comment in POSIX
contiguous files, so maybe disobeying the "reserved" comment in POSIX
header description. I suspect these were meant to be used this way, and
should not have really been `reserved' in the published standards. */
should not have really been "reserved" in the published standards. */
/* *BEWARE* *BEWARE* *BEWARE* that the following information is still
boiling, and may change. Even if the OLDGNU format description should be
@@ -111,9 +118,12 @@ struct sparse
necessary. The following constants tell how many sparse descriptors fit
in each kind of header able to hold them. */
#define SPARSES_IN_EXTRA_HEADER 16
#define SPARSES_IN_OLDGNU_HEADER 4
#define SPARSES_IN_SPARSE_HEADER 21
enum
{
SPARSES_IN_EXTRA_HEADER = 16,
SPARSES_IN_OLDGNU_HEADER = 4,
SPARSES_IN_SPARSE_HEADER = 21
};
/* Extension header for sparse files, used immediately after the GNU extra
header, and used only if all sparse information cannot fit into that
@@ -168,29 +178,32 @@ struct oldgnu_header
'N' Obsolete GNU tar, for file names that do not fit into the main header.
'X' POSIX 1003.1-2001 eXtended (VU version) */
/* This is a dir entry that contains the names of files that were in the
dir at the time the dump was made. */
#define GNUTYPE_DUMPDIR 'D'
enum
{
/* This is a dir entry that contains the names of files that were in the
dir at the time the dump was made. */
GNUTYPE_DUMPDIR = 'D',
/* Identifies the *next* file on the tape as having a long linkname. */
#define GNUTYPE_LONGLINK 'K'
/* Identifies the *next* file on the tape as having a long linkname. */
GNUTYPE_LONGLINK = 'K',
/* Identifies the *next* file on the tape as having a long name. */
#define GNUTYPE_LONGNAME 'L'
/* Identifies the *next* file on the tape as having a long name. */
GNUTYPE_LONGNAME = 'L',
/* This is the continuation of a file that began on another volume. */
#define GNUTYPE_MULTIVOL 'M'
/* This is the continuation of a file that began on another volume. */
GNUTYPE_MULTIVOL = 'M',
/* This is for sparse files. */
#define GNUTYPE_SPARSE 'S'
/* This is for sparse files. */
GNUTYPE_SPARSE = 'S',
/* This file is a tape/volume header. Ignore it on extraction. */
#define GNUTYPE_VOLHDR 'V'
/* This file is a tape/volume header. Ignore it on extraction. */
GNUTYPE_VOLHDR = 'V',
/* Solaris extended header */
#define SOLARIS_XHDTYPE 'X'
/* Solaris extended header. */
SOLARIS_XHDTYPE = 'X'
};
/* J@"org Schilling star header */
/* Jörg Schilling star header. */
struct star_header
{ /* byte offset */
@@ -215,8 +228,11 @@ struct star_header
/* 500 */
};
#define SPARSES_IN_STAR_HEADER 4
#define SPARSES_IN_STAR_EXT_HEADER 21
enum
{
SPARSES_IN_STAR_HEADER = 4,
SPARSES_IN_STAR_EXT_HEADER = 21
};
struct star_in_header
{
@@ -245,8 +261,9 @@ struct star_ext_header
/* tar Header Block, overall structure. */
/* tar files are made in basic blocks of this size. */
#define BLOCKSIZE 512
/* tar files are made in basic blocks of size BLOCKSIZE.
LG_BLOCKSIZE is the log base 2 of BLOCKSIZE. */
enum { LG_BLOCKSIZE = 9, BLOCKSIZE = 1 << LG_BLOCKSIZE };
enum archive_format
{
@@ -271,9 +288,24 @@ struct sp_array
struct xheader
{
struct obstack *stk;
size_t size;
idx_t size;
char *buffer;
uintmax_t string_length;
idx_t string_length;
};
/* Information about xattrs for a file. */
struct xattr_array
{
char *xkey;
char *xval_ptr;
idx_t xval_len;
};
struct xattr_map
{
struct xattr_array *xm_map;
idx_t xm_size; /* Size of the xattr map */
idx_t xm_max; /* Max. number of entries in xattr_map */
};
struct tar_stat_info
@@ -287,6 +319,15 @@ struct tar_stat_info
char *uname; /* user name of owner */
char *gname; /* group name of owner */
char *cntx_name; /* SELinux context for the current archive entry. */
char *acls_a_ptr; /* Access ACLs for the current archive entry. */
idx_t acls_a_len; /* Access ACLs for the current archive entry. */
char *acls_d_ptr; /* Default ACLs for the current archive entry. */
idx_t acls_d_len; /* Default ACLs for the current archive entry. */
struct stat stat; /* regular filesystem stat */
/* STAT doesn't always have access, data modification, and status
@@ -301,14 +342,24 @@ struct tar_stat_info
bool is_sparse; /* Is the file sparse */
/* For sparse files: */
unsigned sparse_major;
unsigned sparse_minor;
size_t sparse_map_avail; /* Index to the first unused element in
intmax_t sparse_major;
intmax_t sparse_minor;
idx_t sparse_map_avail; /* Index to the first unused element in
sparse_map array. Zero if the file is
not sparse */
size_t sparse_map_size; /* Size of the sparse map */
idx_t sparse_map_size; /* Size of the sparse map */
struct sp_array *sparse_map;
off_t real_size; /* The real size of sparse file */
bool real_size_set; /* True when GNU.sparse.realsize is set in
archived file */
bool sparse_name_done; /* Set to true if 'GNU.sparse.name' header was
processed pax header parsing. Following 'path'
header (lower priority) will be ignored. */
struct xattr_map xattr_map;
/* Extended headers */
struct xheader xhdr;
@@ -337,6 +388,9 @@ struct tar_stat_info
It is negative if it could not be reopened after it was closed.
Negate it to find out what errno was when the reopen failed. */
int fd;
/* Exclusion list */
struct exclist *exclude_list;
};
union block

View File

@@ -1,5 +1,5 @@
/* This file is part of GNU tar.
Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
Copyright 2006-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
@@ -12,11 +12,12 @@
Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <system.h>
#include <regex.h>
#include <mcel.h>
#include <quotearg.h>
#include "common.h"
enum transform_type
@@ -50,9 +51,9 @@ struct replace_segm
struct
{
char *ptr;
size_t size;
idx_t size;
} literal; /* type == segm_literal */
size_t ref; /* type == segm_backref */
idx_t ref; /* type == segm_backref */
enum case_ctl_type ctl; /* type == segm_case_ctl */
} v;
};
@@ -62,16 +63,16 @@ struct transform
struct transform *next;
enum transform_type transform_type;
int flags;
unsigned match_number;
idx_t match_number;
regex_t regex;
/* Compiled replacement expression */
struct replace_segm *repl_head, *repl_tail;
size_t segm_count; /* Number of elements in the above list */
idx_t segm_count; /* Number of elements in the above list */
};
int transform_flags = XFORM_ALL;
static int transform_flags = XFORM_ALL;
static struct transform *transform_head, *transform_tail;
static struct transform *
@@ -101,9 +102,9 @@ add_segment (struct transform *tf)
}
static void
add_literal_segment (struct transform *tf, char *str, char *end)
add_literal_segment (struct transform *tf, const char *str, const char *end)
{
size_t len = end - str;
idx_t len = end - str;
if (len)
{
struct replace_segm *segm = add_segment (tf);
@@ -116,7 +117,7 @@ add_literal_segment (struct transform *tf, char *str, char *end)
}
static void
add_char_segment (struct transform *tf, int chr)
add_char_segment (struct transform *tf, char chr)
{
struct replace_segm *segm = add_segment (tf);
segm->type = segm_literal;
@@ -127,15 +128,15 @@ add_char_segment (struct transform *tf, int chr)
}
static void
add_backref_segment (struct transform *tf, size_t ref)
add_backref_segment (struct transform *tf, idx_t ref)
{
struct replace_segm *segm = add_segment (tf);
segm->type = segm_backref;
segm->v.ref = ref;
}
static int
parse_xform_flags (int *pflags, int c)
static bool
parse_xform_flags (int *pflags, char c)
{
switch (c)
{
@@ -164,9 +165,9 @@ parse_xform_flags (int *pflags, int c)
break;
default:
return 1;
return false;
}
return 0;
return true;
}
static void
@@ -180,8 +181,7 @@ add_case_ctl_segment (struct transform *tf, enum case_ctl_type ctl)
static const char *
parse_transform_expr (const char *expr)
{
int delim;
int i, j, rc;
idx_t i, j;
char *str, *beg, *cur;
const char *p;
int cflags = 0;
@@ -199,16 +199,17 @@ parse_transform_expr (const char *expr)
expr++;
break;
}
if (parse_xform_flags (&transform_flags, *expr))
USAGE_ERROR ((0, 0, _("Unknown transform flag: %c"),
*expr));
if (!parse_xform_flags (&transform_flags, *expr))
paxusage (_("Unknown transform flag: %c"), *expr);
}
return expr;
}
USAGE_ERROR ((0, 0, _("Invalid transform expression")));
paxusage (_("Invalid transform expression"));
}
delim = expr[1];
char delim = expr[1];
if (!delim)
paxusage (_("Invalid transform expression"));
/* Scan regular expression */
for (i = 2; expr[i] && expr[i] != delim; i++)
@@ -216,7 +217,7 @@ parse_transform_expr (const char *expr)
i++;
if (expr[i] != delim)
USAGE_ERROR ((0, 0, _("Invalid transform expression")));
paxusage (_("Invalid transform expression"));
/* Scan replacement expression */
for (j = i + 1; expr[j] && expr[j] != delim; j++)
@@ -224,7 +225,7 @@ parse_transform_expr (const char *expr)
j++;
if (expr[j] != delim)
USAGE_ERROR ((0, 0, _("Invalid transform expression")));
paxusage (_("Invalid transform expression"));
/* Check flags */
tf->transform_type = transform_first;
@@ -246,14 +247,16 @@ parse_transform_expr (const char *expr)
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
tf->match_number = strtoul (p, (char**) &p, 0);
p--;
{
char *endp;
tf->match_number = stoint (p, &endp, NULL, 0, IDX_MAX);
p = endp - 1;
}
break;
default:
if (parse_xform_flags (&tf->flags, *p))
USAGE_ERROR ((0, 0, _("Unknown flag in transform expression: %c"),
*p));
if (!parse_xform_flags (&tf->flags, *p))
paxusage (_("Unknown flag in transform expression: %c"), *p);
}
if (*p == ';')
@@ -264,16 +267,16 @@ parse_transform_expr (const char *expr)
memcpy (str, expr + 2, i - 2);
str[i - 2] = 0;
rc = regcomp (&tf->regex, str, cflags);
int rc = regcomp (&tf->regex, str, cflags);
if (rc)
{
char errbuf[512];
regerror (rc, &tf->regex, errbuf, sizeof (errbuf));
USAGE_ERROR ((0, 0, _("Invalid transform expression: %s"), errbuf));
paxusage (_("Invalid transform expression: %s"), errbuf);
}
if (str[0] == '^' || str[strlen (str) - 1] == '$')
if (str[0] == '^' || (i > 2 && str[i - 3] == '$'))
tf->transform_type = transform_first;
free (str);
@@ -288,17 +291,18 @@ parse_transform_expr (const char *expr)
{
if (*cur == '\\')
{
size_t n;
add_literal_segment (tf, beg, cur);
switch (*++cur)
{
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
n = strtoul (cur, &cur, 10);
if (n > tf->regex.re_nsub)
USAGE_ERROR ((0, 0, _("Invalid transform replacement: back reference out of range")));
add_backref_segment (tf, n);
{
idx_t n = stoint (cur, &cur, NULL, 0, IDX_MAX);
if (tf->regex.re_nsub < n)
paxusage (_("Invalid transform replacement:"
" back reference out of range"));
add_backref_segment (tf, n);
}
break;
case '\\':
@@ -347,7 +351,7 @@ parse_transform_expr (const char *expr)
break;
case 'L':
/* Turn the replacement to lowercase until a `\U' or `\E'
/* Turn the replacement to lowercase until a '\U' or '\E'
is found, */
add_case_ctl_segment (tf, ctl_locase);
cur++;
@@ -360,7 +364,7 @@ parse_transform_expr (const char *expr)
break;
case 'U':
/* Turn the replacement to uppercase until a `\L' or `\E'
/* Turn the replacement to uppercase until a '\L' or '\E'
is found, */
add_case_ctl_segment (tf, ctl_upcase);
cur++;
@@ -373,19 +377,21 @@ parse_transform_expr (const char *expr)
break;
case 'E':
/* Stop case conversion started by `\L' or `\U'. */
/* Stop case conversion started by '\L' or '\U'. */
add_case_ctl_segment (tf, ctl_stop);
cur++;
break;
default:
/* Try to be nice */
{
char buf[2];
buf[0] = '\\';
buf[1] = *cur;
add_literal_segment (tf, buf, buf + 2);
}
if (*cur == delim)
add_char_segment (tf, delim);
else
{
char buf[2];
buf[0] = '\\';
buf[1] = *cur;
add_literal_segment (tf, buf, buf + 2);
}
cur++;
break;
}
@@ -401,6 +407,7 @@ parse_transform_expr (const char *expr)
cur++;
}
add_literal_segment (tf, beg, cur);
free(str);
return p;
}
@@ -412,74 +419,56 @@ set_transform_expr (const char *expr)
expr = parse_transform_expr (expr);
}
/* Run case conversion specified by CASE_CTL on array PTR of SIZE
characters. Returns pointer to statically allocated storage. */
static char *
run_case_conv (enum case_ctl_type case_ctl, char *ptr, size_t size)
{
static char *case_ctl_buffer;
static size_t case_ctl_bufsize;
char *p;
if (case_ctl_bufsize < size)
{
case_ctl_bufsize = size;
case_ctl_buffer = xrealloc (case_ctl_buffer, case_ctl_bufsize);
}
memcpy (case_ctl_buffer, ptr, size);
switch (case_ctl)
{
case ctl_upcase_next:
case_ctl_buffer[0] = toupper ((unsigned char) case_ctl_buffer[0]);
break;
case ctl_locase_next:
case_ctl_buffer[0] = tolower ((unsigned char) case_ctl_buffer[0]);
break;
case ctl_upcase:
for (p = case_ctl_buffer; p < case_ctl_buffer + size; p++)
*p = toupper ((unsigned char) *p);
break;
case ctl_locase:
for (p = case_ctl_buffer; p < case_ctl_buffer + size; p++)
*p = tolower ((unsigned char) *p);
break;
case ctl_stop:
break;
}
return case_ctl_buffer;
}
static struct obstack stk;
static bool stk_init;
/* Run case conversion specified by CASE_CTL on array PTR of SIZE
characters. Append the result to STK. */
static void
run_case_conv (enum case_ctl_type case_ctl, char *ptr, idx_t size)
{
char const *p = ptr, *plim = ptr + size;
mbstate_t mbs; mbszero (&mbs);
while (p < plim)
{
mcel_t g = mcel_scan (p, plim);
char32_t ch;
switch (case_ctl)
{
case ctl_upcase: case ctl_upcase_next: ch = c32toupper (g.ch); break;
case ctl_locase: case ctl_locase_next: ch = c32tolower (g.ch); break;
default: ch = g.ch; break;
}
if (ch == g.ch)
obstack_grow (&stk, p, g.len);
else
{
obstack_make_room (&stk, MB_LEN_MAX);
mbstate_t ombs; mbszero (&ombs);
idx_t outbytes = c32rtomb (obstack_next_free (&stk), ch, &ombs);
obstack_blank_fast (&stk, outbytes);
}
p += g.len;
if (case_ctl != ctl_upcase && case_ctl != ctl_locase)
break;
}
obstack_grow (&stk, p, plim - p);
}
static void
_single_transform_name_to_obstack (struct transform *tf, char *input)
{
regmatch_t *rmp;
int rc;
size_t nmatches = 0;
idx_t nmatches = 0;
enum case_ctl_type case_ctl = ctl_stop, /* Current case conversion op */
save_ctl = ctl_stop; /* Saved case_ctl for \u and \l */
/* Reset case conversion after a single-char operation */
#define CASE_CTL_RESET() if (case_ctl == ctl_upcase_next \
|| case_ctl == ctl_locase_next) \
{ \
case_ctl = save_ctl; \
save_ctl = ctl_stop; \
}
rmp = xmalloc ((tf->regex.re_nsub + 1) * sizeof (*rmp));
regmatch_t *rmp = xinmalloc (tf->regex.re_nsub + 1, sizeof *rmp);
while (*input)
{
size_t disp;
char *ptr;
idx_t disp;
rc = regexec (&tf->regex, input, tf->regex.re_nsub + 1, rmp, 0);
@@ -489,9 +478,6 @@ _single_transform_name_to_obstack (struct transform *tf, char *input)
disp = rmp[0].rm_eo;
if (rmp[0].rm_so)
obstack_grow (&stk, input, rmp[0].rm_so);
nmatches++;
if (tf->match_number && nmatches < tf->match_number)
{
@@ -500,37 +486,36 @@ _single_transform_name_to_obstack (struct transform *tf, char *input)
continue;
}
if (rmp[0].rm_so)
obstack_grow (&stk, input, rmp[0].rm_so);
for (segm = tf->repl_head; segm; segm = segm->next)
{
switch (segm->type)
{
case segm_literal: /* Literal segment */
if (case_ctl == ctl_stop)
ptr = segm->v.literal.ptr;
else
run_case_conv (case_ctl,
segm->v.literal.ptr,
segm->v.literal.size);
case_ctl_reset:
/* Reset case conversion after a single-char operation. */
if (case_ctl == ctl_upcase_next
|| case_ctl == ctl_locase_next)
{
ptr = run_case_conv (case_ctl,
segm->v.literal.ptr,
segm->v.literal.size);
CASE_CTL_RESET();
case_ctl = save_ctl;
save_ctl = ctl_stop;
}
obstack_grow (&stk, ptr, segm->v.literal.size);
break;
case segm_backref: /* Back-reference segment */
if (rmp[segm->v.ref].rm_so != -1
&& rmp[segm->v.ref].rm_eo != -1)
if (0 <= rmp[segm->v.ref].rm_so
&& 0 <= rmp[segm->v.ref].rm_eo)
{
size_t size = rmp[segm->v.ref].rm_eo
- rmp[segm->v.ref].rm_so;
ptr = input + rmp[segm->v.ref].rm_so;
if (case_ctl != ctl_stop)
{
ptr = run_case_conv (case_ctl, ptr, size);
CASE_CTL_RESET();
}
obstack_grow (&stk, ptr, size);
idx_t size = (rmp[segm->v.ref].rm_eo
- rmp[segm->v.ref].rm_so);
run_case_conv (case_ctl,
input + rmp[segm->v.ref].rm_so, size);
goto case_ctl_reset;
}
break;
@@ -548,7 +533,7 @@ _single_transform_name_to_obstack (struct transform *tf, char *input)
default:
break;
}
/*FALL THROUGH*/
FALLTHROUGH;
case ctl_upcase:
case ctl_locase:
@@ -577,11 +562,11 @@ _single_transform_name_to_obstack (struct transform *tf, char *input)
free (rmp);
}
static bool
static void
_transform_name_to_obstack (int flags, char *input, char **output)
{
struct transform *tf;
bool alloced = false;
bool ok = false;
if (!stk_init)
{
@@ -595,36 +580,57 @@ _transform_name_to_obstack (int flags, char *input, char **output)
{
_single_transform_name_to_obstack (tf, input);
input = obstack_finish (&stk);
alloced = true;
ok = true;
}
}
if (!ok)
{
obstack_grow0 (&stk, input, strlen (input));
input = obstack_finish (&stk);
}
*output = input;
return alloced;
}
/* Transform name *PINPUT of a file or archive member of type TYPE
(a single XFORM_* bit). If FUN is not NULL, call this function
to further transform the result. Arguments to FUN are the transformed
name and type, it's return value is the new transformed name.
If transformation results in a non-empty string, store the result in
*PINPUT and return true. Otherwise, if it results in an empty string,
issue a warning, return false and don't modify PINPUT.
*/
bool
transform_name_fp (char **pinput, int flags,
char *(*fun)(char *, void *), void *dat)
transform_name_fp (char **pinput, int type,
char const *(*fun) (char const *, int))
{
char *str;
bool ret = _transform_name_to_obstack (flags, *pinput, &str);
if (ret)
{
assign_string (pinput, fun ? fun (str, dat) : str);
obstack_free (&stk, str);
}
else if (fun)
{
*pinput = NULL;
assign_string (pinput, fun (str, dat));
free (str);
ret = true;
}
return ret;
char *str;
char const *result;
_transform_name_to_obstack (type, *pinput, &str);
result = (str[0] != 0 && fun) ? fun (str, type) : str;
if (result[0] == 0)
{
warnopt (WARN_EMPTY_TRANSFORM, 0,
_("%s: transforms to empty name"), quotearg_colon (*pinput));
obstack_free (&stk, str);
return false;
}
assign_string (pinput, result);
obstack_free (&stk, str);
return true;
}
bool
transform_name (char **pinput, int type)
{
return transform_name_fp (pinput, type, NULL, NULL);
return transform_name_fp (pinput, type, NULL);
}
bool
transform_program_p (void)
{
return transform_head != NULL;
}

View File

@@ -1,19 +1,21 @@
/* This file is part of GNU tar.
Copyright (C) 2009 Free Software Foundation, Inc.
/* Unlink files.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
Copyright 2009-2025 Free Software Foundation, Inc.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
This file is part of GNU tar.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <system.h>
#include "common.h"
@@ -22,38 +24,51 @@
struct deferred_unlink
{
struct deferred_unlink *next; /* Next unlink in the queue */
char *file_name; /* Absolute name of the file to unlink */
idx_t dir_idx; /* Directory index in wd */
char *file_name; /* Name of the file to unlink, relative
to dir_idx */
bool is_dir; /* True if file_name is a directory */
off_t records_written; /* Number of records written when this
entry got added to the queue */
};
static bool
is_cwd (struct deferred_unlink const *p)
{
return p->is_dir && !p->file_name[p->file_name[0] == '.'];
}
/* The unlink queue */
static struct deferred_unlink *dunlink_head, *dunlink_tail;
/* Number of entries in the queue */
static size_t dunlink_count;
/* List of entries available for allocation */
static struct deferred_unlink *dunlink_avail;
/* Delay (number of records written) between adding entry to the
list and its actual removal. */
size_t deferred_unlink_delay = 0;
static struct deferred_unlink *
dunlink_alloc (void)
{
struct deferred_unlink *p;
if (dunlink_avail)
struct deferred_unlink *p = dunlink_avail;
if (!p)
return xmalloc (sizeof *p);
dunlink_avail = p->next;
return p;
}
static void
dunlink_insert (struct deferred_unlink *anchor, struct deferred_unlink *p)
{
if (anchor)
{
p = dunlink_avail;
dunlink_avail = p->next;
p->next = NULL;
p->next = anchor->next;
anchor->next = p;
}
else
p = xmalloc (sizeof (*p));
return p;
{
p->next = dunlink_head;
dunlink_head = p;
}
if (!p->next)
dunlink_tail = p;
}
static void
@@ -68,44 +83,59 @@ static void
flush_deferred_unlinks (bool force)
{
struct deferred_unlink *p, *prev = NULL;
idx_t saved_chdir = chdir_current;
for (p = dunlink_head; p; )
{
struct deferred_unlink *next = p->next;
if (force
|| records_written > p->records_written + deferred_unlink_delay)
|| p->records_written < records_written)
{
chdir_do (p->dir_idx);
if (p->is_dir)
{
if (unlinkat (chdir_fd, p->file_name, AT_REMOVEDIR) != 0)
const char *fname;
if (p->dir_idx && is_cwd (p))
{
prev = p;
p = next;
continue;
}
else
fname = p->file_name;
if (unlinkat (chdir_fd, fname, AT_REMOVEDIR) < 0)
{
switch (errno)
{
case ENOENT:
/* nothing to worry about */
break;
case EEXIST:
/* OpenSolaris >=10 sets EEXIST instead of ENOTEMPTY
if trying to remove a non-empty directory */
#if defined ENOTEMPTY && ENOTEMPTY != EEXIST
case ENOTEMPTY:
if (!force)
{
/* Keep the record in list, in the hope we'll
be able to remove it later */
prev = p;
p = next;
continue;
}
/* fall through */
#endif
/* Keep the record in list, in the hope we'll
be able to remove it later */
prev = p;
p = next;
continue;
default:
rmdir_error (p->file_name);
rmdir_error (fname);
}
}
}
else
{
if (unlinkat (chdir_fd, p->file_name, 0) != 0 && errno != ENOENT)
if (unlinkat (chdir_fd, p->file_name, 0) < 0 && errno != ENOENT)
unlink_error (p->file_name);
}
dunlink_reclaim (p);
dunlink_count--;
p = next;
if (prev)
prev->next = p;
@@ -120,12 +150,41 @@ flush_deferred_unlinks (bool force)
}
if (!dunlink_head)
dunlink_tail = NULL;
else if (force)
{
for (p = dunlink_head; p; )
{
struct deferred_unlink *next = p->next;
const char *fname;
chdir_do (p->dir_idx);
if (p->dir_idx && is_cwd (p))
{
fname = tar_dirname ();
chdir_do (p->dir_idx - 1);
}
else
fname = p->file_name;
if (unlinkat (chdir_fd, fname, AT_REMOVEDIR) < 0)
{
if (errno != ENOENT)
rmdir_error (fname);
}
dunlink_reclaim (p);
p = next;
}
dunlink_head = dunlink_tail = NULL;
}
chdir_do (saved_chdir);
}
void
finish_deferred_unlinks ()
finish_deferred_unlinks (void)
{
flush_deferred_unlinks (true);
while (dunlink_avail)
{
struct deferred_unlink *next = dunlink_avail->next;
@@ -140,19 +199,28 @@ queue_deferred_unlink (const char *name, bool is_dir)
struct deferred_unlink *p;
if (dunlink_head
&& records_written > dunlink_head->records_written + deferred_unlink_delay)
&& records_written > dunlink_head->records_written)
flush_deferred_unlinks (false);
p = dunlink_alloc ();
p->next = NULL;
p->file_name = normalize_filename (name);
p->dir_idx = chdir_current;
p->file_name = xstrdup (name);
normalize_filename_x (p->file_name);
p->is_dir = is_dir;
p->records_written = records_written;
if (dunlink_tail)
dunlink_tail->next = p;
if (is_cwd (p))
{
struct deferred_unlink *q, *prev;
for (q = dunlink_head, prev = NULL; q; prev = q, q = q->next)
if (is_cwd (q) && q->dir_idx < p->dir_idx)
break;
if (q)
dunlink_insert (prev, p);
else
dunlink_insert (dunlink_tail, p);
}
else
dunlink_head = p;
dunlink_tail = p;
dunlink_count++;
dunlink_insert (dunlink_tail, p);
}

View File

@@ -1,21 +1,21 @@
/* Update a tar archive.
Copyright (C) 1988, 1992, 1994, 1996, 1997, 1999, 2000, 2001, 2003,
2004, 2005, 2007, 2010 Free Software Foundation, Inc.
Copyright 1988-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
This file is part of GNU tar.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Implement the 'r', 'u' and 'A' options for tar. 'A' means that the
file names are tar files, and they should simply be appended to the end
@@ -26,10 +26,6 @@
#include <quotearg.h>
#include "common.h"
/* FIXME: This module should not directly handle the following variable,
instead, this should be done in buffer.c only. */
extern union block *current_block;
/* We've hit the end of the old stuff, and its time to start writing new
stuff to the tape. This involves seeking back one record and
re-writing the current record (which has been changed).
@@ -42,13 +38,14 @@ bool time_to_start_writing;
first part of the record. */
char *output_start;
static bool acting_as_filter;
/* Catenate file FILE_NAME to the archive without creating a header for it.
It had better be a tar file or the archive is screwed. */
static void
append_file (char *file_name)
{
int handle = openat (chdir_fd, file_name, O_RDONLY | O_BINARY);
struct stat stat_data;
if (handle < 0)
{
@@ -56,49 +53,44 @@ append_file (char *file_name)
return;
}
if (fstat (handle, &stat_data) != 0)
stat_error (file_name);
else
while (true)
{
off_t bytes_left = stat_data.st_size;
while (bytes_left > 0)
{
union block *start = find_next_block ();
size_t buffer_size = available_space_after (start);
size_t status;
char buf[UINTMAX_STRSIZE_BOUND];
if (bytes_left < buffer_size)
{
buffer_size = bytes_left;
status = buffer_size % BLOCKSIZE;
if (status)
memset (start->buffer + bytes_left, 0, BLOCKSIZE - status);
}
status = safe_read (handle, start->buffer, buffer_size);
if (status == SAFE_READ_ERROR)
read_fatal_details (file_name, stat_data.st_size - bytes_left,
buffer_size);
if (status == 0)
FATAL_ERROR ((0, 0,
ngettext ("%s: File shrank by %s byte",
"%s: File shrank by %s bytes",
bytes_left),
quotearg_colon (file_name),
STRINGIFY_BIGINT (bytes_left, buf)));
bytes_left -= status;
set_next_block_after (start + (status - 1) / BLOCKSIZE);
}
union block *start = find_next_block ();
idx_t bufsize = available_space_after (start);
idx_t status = full_read (handle, charptr (start), bufsize);
if (status < bufsize && errno)
read_fatal (file_name);
if (status == 0)
break;
idx_t rem = status % BLOCKSIZE;
if (rem)
memset (charptr (start) + (status - rem), 0, BLOCKSIZE - rem);
set_next_block_after (charptr (start) + status - 1);
}
if (close (handle) != 0)
if (close (handle) < 0)
close_error (file_name);
}
/* If NAME is not a pattern, remove it from the namelist. Otherwise,
remove the FILE_NAME that matched it. Take care to look for exact
match when removing it. */
static void
remove_exact_name (struct name *name, char const *file_name)
{
if (name->is_wildcard)
{
struct name *match = name_scan (file_name, true);
name->found_count++;
if (match)
name = match;
else
return;
}
remname (name);
}
/* Implement the 'r' (add files to end of archive), and 'u' (add files
to end of archive if they aren't there, or are more up to date than
the version in the archive) commands. */
@@ -110,7 +102,8 @@ update_archive (void)
name_gather ();
open_archive (ACCESS_UPDATE);
buffer_write_global_xheader ();
acting_as_filter = strcmp (archive_name_array[0], "-") == 0;
xheader_forbid_global ();
while (!found_end)
{
@@ -129,11 +122,13 @@ update_archive (void)
struct name *name;
decode_header (current_header, &current_stat_info,
&current_format, 0);
&current_format, false);
transform_stat_info (current_header->header.typeflag,
&current_stat_info);
archive_format = current_format;
if (subcommand_option == UPDATE_SUBCOMMAND
&& (name = name_scan (current_stat_info.file_name)) != NULL)
&& (name = name_scan (current_stat_info.file_name, false)) != NULL)
{
struct stat s;
@@ -142,42 +137,36 @@ update_archive (void)
{
if (S_ISDIR (s.st_mode))
{
char *p, *dirp;
DIR *stream;
int fd = openat (chdir_fd, name->name,
open_read_flags | O_DIRECTORY);
if (fd < 0)
open_error (name->name);
else if (! ((stream = fdopendir (fd))
&& (dirp = streamsavedir (stream))))
savedir_error (name->name);
else
char *p;
char *dirp = tar_savedir (current_stat_info.file_name,
true);
if (dirp)
{
namebuf_t nbuf = namebuf_create (name->name);
namebuf_t nbuf = namebuf_create (current_stat_info.file_name);
for (p = dirp; *p; p += strlen (p) + 1)
addname (namebuf_name (nbuf, p),
0, false, NULL);
name->change_dir, false, NULL);
namebuf_free (nbuf);
free (dirp);
remname (name);
remove_exact_name (name, current_stat_info.file_name);
}
if (stream
? closedir (stream) != 0
: 0 <= fd && close (fd) != 0)
savedir_error (name->name);
}
else if (tar_timespec_cmp (get_stat_mtime (&s),
current_stat_info.mtime)
<= 0)
remname (name);
{
remove_exact_name (name, current_stat_info.file_name);
}
else if (name->is_wildcard)
addname (current_stat_info.file_name,
name->change_dir, false, NULL);
}
}
skip_member ();
skim_member (acting_as_filter);
break;
}
@@ -195,14 +184,12 @@ update_archive (void)
switch (previous_status)
{
case HEADER_STILL_UNREAD:
WARN ((0, 0, _("This does not look like a tar archive")));
/* Fall through. */
paxwarn (0, _("This does not look like a tar archive"));
FALLTHROUGH;
case HEADER_SUCCESS:
case HEADER_ZERO_BLOCK:
ERROR ((0, 0, _("Skipping to next header")));
/* Fall through. */
paxerror (0, _("Skipping to next header"));
FALLTHROUGH;
case HEADER_FAILURE:
break;
@@ -219,14 +206,14 @@ update_archive (void)
reset_eof ();
time_to_start_writing = true;
output_start = current_block->buffer;
output_start = charptr (current_block);
{
struct name const *p;
while ((p = name_from_list ()) != NULL)
{
char *file_name = p->name;
if (excluded_name (file_name))
if (excluded_name (file_name, NULL))
continue;
if (interactive_option && !confirm ("add", file_name))
continue;

View File

@@ -1,20 +1,21 @@
/* Charset handling for GNU tar.
Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
Copyright 2004-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
This file is part of GNU tar.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <system.h>
#include <quotearg.h>
@@ -34,11 +35,15 @@
# define iconv_open(tocode, fromcode) ((iconv_t) -1)
# undef iconv
# define iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft) ((size_t) 0)
# define iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft) \
(errno = ENOSYS, SIZE_MAX)
# undef iconv_close
# define iconv_close(cd) 0
# undef iconv_t
# define iconv_t int
#endif
@@ -49,24 +54,23 @@ static iconv_t conv_desc[2] = { (iconv_t) -1, (iconv_t) -1 };
static iconv_t
utf8_init (bool to_utf)
{
if (conv_desc[(int) to_utf] == (iconv_t) -1)
if (conv_desc[to_utf] == (iconv_t) -1)
{
if (to_utf)
conv_desc[(int) to_utf] = iconv_open ("UTF-8", locale_charset ());
conv_desc[to_utf] = iconv_open ("UTF-8", locale_charset ());
else
conv_desc[(int) to_utf] = iconv_open (locale_charset (), "UTF-8");
conv_desc[to_utf] = iconv_open (locale_charset (), "UTF-8");
}
return conv_desc[(int) to_utf];
return conv_desc[to_utf];
}
bool
utf8_convert (bool to_utf, char const *input, char **output)
{
char ICONV_CONST *ib;
char *ob;
char *ob, *ret;
size_t inlen;
size_t outlen;
size_t rc;
iconv_t cd = utf8_init (to_utf);
if (cd == 0)
@@ -74,16 +78,35 @@ utf8_convert (bool to_utf, char const *input, char **output)
*output = xstrdup (input);
return true;
}
else if (cd == (iconv_t)-1)
else if (cd == (iconv_t) -1)
return false;
inlen = strlen (input) + 1;
outlen = inlen * MB_LEN_MAX + 1;
ob = *output = xmalloc (outlen);
bool overflow = ckd_mul (&outlen, inlen, MB_LEN_MAX);
overflow |= ckd_add (&outlen, outlen, 1);
if (overflow)
xalloc_die ();
ob = ret = xmalloc (outlen);
ib = (char ICONV_CONST *) input;
rc = iconv (cd, &ib, &inlen, &ob, &outlen);
/* According to POSIX, "if iconv() encounters a character in the input
buffer that is valid, but for which an identical character does not
exist in the target codeset, iconv() shall perform an
implementation-defined conversion on this character." It will "update
the variables pointed to by the arguments to reflect the extent of the
conversion and return the number of non-identical conversions performed".
On error, it returns SIZE_MAX.
In other words, non-zero return always indicates failure, either because
the input was not fully converted, or because it was converted in a
non-reversible way.
*/
if (iconv (cd, &ib, &inlen, &ob, &outlen) != 0)
{
free (ret);
return false;
}
*ob = 0;
return rc != -1;
*output = ret;
return true;
}

View File

@@ -1,19 +1,21 @@
/* This file is part of GNU tar.
/* Warnings for GNU tar.
Copyright (C) 2009 Free Software Foundation, Inc.
Copyright 2009-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
This file is part of GNU tar.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>. */
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <system.h>
#include <argmatch.h>
@@ -41,6 +43,14 @@ static char const *const warning_args[] = {
"unknown-cast",
"unknown-keyword",
"xdev",
"decompress-program",
"existing-file",
"xattr-write",
"record-size",
"failed-read",
"missing-zero-blocks",
"verbose",
"empty-transform",
NULL
};
@@ -64,17 +74,25 @@ static int warning_types[] = {
WARN_TIMESTAMP,
WARN_UNKNOWN_CAST,
WARN_UNKNOWN_KEYWORD,
WARN_XDEV
WARN_XDEV,
WARN_DECOMPRESS_PROGRAM,
WARN_EXISTING_FILE,
WARN_XATTR_WRITE,
WARN_RECORD_SIZE,
WARN_FAILED_READ,
WARN_MISSING_ZERO_BLOCKS,
WARN_VERBOSE_WARNINGS,
WARN_EMPTY_TRANSFORM
};
ARGMATCH_VERIFY (warning_args, warning_types);
int warning_option = WARN_ALL;
int warning_option = WARN_ALL & ~(WARN_VERBOSE_WARNINGS|WARN_MISSING_ZERO_BLOCKS);
void
set_warning_option (const char *arg)
{
int negate = 0;
bool negate = false;
int option;
if (strcmp (arg, "none") == 0)
@@ -84,7 +102,7 @@ set_warning_option (const char *arg)
}
if (strlen (arg) > 2 && memcmp (arg, "no-", 3) == 0)
{
negate = 1;
negate = true;
arg += 3;
}
@@ -95,3 +113,17 @@ set_warning_option (const char *arg)
else
warning_option |= option;
}
void
warnopt (int opt, int errnum, char const *format, ...)
{
if (warning_enabled (opt))
{
if (error_hook)
error_hook ();
va_list ap;
va_start (ap, format);
verror (0, errnum, format, ap);
va_end (ap);
}
}

833
src/xattrs.c Normal file
View File

@@ -0,0 +1,833 @@
/* Support for extended attributes.
Copyright (C) 2006-2025 Free Software Foundation, Inc.
This file is part of GNU tar.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Written by James Antill, on 2006-07-27. */
#include <config.h>
#include <system.h>
#include <fnmatch.h>
#include <quotearg.h>
#include "common.h"
#include "xattr-at.h"
#include "selinux-at.h"
static char const XATTRS_PREFIX[] = "SCHILY.xattr.";
enum { XATTRS_PREFIX_LEN = sizeof XATTRS_PREFIX - 1 };
void
xheader_xattr_init (struct tar_stat_info *st)
{
xattr_map_init (&st->xattr_map);
st->acls_a_ptr = NULL;
st->acls_a_len = 0;
st->acls_d_ptr = NULL;
st->acls_d_len = 0;
st->cntx_name = NULL;
}
void
xattr_map_init (struct xattr_map *map)
{
memset (map, 0, sizeof *map);
}
void
xattr_map_free (struct xattr_map *xattr_map)
{
for (idx_t i = 0; i < xattr_map->xm_size; i++)
{
free (xattr_map->xm_map[i].xkey);
free (xattr_map->xm_map[i].xval_ptr);
}
free (xattr_map->xm_map);
}
void
xattr_map_add (struct xattr_map *map,
const char *key, const char *val, idx_t len)
{
if (map->xm_size == map->xm_max)
map->xm_map = xpalloc (map->xm_map, &map->xm_max, 1, -1,
sizeof *map->xm_map);
struct xattr_array *p = &map->xm_map[map->xm_size];
p->xkey = xstrdup (key);
p->xval_ptr = ximemdup (val, len + 1);
p->xval_len = len;
map->xm_size++;
}
static void
xheader_xattr_add (struct tar_stat_info *st,
const char *key, const char *val, idx_t len)
{
idx_t klen = strlen (key);
char *xkey = xmalloc (XATTRS_PREFIX_LEN + klen + 1);
char *tmp = xkey;
tmp = stpcpy (tmp, XATTRS_PREFIX);
stpcpy (tmp, key);
xattr_map_add (&st->xattr_map, xkey, val, len);
free (xkey);
}
void
xattr_map_copy (struct xattr_map *dst, const struct xattr_map *src)
{
for (idx_t i = 0; i < src->xm_size; i++)
xattr_map_add (dst, src->xm_map[i].xkey,
src->xm_map[i].xval_ptr,
src->xm_map[i].xval_len);
}
struct xattrs_mask_map
{
const char **masks;
idx_t size;
idx_t used;
};
/* list of fnmatch patterns */
static struct
{
/* lists of fnmatch patterns */
struct xattrs_mask_map incl;
struct xattrs_mask_map excl;
} xattrs_setup;
/* disable posix acls when problem found in gnulib script m4/acl.m4 */
#if ! USE_ACL
# undef HAVE_POSIX_ACLS
#endif
#ifdef HAVE_POSIX_ACLS
# include "acl.h"
# include <sys/acl.h>
# ifdef HAVE_ACL_LIBACL_H
# /* needed for numeric-owner support */
# include <acl/libacl.h>
# endif
#endif
#ifdef HAVE_POSIX_ACLS
/* acl-at wrappers, TODO: move to gnulib in future? */
static acl_t acl_get_file_at (int, const char *, acl_type_t);
static int acl_set_file_at (int, const char *, acl_type_t, acl_t);
static int file_has_acl_at (int, char const *, struct stat const *);
static int acl_delete_def_file_at (int, char const *);
/* acl_get_file_at */
#define AT_FUNC_NAME acl_get_file_at
#define AT_FUNC_RESULT acl_t
#define AT_FUNC_FAIL (acl_t)NULL
#define AT_FUNC_F1 acl_get_file
#define AT_FUNC_POST_FILE_PARAM_DECLS , acl_type_t type
#define AT_FUNC_POST_FILE_ARGS , type
#include "at-func.c"
#undef AT_FUNC_NAME
#undef AT_FUNC_F1
#undef AT_FUNC_RESULT
#undef AT_FUNC_FAIL
#undef AT_FUNC_POST_FILE_PARAM_DECLS
#undef AT_FUNC_POST_FILE_ARGS
/* acl_set_file_at */
#define AT_FUNC_NAME acl_set_file_at
#define AT_FUNC_F1 acl_set_file
#define AT_FUNC_POST_FILE_PARAM_DECLS , acl_type_t type, acl_t acl
#define AT_FUNC_POST_FILE_ARGS , type, acl
#include "at-func.c"
#undef AT_FUNC_NAME
#undef AT_FUNC_F1
#undef AT_FUNC_POST_FILE_PARAM_DECLS
#undef AT_FUNC_POST_FILE_ARGS
/* acl_delete_def_file_at */
#define AT_FUNC_NAME acl_delete_def_file_at
#define AT_FUNC_F1 acl_delete_def_file
#define AT_FUNC_POST_FILE_PARAM_DECLS
#define AT_FUNC_POST_FILE_ARGS
#include "at-func.c"
#undef AT_FUNC_NAME
#undef AT_FUNC_F1
#undef AT_FUNC_POST_FILE_PARAM_DECLS
#undef AT_FUNC_POST_FILE_ARGS
/* gnulib file_has_acl_at */
#define AT_FUNC_NAME file_has_acl_at
#define AT_FUNC_F1 file_has_acl
#define AT_FUNC_POST_FILE_PARAM_DECLS , struct stat const *st
#define AT_FUNC_POST_FILE_ARGS , st
#include "at-func.c"
#undef AT_FUNC_NAME
#undef AT_FUNC_F1
#undef AT_FUNC_POST_FILE_PARAM_DECLS
#undef AT_FUNC_POST_FILE_ARGS
/* convert unix permissions into an ACL ... needed due to "default" ACLs */
static acl_t
perms2acl (int perms)
{
char val[] = "user::---,group::---,other::---";
/* 0123456789 123456789 123456789 123456789 */
/* user */
if (perms & 0400)
val[6] = 'r';
if (perms & 0200)
val[7] = 'w';
if (perms & 0100)
val[8] = 'x';
/* group */
if (perms & 0040)
val[17] = 'r';
if (perms & 0020)
val[18] = 'w';
if (perms & 0010)
val[19] = 'x';
/* other */
if (perms & 0004)
val[28] = 'r';
if (perms & 0002)
val[29] = 'w';
if (perms & 0001)
val[30] = 'x';
return acl_from_text (val);
}
static char *
skip_to_ext_fields (char *ptr)
{
/* skip tag name (user/group/default/mask) */
ptr += strcspn (ptr, ":,\n");
if (*ptr != ':')
return ptr;
++ptr;
ptr += strcspn (ptr, ":,\n"); /* skip user/group name */
if (*ptr != ':')
return ptr;
++ptr;
ptr += strcspn (ptr, ":,\n"); /* skip perms */
return ptr;
}
/* The POSIX draft allows extra fields after the three main ones. Star
uses this to add a fourth field for user/group which is the numeric ID.
This function removes such extra fields by overwriting them with the
characters that follow. */
static char *
fixup_extra_acl_fields (char *ptr)
{
char *src = ptr;
char *dst = ptr;
while (*src)
{
const char *old = src;
idx_t len = 0;
src = skip_to_ext_fields (src);
len = src - old;
if (old != dst)
memmove (dst, old, len);
dst += len;
if (*src == ':') /* We have extra fields, skip them all */
src += strcspn (src, "\n,");
if ((*src == '\n') || (*src == ','))
*dst++ = *src++; /* also done when dst == src, but that's ok */
}
if (src != dst)
*dst = 0;
return ptr;
}
/* Set the "system.posix_acl_access/system.posix_acl_default" extended
attribute. Called only when acls_option > 0. */
static void
xattrs__acls_set (struct tar_stat_info const *st,
char const *file_name, acl_type_t type,
char *ptr, bool def)
{
acl_t acl;
if (ptr)
{
ptr = fixup_extra_acl_fields (ptr);
acl = acl_from_text (ptr);
}
else if (def)
{
/* No "default" IEEE 1003.1e ACL set for directory. At this moment,
FILE_NAME may already have inherited default acls from parent
directory; clean them up. */
if (acl_delete_def_file_at (chdir_fd, file_name) < 0)
warnopt (WARN_XATTR_WRITE, errno,
_("acl_delete_def_file_at: Cannot drop default POSIX ACLs "
"for file '%s'"),
file_name);
return;
}
else
acl = perms2acl (st->stat.st_mode);
if (!acl)
{
call_arg_warn ("acl_from_text", file_name);
return;
}
if (acl_set_file_at (chdir_fd, file_name, type, acl) < 0)
/* warn even if filesystem does not support acls */
warnopt (WARN_XATTR_WRITE, errno,
_ ("acl_set_file_at: Cannot set POSIX ACLs for file '%s'"),
file_name);
acl_free (acl);
}
/* Cleanup textual representation of the ACL in VAL by eliminating tab
characters and comments */
static void
xattrs_acls_cleanup (char *val, idx_t *plen)
{
char *p, *q;
p = q = val + strcspn (val, "#\t");
while (*q)
{
if (*q == '\t')
q++;
else if (*q == '#')
{
while (*q != '\n')
q++;
}
else
*p++ = *q++;
}
*plen = p - val;
*p++ = 0;
}
static void
acls_get_text (int parentfd, const char *file_name, acl_type_t type,
char **ret_ptr, idx_t *ret_len)
{
char *val = NULL;
acl_t acl;
if (!(acl = acl_get_file_at (parentfd, file_name, type)))
{
if (errno != ENOTSUP)
call_arg_warn ("acl_get_file_at", file_name);
return;
}
if (numeric_owner_option)
{
#ifdef HAVE_ACL_LIBACL_H
val = acl_to_any_text (acl, NULL, '\n',
TEXT_SOME_EFFECTIVE | TEXT_NUMERIC_IDS);
#else
static bool warned;
if (!warned)
{
warned = true;
paxwarn (0, _("--numeric-owner is ignored for ACLs:"
" libacl is not available"));
}
#endif
}
else
val = acl_to_text (acl, NULL);
acl_free (acl);
if (!val)
{
call_arg_warn ("acl_to_text", file_name);
return;
}
*ret_ptr = xstrdup (val);
xattrs_acls_cleanup (*ret_ptr, ret_len);
acl_free (val);
}
static void
xattrs__acls_get_a (int parentfd, const char *file_name,
char **ret_ptr, idx_t *ret_len)
{
acls_get_text (parentfd, file_name, ACL_TYPE_ACCESS, ret_ptr, ret_len);
}
/* "system.posix_acl_default" */
static void
xattrs__acls_get_d (int parentfd, char const *file_name,
char **ret_ptr, idx_t *ret_len)
{
acls_get_text (parentfd, file_name, ACL_TYPE_DEFAULT, ret_ptr, ret_len);
}
#endif /* HAVE_POSIX_ACLS */
static void
acls_one_line (const char *prefix, char delim,
const char *aclstring, idx_t len)
{
/* support both long and short text representation of posix acls */
struct obstack stk;
idx_t pref_len = strlen (prefix);
const char *oldstring = aclstring;
idx_t pos = 0;
if (!aclstring || !len)
return;
obstack_init (&stk);
while (pos <= len)
{
idx_t move = strcspn (aclstring, ",\n");
if (!move)
break;
if (oldstring != aclstring)
obstack_1grow (&stk, delim);
obstack_grow (&stk, prefix, pref_len);
obstack_grow (&stk, aclstring, move);
pos += move + 1;
aclstring += move + 1;
}
obstack_1grow (&stk, '\0');
fputs (obstack_finish (&stk), stdlis);
obstack_free (&stk, NULL);
}
void
xattrs_acls_get (MAYBE_UNUSED int parentfd, MAYBE_UNUSED char const *file_name,
MAYBE_UNUSED struct tar_stat_info *st,
MAYBE_UNUSED bool xisfile)
{
if (acls_option > 0)
{
#ifndef HAVE_POSIX_ACLS
static bool done;
if (!done)
{
done = true;
paxwarn (0, _("POSIX ACL support is not available"));
}
#else
int err = file_has_acl_at (parentfd, file_name, &st->stat);
if (err == 0)
return;
if (err < 0)
{
call_arg_warn ("file_has_acl_at", file_name);
return;
}
xattrs__acls_get_a (parentfd, file_name,
&st->acls_a_ptr, &st->acls_a_len);
if (!xisfile)
xattrs__acls_get_d (parentfd, file_name,
&st->acls_d_ptr, &st->acls_d_len);
#endif
}
}
void
xattrs_acls_set (MAYBE_UNUSED struct tar_stat_info const *st,
MAYBE_UNUSED char const *file_name, char typeflag)
{
if (acls_option > 0 && typeflag != SYMTYPE)
{
#ifndef HAVE_POSIX_ACLS
static bool done;
if (!done)
{
done = true;
paxwarn (0, _("POSIX ACL support is not available"));
}
#else
xattrs__acls_set (st, file_name, ACL_TYPE_ACCESS,
st->acls_a_ptr, false);
if (typeflag == DIRTYPE || typeflag == GNUTYPE_DUMPDIR)
xattrs__acls_set (st, file_name, ACL_TYPE_DEFAULT,
st->acls_d_ptr, true);
#endif
}
}
static void
mask_map_realloc (struct xattrs_mask_map *map)
{
if (map->used == map->size)
map->masks = xpalloc (map->masks, &map->size, 1, -1, sizeof *map->masks);
}
void
xattrs_mask_add (const char *mask, bool incl)
{
struct xattrs_mask_map *mask_map =
incl ? &xattrs_setup.incl : &xattrs_setup.excl;
/* ensure there is enough space */
mask_map_realloc (mask_map);
/* just assign pointers -- we silently expect that pointer "mask" is valid
through the whole program (pointer to argv array) */
mask_map->masks[mask_map->used++] = mask;
}
static bool xattrs_masked_out (const char *kw, bool archiving);
/* get xattrs from file given by FILE_NAME or FD (when non-zero)
xattrs are checked against the user supplied include/exclude mask
if no mask is given this includes all the user.*, security.*, system.*,
etc. available domains */
void
xattrs_xattrs_get (int parentfd, char const *file_name,
struct tar_stat_info *st, int fd)
{
if (xattrs_option)
{
#ifndef HAVE_XATTRS
static bool done;
if (!done)
{
done = true;
paxwarn (0, _("XATTR support is not available"));
}
#else
static idx_t xsz = 1024 / 2 * 3;
static char *xatrs = NULL;
ssize_t xret;
while (!xatrs
|| (((xret = (fd == 0
? listxattrat (parentfd, file_name, xatrs, xsz)
: flistxattr (fd, xatrs, xsz)))
< 0)
&& errno == ERANGE))
{
xatrs = xpalloc (xatrs, &xsz, 1, -1, sizeof *xatrs);
}
if (xret < 0)
call_arg_warn ((fd == 0) ? "llistxattrat" : "flistxattr", file_name);
else
{
const char *attr = xatrs;
static idx_t asz = 1024 / 2 * 3;
static char *val = NULL;
while (xret > 0)
{
idx_t len = strlen (attr);
ssize_t aret = 0;
while (!val
|| (((aret = (fd == 0
? lgetxattrat (parentfd, file_name, attr,
val, asz)
: fgetxattr (fd, attr, val, asz)))
< 0)
&& errno == ERANGE))
{
val = xpalloc (val, &asz, 1, -1, sizeof *val);
}
if (0 <= aret)
{
if (!xattrs_masked_out (attr, true))
xheader_xattr_add (st, attr, val, aret);
}
else if (errno != ENOATTR)
call_arg_warn ((fd == 0) ? "lgetxattrat"
: "fgetxattr", file_name);
attr += len + 1;
xret -= len + 1;
}
}
#endif
}
}
#ifdef HAVE_XATTRS
static void
xattrs__fd_set (char const *file_name, char typeflag,
const char *attr, const char *ptr, idx_t len)
{
if (ptr)
{
const char *sysname = "setxattrat";
int ret;
if (typeflag != SYMTYPE)
ret = setxattrat (chdir_fd, file_name, attr, ptr, len, 0);
else
{
sysname = "lsetxattr";
ret = lsetxattrat (chdir_fd, file_name, attr, ptr, len, 0);
}
if (ret < 0)
warnopt (WARN_XATTR_WRITE, errno,
_("%s: Cannot set '%s' extended attribute for file '%s'"),
sysname, attr, file_name);
}
}
#endif
/* lgetfileconat is called against FILE_NAME iff the FD parameter is set to
zero, otherwise the fgetfileconat is used against correct file descriptor */
void
xattrs_selinux_get (MAYBE_UNUSED int parentfd, MAYBE_UNUSED char const *file_name,
MAYBE_UNUSED struct tar_stat_info *st, MAYBE_UNUSED int fd)
{
if (selinux_context_option > 0)
{
#if HAVE_SELINUX_SELINUX_H != 1
static bool done;
if (!done)
{
done = true;
paxwarn (0, _("SELinux support is not available"));
}
#else
int result = (fd
? fgetfilecon (fd, &st->cntx_name)
: lgetfileconat (parentfd, file_name, &st->cntx_name));
if (result < 0 && errno != ENODATA && errno != ENOTSUP)
call_arg_warn (fd ? "fgetfilecon" : "lgetfileconat", file_name);
#endif
}
}
void
xattrs_selinux_set (MAYBE_UNUSED struct tar_stat_info const *st,
MAYBE_UNUSED char const *file_name, MAYBE_UNUSED char typeflag)
{
if (selinux_context_option > 0)
{
#if HAVE_SELINUX_SELINUX_H != 1
static bool done;
if (!done)
{
done = true;
paxwarn (0, _("SELinux support is not available"));
}
#else
const char *sysname = "setfilecon";
int ret;
if (!st->cntx_name)
return;
if (typeflag != SYMTYPE)
{
ret = setfileconat (chdir_fd, file_name, st->cntx_name);
sysname = "setfileconat";
}
else
{
ret = lsetfileconat (chdir_fd, file_name, st->cntx_name);
sysname = "lsetfileconat";
}
if (ret < 0)
warnopt (WARN_XATTR_WRITE, errno,
_("%s: Cannot set SELinux context for file '%s'"),
sysname, file_name);
#endif
}
}
static bool
xattrs_matches_mask (const char *kw, struct xattrs_mask_map *mm)
{
if (!mm->size)
return false;
for (idx_t i = 0; i < mm->used; i++)
if (fnmatch (mm->masks[i], kw, 0) == 0)
return true;
return false;
}
static bool
xattrs_kw_included (const char *kw, bool archiving)
{
static char const USER_DOT_PFX[] = "user.";
if (xattrs_setup.incl.size)
return xattrs_matches_mask (kw, &xattrs_setup.incl);
else if (archiving)
return true;
else
return strncmp (kw, USER_DOT_PFX, sizeof (USER_DOT_PFX) - 1) == 0;
}
static bool
xattrs_kw_excluded (const char *kw)
{
return xattrs_setup.excl.size ?
xattrs_matches_mask (kw, &xattrs_setup.excl) : false;
}
/* Check whether the xattr with keyword KW should be discarded from list of
attributes that are going to be archived/excluded (set ARCHIVING=true for
archiving, false for excluding) */
static bool
xattrs_masked_out (const char *kw, bool archiving)
{
return xattrs_kw_included (kw, archiving) ? xattrs_kw_excluded (kw) : true;
}
void
xattrs_xattrs_set (struct tar_stat_info const *st,
char const *file_name, char typeflag, bool later_run)
{
if (xattrs_option)
{
#ifndef HAVE_XATTRS
static bool done;
if (!done)
{
done = true;
paxwarn (0, _("XATTR support is not available"));
}
#else
if (!st->xattr_map.xm_size)
return;
for (idx_t i = 0; i < st->xattr_map.xm_size; i++)
{
char *keyword = st->xattr_map.xm_map[i].xkey + XATTRS_PREFIX_LEN;
/* TODO: this 'later_run' workaround is temporary solution -> once
capabilities should become fully supported by it's API and there
should exist something like xattrs_capabilities_set() call.
For a regular files: all extended attributes are restored during
the first run except 'security.capability' which is restored in
'later_run == 1'. */
if (typeflag == REGTYPE
&& later_run == (strcmp (keyword, "security.capability") != 0))
continue;
if (xattrs_masked_out (keyword, false /* extracting */ ))
/* we don't want to restore this keyword */
continue;
xattrs__fd_set (file_name, typeflag, keyword,
st->xattr_map.xm_map[i].xval_ptr,
st->xattr_map.xm_map[i].xval_len);
}
#endif
}
}
void
xattrs_print_char (struct tar_stat_info const *st, char *output)
{
if (verbose_option < 2)
{
*output = 0;
return;
}
if (xattrs_option || selinux_context_option > 0 || acls_option > 0)
{
/* placeholders */
*output = ' ';
output[1] = 0;
}
if (xattrs_option && st->xattr_map.xm_size)
for (idx_t i = 0; i < st->xattr_map.xm_size; i++)
{
char *keyword = st->xattr_map.xm_map[i].xkey + XATTRS_PREFIX_LEN;
if (!xattrs_masked_out (keyword, false /* like extracting */ ))
{
*output = '*';
break;
}
}
if (selinux_context_option > 0 && st->cntx_name)
*output = '.';
if (acls_option > 0 && (st->acls_a_len || st->acls_d_len))
*output = '+';
}
void
xattrs_print (struct tar_stat_info const *st)
{
if (verbose_option < 3)
return;
/* selinux */
if (selinux_context_option > 0 && st->cntx_name)
fprintf (stdlis, " s: %s\n", st->cntx_name);
/* acls */
if (acls_option > 0 && (st->acls_a_len || st->acls_d_len))
{
fprintf (stdlis, " a: ");
acls_one_line ("", ',', st->acls_a_ptr, st->acls_a_len);
if (st->acls_a_len && st->acls_d_len)
fprintf (stdlis, ",");
acls_one_line ("default:", ',', st->acls_d_ptr, st->acls_d_len);
fprintf (stdlis, "\n");
}
/* xattrs */
if (xattrs_option && st->xattr_map.xm_size)
{
for (idx_t i = 0; i < st->xattr_map.xm_size; i++)
{
char *keyword = st->xattr_map.xm_map[i].xkey + XATTRS_PREFIX_LEN;
if (!xattrs_masked_out (keyword, false /* like extracting */ ))
fprintf (stdlis, " x: %td %s\n",
st->xattr_map.xm_map[i].xval_len, keyword);
}
}
}

47
src/xattrs.h Normal file
View File

@@ -0,0 +1,47 @@
/* Support for extended attributes.
Copyright (C) 2006-2025 Free Software Foundation, Inc.
This file is part of GNU tar.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Written by James Antill, on 2006-07-27. */
#ifndef GUARD_XATTTRS_H
#define GUARD_XATTTRS_H
/* Add include/exclude fnmatch pattern for xattr key domain. Set INCL parameter
to true/false if you want to add include/exclude pattern */
extern void xattrs_mask_add (const char *mask, bool incl);
extern void xattrs_acls_get (int parentfd, char const *file_name,
struct tar_stat_info *st, bool xisfile);
extern void xattrs_selinux_get (int parentfd, char const *file_name,
struct tar_stat_info *st, int fd);
extern void xattrs_xattrs_get (int parentfd, char const *file_name,
struct tar_stat_info *st, int fd);
extern void xattrs_acls_set (struct tar_stat_info const *st,
char const *file_name, char typeflag);
extern void xattrs_selinux_set (struct tar_stat_info const *st,
char const *file_name, char typeflag);
extern void xattrs_xattrs_set (struct tar_stat_info const *st,
char const *file_name, char typeflag,
bool later_run);
extern void xattrs_print_char (struct tar_stat_info const *st, char *output);
extern void xattrs_print (struct tar_stat_info const *st);
#endif /* GUARD_XATTTRS_H */

File diff suppressed because it is too large Load Diff

5
tests/.gitignore vendored
View File

@@ -8,3 +8,8 @@ argcv.c
argcv.h
genfile.c
genfile
download
ttyemu
checkseekhole
ckmtime
/compress-*.at

View File

@@ -1,29 +1,29 @@
# Makefile for GNU tar regression tests.
# Copyright (C) 1996, 1997, 1999, 2000, 2001, 2003, 2004, 2005,
# 2006, 2007, 2009 Free Software Foundation, Inc.
# Copyright 1996-2025 Free Software Foundation, Inc.
# François Pinard <pinard@iro.umontreal.ca>, 1988.
# Sergey Poznyakoff <gray@mirddin.farlep.net>, 2004.
# This file is part of GNU tar.
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3, or (at your option)
## any later version.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
EXTRA_DIST = $(TESTSUITE_AT) \
testsuite package.m4 star/README star/quicktest.sh \
compress.m4
EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 star/README star/quicktest.sh
DISTCLEANFILES = atconfig $(check_SCRIPTS)
MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE)
CLEANFILES =
## ------------ ##
## package.m4. ##
@@ -45,21 +45,50 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
## Test suite. ##
## ------------ ##
# You can generate the body of this macro with the following shell command:
# LC_ALL=C ls *.at */*.at | sed -e 's/^/ /' -e '$!s/$/\\/'
TESTSUITE_AT = \
T-cd.at\
T-dir00.at\
T-dir01.at\
T-empty.at\
T-mult.at\
T-nest.at\
T-nonl.at\
T-null.at\
testsuite.at\
T-null2.at\
T-rec.at\
T-recurse.at\
T-zfile.at\
acls01.at\
acls02.at\
acls03.at\
add-file.at\
append.at\
append01.at\
append02.at\
append03.at\
append04.at\
append05.at\
backup01.at\
capabs_raw01.at\
checkpoint/defaults.at\
checkpoint/dot-compat.at\
checkpoint/dot-int.at\
checkpoint/dot.at\
checkpoint/interval.at\
chtype.at\
comperr.at\
comprec.at\
delete01.at\
delete02.at\
delete03.at\
delete04.at\
delete05.at\
delete06.at\
difflink.at\
dirrem01.at\
dirrem02.at\
exclude.at\
exclude01.at\
exclude02.at\
@@ -67,6 +96,20 @@ TESTSUITE_AT = \
exclude04.at\
exclude05.at\
exclude06.at\
exclude07.at\
exclude08.at\
exclude09.at\
exclude10.at\
exclude11.at\
exclude12.at\
exclude13.at\
exclude14.at\
exclude15.at\
exclude16.at\
exclude17.at\
exclude18.at\
exclude19.at\
exclude20.at\
extrac01.at\
extrac02.at\
extrac03.at\
@@ -82,19 +125,39 @@ TESTSUITE_AT = \
extrac13.at\
extrac14.at\
extrac15.at\
extrac16.at\
extrac17.at\
extrac18.at\
extrac19.at\
extrac20.at\
extrac21.at\
extrac22.at\
extrac23.at\
extrac24.at\
extrac25.at\
extrac26.at\
extrac27.at\
extrac28.at\
extrac29.at\
extrac30.at\
filerem01.at\
filerem02.at\
gzip.at\
grow.at\
incremental.at\
gzip.at\
ignfail.at\
incr01.at\
incr02.at\
incr03.at\
incr04.at\
incr05.at\
incr06.at\
incr07.at\
incr08.at\
incr09.at\
incr10.at\
incr11.at\
incremental.at\
indexfile.at\
ignfail.at\
label01.at\
label02.at\
label03.at\
@@ -107,11 +170,14 @@ TESTSUITE_AT = \
listed01.at\
listed02.at\
listed03.at\
listed04.at\
listed05.at\
long01.at\
longv7.at\
lustar01.at\
lustar02.at\
lustar03.at\
map.at\
multiv01.at\
multiv02.at\
multiv03.at\
@@ -120,54 +186,124 @@ TESTSUITE_AT = \
multiv06.at\
multiv07.at\
multiv08.at\
multiv09.at\
multiv10.at\
numeric.at\
old.at\
onetop01.at\
onetop02.at\
onetop03.at\
onetop04.at\
onetop05.at\
opcomp01.at\
opcomp02.at\
opcomp03.at\
opcomp04.at\
opcomp05.at\
opcomp06.at\
options.at\
options02.at\
options03.at\
owner.at\
pipe.at\
positional01.at\
positional02.at\
positional03.at\
recurs02.at\
recurse.at\
remfiles01.at\
remfiles02.at\
remfiles03.at\
remfiles04a.at\
remfiles04b.at\
remfiles04c.at\
remfiles05a.at\
remfiles05b.at\
remfiles05c.at\
remfiles06a.at\
remfiles06b.at\
remfiles06c.at\
remfiles07a.at\
remfiles07b.at\
remfiles07c.at\
remfiles08a.at\
remfiles08b.at\
remfiles08c.at\
remfiles09a.at\
remfiles09b.at\
remfiles09c.at\
remfiles10.at\
rename01.at\
rename02.at\
rename03.at\
rename04.at\
rename05.at\
remfiles01.at\
remfiles02.at\
remfiles03.at\
rename06.at\
same-order01.at\
same-order02.at\
selacl01.at\
selnx01.at\
shortfile.at\
shortupd.at\
shortrec.at\
shortupd.at\
sigpipe.at\
skipdir.at\
sparse01.at\
sparse02.at\
sparse03.at\
sparse04.at\
sparse05.at\
sparse06.at\
sparse07.at\
sparsemv.at\
sparsemvp.at\
spmvp00.at\
spmvp01.at\
spmvp10.at\
sptrcreat.at\
sptrdiff00.at\
sptrdiff01.at\
star/gtarfail.at\
star/gtarfail2.at\
star/multi-fail.at\
star/pax-big-10g.at\
star/ustar-big-2g.at\
star/ustar-big-8g.at\
testsuite.at\
time01.at\
time02.at\
truncate.at\
update.at\
update01.at\
update02.at\
update03.at\
update04.at\
verbose.at\
verify.at\
version.at\
volsize.at\
volume.at\
verbose.at\
version.at\
xattr01.at\
xattr02.at\
xattr03.at\
xattr04.at\
xattr05.at\
xattr06.at\
xattr07.at\
xattr08.at\
xform-h.at\
xform01.at\
star/gtarfail.at\
star/gtarfail2.at\
star/multi-fail.at\
star/ustar-big-2g.at\
star/ustar-big-8g.at\
star/pax-big-10g.at
xform02.at\
xform03.at\
xform04.at
distclean-local:
-rm -rf download
TESTSUITE = $(srcdir)/testsuite
AUTOTEST = $(AUTOM4TE) --language=autotest
$(TESTSUITE): package.m4 $(TESTSUITE_AT)
$(TESTSUITE): compress.m4 package.m4 $(TESTSUITE_AT)
$(AUTOTEST) -I $(srcdir) testsuite.at -o $@.tmp
mv $@.tmp $@
@@ -186,7 +322,7 @@ check-full:
#check_SCRIPTS = tar
# Run the test suite on the *installed* tree.
installcheck-local:
installcheck-local: $(check_PROGRAMS)
$(SHELL) $(TESTSUITE) $(TESTSUITEFLAGS) AUTOTEST_PATH=$(exec_prefix)/bin
@@ -194,11 +330,21 @@ installcheck-local:
## genfile ##
## ------------ ##
check_PROGRAMS = genfile
check_PROGRAMS = genfile checkseekhole ckmtime
genfile_SOURCES = genfile.c argcv.c argcv.h
checkseekhole_SOURCES = checkseekhole.c
localedir = $(datadir)/locale
INCLUDES = -I$(top_srcdir)/gnu -I../gnu -I$(top_srcdir)/gnu -I$(top_srcdir)/lib
AM_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\"
LDADD = ../gnu/libgnu.a $(LIBINTL) $(LIB_CLOCK_GETTIME) $(LIB_EACCESS)
AM_CPPFLAGS = \
-I$(top_srcdir)/gnu\
-I../gnu\
-I$(top_srcdir)/gnu\
-I$(top_srcdir)/lib\
-DLOCALEDIR=\"$(localedir)\"
LDADD = ../gnu/libgnu.a\
$(LIB_ACL) $(QCOPY_ACL_LIB) $(CLOCK_TIME_LIB) $(EUIDACCESS_LIBGEN)\
$(GETRANDOM_LIB) $(HARD_LOCALE_LIB) $(FILE_HAS_ACL_LIB) $(MBRTOWC_LIB)\
$(LIB_SELINUX) $(SETLOCALE_NULL_LIB) \
$(LIBINTL) $(LIBICONV)

44
tests/T-cd.at Normal file
View File

@@ -0,0 +1,44 @@
# Process this file with autom4te to create testsuite. -*- Autotest -*-
#
# Test suite for GNU tar.
# Copyright 2013-2025 Free Software Foundation, Inc.
#
# This file is part of GNU tar.
#
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([-C in file lists])
AT_KEYWORDS([files-from T-cd chdir])
AT_TAR_CHECK([
AT_SORT_PREREQ
>file1
mkdir dir
>dir/file2
>dir/file3
AT_DATA([F1],[file1
-C dir
.
])
tar cf archive -T F1
tar tf archive | sort
],
[0],
[./
./file2
./file3
file1
],[],[],[],[ustar])
AT_CLEANUP

46
tests/T-dir00.at Normal file
View File

@@ -0,0 +1,46 @@
# Process this file with autom4te to create testsuite. -*- Autotest -*-
#
# Test suite for GNU tar.
# Copyright 2014-2025 Free Software Foundation, Inc.
# This file is part of GNU tar.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Tar 1.27 and 1.28 did not extract files under directory members listed
# in the file read by --file-from.
#
# Reported-by: Jean-Louis Martineau <martineau@zmanda.com>
# References: <541AE02C.2050008@zmanda.com>,
# http://lists.gnu.org/archive/html/bug-tar/2014-09/msg00006.html
AT_SETUP([recursive extraction from --files-from])
AT_KEYWORDS([files-from extract T-dir T-dir00])
AT_TAR_CHECK([
AT_SORT_PREREQ
mkdir dir
genfile -f dir/file1
genfile -f dir/file2
tar cf archive dir
rm -rf dir
echo dir > list
tar xfTv archive list | sort
],
[0],
[dir/
dir/file1
dir/file2
])
AT_CLEANUP

46
tests/T-dir01.at Normal file
View File

@@ -0,0 +1,46 @@
# Process this file with autom4te to create testsuite. -*- Autotest -*-
#
# Test suite for GNU tar.
# Copyright 2014-2025 Free Software Foundation, Inc.
# This file is part of GNU tar.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Tar 1.27 and 1.28 did not remove trailing slashes from file names
# obtained with the --file-from option.
#
# Reported-by: Jean-Louis Martineau <martineau@zmanda.com>
# References: <541AE02C.2050008@zmanda.com>,
# http://lists.gnu.org/archive/html/bug-tar/2014-09/msg00006.html
AT_SETUP([trailing slash in --files-from])
AT_KEYWORDS([files-from extract T-dir T-dir01])
AT_TAR_CHECK([
AT_SORT_PREREQ
mkdir dir
genfile -f dir/file1
genfile -f dir/file2
tar cf archive dir
rm -rf dir
echo dir/ > list
tar xfTv archive list | sort
],
[0],
[dir/
dir/file1
dir/file2
])
AT_CLEANUP

View File

@@ -1,30 +1,30 @@
# Process this file with autom4te to create testsuite. -*- Autotest -*-
# Test suite for GNU tar.
# Copyright (C) 2006, 2007 Free Software Foundation, Inc.
# Copyright 2006-2025 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# This file is part of GNU tar.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Tar 1.16 coredumped if a filelist file contained empty (zero-length)
# entries
# Reported by: Karl Berry <karl@freefriends.org>
# References: <200610301353.k9UDr1O30680@f7.net>
AT_SETUP([files-from: empty entries])
AT_KEYWORDS([files-from empty])
AT_SETUP([empty entries])
AT_KEYWORDS([files-from empty-line])
AT_DATA([file-list],
[jeden
@@ -34,17 +34,16 @@ trzy
])
AT_TAR_CHECK([
AT_SORT_PREREQ
genfile --file jeden
genfile --file dwa
genfile --file trzy
tar cfvT archive ../file-list | sort
tar cfvT archive ../file-list
],
[0],
[dwa
jeden
[jeden
dwa
trzy
],
[],[],[],[ustar]) # Testing one format is enough

46
tests/T-mult.at Normal file
View File

@@ -0,0 +1,46 @@
# Process this file with autom4te to create testsuite. -*- Autotest -*-
#
# Test suite for GNU tar.
# Copyright 2013-2025 Free Software Foundation, Inc.
#
# This file is part of GNU tar.
#
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([multiple file lists])
AT_KEYWORDS([files-from T-mult])
AT_TAR_CHECK([
>file1
>file2
>file3
>file4
AT_DATA([F1],[file1
file2
])
AT_DATA([F2],[file3
file4
])
tar cf archive -T F1 -T F2
tar tf archive
],
[0],
[file1
file2
file3
file4
],[],[],[],[ustar])
AT_CLEANUP

46
tests/T-nest.at Normal file
View File

@@ -0,0 +1,46 @@
# Process this file with autom4te to create testsuite. -*- Autotest -*-
#
# Test suite for GNU tar.
# Copyright 2013-2025 Free Software Foundation, Inc.
#
# This file is part of GNU tar.
#
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([nested file lists])
AT_KEYWORDS([files-from T-nest])
AT_TAR_CHECK([
>file1
>file2
>file3
>file4
AT_DATA([F1],[file1
-T F2
file2
])
AT_DATA([F2],[file3
file4
])
tar cf archive -T F1
tar tf archive
],
[0],
[file1
file3
file4
file2
],[],[],[],[ustar])
AT_CLEANUP

Some files were not shown because too many files have changed in this diff Show More