understand which code paths aren't possible.
This commit eliminates 117 false positive bug reports of the form
"allocate memory; error out if pointer is NULL; use pointer".
where it is used. [1]
Don't leak file descriptors in write_entry_backend if archive_write_header
returns ARCHIVE_FAILED.
Found by: Coverity Prevent [1]
since they are only tested for zero/nonzero; but it's arguably a bad
idea to set a {-1, 0} variable to 1 (as happens in this code).
Found by: Coverity Prevent
In addition to a number of bug fixes and minor changes:
* --numeric-owner (ignore user/group names on create and extract)
* -S (sparsify files on extraction)
* -s (regex filename substitutions)
* Use new libarchive 'linkify' to get correct hardlink handling for
both old and new cpio formats
* Rework 'copy' test to be insensitive to readdir() filename ordering
Most of the credit for this work goes to Joerg Sonnenberger, who
has been duplicating features from NetBSD's 'pax' program.
hardlink table for two reasons: 1. If le->name is set to NULL, the
structure le won't be inserted into the table; 2. Even if le somehow
did manage to get into the table with le->name equal to NULL, we would
die when we dereferenced le->null before we could get to the point of
freeing the entry.
Remove the unnecessary "if (le->name != NULL)" test and just free the
pointer.
Found by: Coverity Prevent
running 'tar ""' would print 'No memory' instead of the correct error
message, 'Must specify one of -c, -r, -t, -u, -x' if malloc is set to
System V mode (malloc(0) == NULL).
(in fact, there has never been any way for it to be NULL, going all the
way back to revision 1.1 of this file), so remove the check and
unconditionally free entry.
Found by: Coverity Prevent
handling to bsdtar. When writing archives (including copying via the
@archive directive) a line is output to stderr indicating what is being
done (adding or copying), the path, and how far through the file we are;
extracting currently does not report progress within each file, but
this is likely to happen eventually.
Discussed with: kientzle
Obtained from: tarsnap
files if the existing file is newer than the archive entry).
Currently if any files are ignored, bsdtar will exit with a non-zero
exit status; this is likely to change in the future, but requires some
API changes in libarchive.
Discussed with: kientzle
Obtained from: tarsnap
* --format can be used with -r or -u
* -o is a synonym for --format=ustar when used with -c, -r, or -u
Also, fix the erroneous sanity check that suppressed --format with -r or -u.
GNU tar changed -l to match SUSv2 a couple of years ago,
so bsdtar no longer needs to pander to this particular GNUism.
Thanks to: Debian maintainers
MFC after: 7 days
* prototypes for optarg/optind on platforms that don't already have them
* Disambiguate version number macros
* Remove unnecessary PACKAGE_NAME macro
* Hook for forthcoming bsdtar test suite
* Sync version number up with the portable distribution
(This does a couple of things that the standard library's strmode()
doesn't; it proved useful in bsdcpio as well, so I pushed it down
into libarchive.)
* Implement --use-compress-program using new libarchive feature.
* Minor portability improvement by adjusting casts used to
print out uids, gids, and device numbers.
Thanks to: Joerg Sonnenberger for the --use-compress-program implementation.
MFC after: 15 days
failed path is one which was specified on the command line.
This is a compromise between the situation prior to revision 1.57
(where a race between tar(1) and rm(1) could cause tar(1) to
spuriously report an error) and the situation after revision 1.57
(where "tar -c /no/such/path" prints a warning but returns with
an exit code of zero).
Inspired by: rafan
MFC after: 1 week
occur on the write side of extracting a file to ARCHIVE_WARN errors
when returning them from archive_read_extract.
In bsdtar: Use the return code from archive_read_data_into_fd and
archive_read_extract to determine whether we should continue trying to
extract an archive after one of the entries fails.
This commit makes extracting a truncated tarball complain once about
the archive being truncated, instead of complaining twice (once when
trying to extract an entry, and once when trying to seek to the next
entry).
Discussed with: kientzle
into separate append_archive and append_archive_filename functions; the first
takes a "struct archive *" as input, while the second takes a filename, opens
the archive, and calls the first.
There should be no changes in behaviour as a result of this commit; it simply
reorganizes code to make more sense. At some point in the future it may be
possible to share code between append_archive and read_archive, but not yet.
Discussed with: kientzle
affecting the return value from bsdtar), since (a) it usually occurs
due to a perfectly innocent (and unavoidable) race condition where a
user deletes a file in the window between bsdtar reading a directory
and attempting to read the file; and (b) aside from printing a warning
message, bsdtar behaves exactly as if the file had been deleted prior
to bsdtar reading its parent directory.
Reviewed by: kientzle
MFC after: 6 days
complaining about lstat(2) failing. It's a bit scary to find the message
tar: /: Cannot stat: No such file or directory
printed while doing a backup.
MFC after: 1 week
better job searching for the bsdtar binary to test and the gtar binary
to use for inter-operability testing. It should now find the built
(but not installed) binary if there is one, then search for an
installed binary in a number of standard locations.
* New test scripts exercise some basic functionality
* Most header inclusions are now protected (portability)
* read.c now relies on security checks in libarchive instead
of trying to do its own (optimization)
* -p now enabled by default for root, add --no-same-permissions
to disable it
* Comments, minor style fixes.
as part of an old configuration shuffle. As a result, although
ACL restore has been working, ACLs haven't been written into archives
for some time. <sigh>
Pointy hat: You know.
MFC after: 3 days
determine if this is a physical dir without an lstat().
While I'm in here, try to clarify the comments around
the _is_dir() and _is_physical_dir() tests.
(as determined by the initial size given to the header).
Libarchive recently changed to correctly return the amount
of data actually consumed in this case, which revealed this
bug in bsdtar.
* Create file if it doesn't exist.
* If archive is "empty", then append to it with pax restricted
* If user specified a format, use that if it's compatible with
the existing format.
forthcoming. This commit also has a number of style(9) fixes and
minor corrections so the code works better with the build system being
used for non-FreeBSD builds.
Many thanks to: Jaakko Heinonen, who proposed a mechanism for extended
attribute support and implemented both the machine-independent portion
and the Linux-specific portion.
(I'm not using GPL, but I still think there are good
ideas in the GNU projects. ;-) Among other things,
this should make it easier for clients of bsdtar to
recognize it automatically:
bsdtar --version | grep bsdtar
chdir(), be sure to undo the effects of the chdir before continuing.
Without this, after hitting a directory with mode 0111 (for example),
tar will get lost, and won't add any yet unvisted files to your
archive. (Or possibly add the wrong files, I suppose...)
Reviewed By: kientzle@
option is undocumented because it does nothing. It does nothing
because bsdtar never needs it. It is accepted because gnutar does
sometimes need it and many scripts use it.
Reported by: Pawel Jakub Dawidek
when list the archive contents, then try to extract selected files
(file selection always works against unedited pathnames). With this change,
-t always shows the pathnames as they appear in the archive.
Thanks to: Robert Watson
This causes attempts to update a non-existent file to report
an actual error instead of triggering an assertion failure.
PR: bin/87911
Thanks to: roemer.ulrich
MFC after: 3 days
Note: This does not entirely fix bin/87911. I need to decide on
the "correct" response when someone tries to update a non-existent
archive file.
set up before it is called, so move the progname initialization before
the first possible call to bsdtar_warnc().
Thanks to: Stanislav Sedov
PR: bin/83366
MFC after: 7 days
(combine with existing seconds-based), treat '-' as punctuation rather
than a negative number indicator (eliminates several special cases),
use a single list of special words instead of several separate lists,
use table-driven abbreviation logic (eliminate duplicate word entries
and special-case abbreviation and plural handling). The result is
shorter, simpler (judging from comments, earlier maintainers didn't
understand the special handling for "negative years"), handles more
cases (e.g., "tu" is now a recognized abbreviation for "tuesday",
"3rd" is now equivalent to "third") and it has 2 fewer shift/reduce
conflicts.
particular, acl support is no longer enabled on FreeBSD 4, acl support
should be correctly enabled on Linux, dirent.d_namlen should be
correctly detected on platforms that support it.
Thanks to: Greg Lewis, Juergen Lock, and Jaakko Heinonen
extraction and creation. While I'm here, fix a bug reported by Garrett
Wollman: when stripping the leading '/' from the path "/", don't produce
an entry with an empty name; produce "." instead.
Also, reduce the WARNS level to 5 since different build environments
end up using different Yacc skeletons. The BSD one does not
predeclare yyparse, the FSF one does, so it's not really possible to
consistently enforce both -Wmissing-prototypes and -Wredundant-decls.
switches to support selecting files by time of modification.
Special thanks to: Steven M. Bellovin, Rich $alz, and Jim Berets,
authors of the public-domain getdate.y date-parsing code.
source code. Include configure logic to pick up the
system one when it exists and use the fallback version
when it doesn't exist. Set the default for FreeBSD
to use the system version.
With this, bsdtar should now be quite portable.
In particular:
-W excl=text
fails because "excl" is a prefix of both "exclude" and "exclude-from". But,
-W exclude=text
is okay because it matches "exclude" exactly.
Thanks to: Jose F Nieves
MFC after: 7 days
synonym for --format. Update the man page to reflect this. While
I'm here, change the man page to document "tar" rather than "bsdtar,"
update some comments about -l compatibility and fix a few grammar nits.
throw out the whole thing and stop tracking links entirely. That will
break all remaining hardlinks, but should free up enough memory to
let everything finish.
For -l, upset everyone by breaking it. Specifically, -l now produces
a lengthy error message that suggests --check-links (POSIX -l) or
--one-file-system (GNU -l) instead. However, if POSIXLY_CORRECT is set,
use the POSIX interpretation.
For -o, please everyone by making it work both ways:
* -xo uses POSIX behavior
* -co uses "almost GNU" behavior (as close as we can get until
libarchive implements a true V7 tar format)
of course, but I make an effort to accomodate GNU tar scripts that
use -o with -c (with a meaning that totally contradicts SUSv2) by
only issuing a benign warning message in that case.
* Don't change the umask; the library now ignores the umask if
you set EXTRACT_PERM
* Set the EXTRACT_ACL and EXTRACT_FFLAGS bits (used to be
controlled by EXTRACT_PERM).
* Add --null option (sort #defines here)
* Add process_lines function to util.c that reads newline-terminated
or null-terminated lines (with self-sizing buffers, etc) and iteratively
invokes a provided function. Use this to dramatically simplify:
-T handling for -c, --exclude-from-file, and --include-from-file.
* Add -T handling to -x (via include_from_file)
Hopefully, this will fix the openoffice port and a couple of
others that rely on -T and --null.
Instead, display a warning, clean up, and let main() return the error.
In particular, this means that chdir() problems won't leave broken
archives, though they will prompt an error exit value.
This requires some non-trivial surgery to the options parsing.
While here, let people who only have getopt() access long options
through the -W longopt=value convention.
* Usage goes to stderr, not stdout
* Use correct argument markup
* bsdtar --help no longer exits with an error return code
* ensure that the word "bsdtar" appears in the first
line output from "bsdtar --help" (even if the program is
invoked as "tar")
In particular, scripts can now test for the presence of bsdtar.
For example, in /bin/sh:
if (tar --help 2>&1 | grep bsdtar >/dev/null 2>&1) then \
echo bsdtar; else echo not bsdtar; fi
an existing symlink (as might happen if you extract an archive twice).
Also, if we remove the offending link, then we've removed the problem
and can safely go forward with the extraction.
Pointed out by: print/adobe-cmaps port (whose distfile has
duplicate entries for the same symlinks)
Thanks to: Kris Kennaway (for using ports as a testbed for bsdtar)
--exclude='pattern'.
I should have added this a long time ago, since it's so useful for testing.
In particular, it allows me to select a few entries from a troublesome
archive so that I can easily focus my debugging efforts:
bsdtar -czf new.tgz --include='*foo*' @old.tgz