Commit Graph

3337 Commits

Author SHA1 Message Date
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