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.
This commit is contained in:
Sergey Poznyakoff
2025-05-06 15:23:03 +03:00
parent bfc3346394
commit 6131dd2805
8 changed files with 131 additions and 45 deletions

View File

@@ -4639,7 +4639,7 @@ The subsections below discuss allowed values for @var{keyword} along with the
warning messages they control.
@menu
* General Warnings:: Keywords applicable for @command{tar --create}.
* General Warnings:: Keywords controlling @command{tar} operation.
* Archive Creation Warnings:: Keywords applicable for @command{tar --create}.
* Archive Extraction Warnings:: Keywords applicable for @command{tar --extract}.
* Incremental Extraction Warnings:: Keywords controlling incremental extraction.
@@ -4670,6 +4670,11 @@ suppressed if @option{--ignore-zeros} is in effect (@pxref{Ignore
Zeros}).
@end defvr
@defvr {warning} empty-transform
@cindex @samp{transforms to empty name}, warning message.
@samp{transforms to empty name}. @xref{transform}.
@end defvr
@defvr {warning} missing-zero-blocks
@cindex @samp{Terminating zero blocks missing}, warning message.
@samp{Terminating zero blocks missing at %s}. This warning is
@@ -8906,7 +8911,9 @@ $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
The option @option{--strip=2} instructs @command{tar} to strip the
two leading components (@file{usr/} and @file{include/}) off the file
name.
name, before extracting it. Notice, that archive members to extract are
searched before that modification, hence the file name is specified in
full.
If you add the @option{--verbose} (@option{-v}) option to the invocation
above, you will note that the verbose listing still contains the
@@ -9022,7 +9029,6 @@ follows the GNU @command{sed} implementation in this regard, so
the interaction is defined to be: ignore matches before the
@var{number}th, and then match and replace all matches from the
@var{number}th on.
@end table
In addition, several @dfn{transformation scope} flags are supported,
@@ -9162,6 +9168,42 @@ $ @kbd{tar -cf arch.tar \
--transform='s,/usr/var,/var/;s,/usr/local,/usr/,'}
@end smallexample
Applying transformations to some file names may produce empty
strings. This may indicate errors in regular expressions, but it may
as well happen during normal operation, for instance, when using
@option{--strip-components} option with a value which is greater then
or equal to the number of directory components in the topmost
directory stored in the archive. Consider the following example. Let
the archive @file{usr.tar} contain:
@example
@group
$ @kbd{tar tf usr.tar}
usr/
usr/local/
...
@end group
@end example
Extracting from this archive with the @option{--strip=1} option will
transform the name of its first entry (@samp{usr/}) to an empty
string. When this happens, @GNUTAR{} prints a warning and skips this
member:
@example
@group
$ @kbd{tar --strip=1 -xf usr.tar}
tar: usr: transforms to empty name
@end group
@end example
If an empty name results from transformations applied when creating or
updating the archive, the warning is output and the file is not
archived.
If this is intended, you can suppress the warning using the
@option{--warning=no-empty-transform} option (@pxref{warnings}).
@node after
@section Operating Only on New Files