Commit Graph

346 Commits

Author SHA1 Message Date
delphij
b963db4652 Remove unneeded header includes from usr.bin/ except contributed code.
Tested with:	make universe
2009-12-11 23:35:38 +00:00
pjd
811a23dd7d Make sure to use up-to-date libarchive header files from source tree when
compiling tar and not the ones from /usr/include/.

Reviewed by:	kientzle
Approved by:	kientzle
2009-09-07 06:37:44 +00:00
kientzle
392ab3c6f7 Make -lcrypto usage dependent on whether or not we're building with OpenSSL. 2009-04-18 06:03:09 +00:00
kientzle
4e8cb50d8b Merge remaining changes from libarchive.googlecode.com:
* Add xz and lzma compression options
 * Rename --format-options to simply --options
 * Add --same-owner for GNU tar compat
 * Add -lmd and -lcrypto to fix link
 * Documentation
2009-04-17 03:45:15 +00:00
kientzle
f1f2531950 Set options before opening the archive.
Catch and report close-time errors.
2009-04-17 03:40:40 +00:00
kientzle
a88f72ea58 Minor portability improvement in calls to ctype.h macros. 2009-04-17 03:37:09 +00:00
kientzle
1d72251133 Merge from libarchive.googlecode.com: Numerous Windows-specific build tweaks. 2009-04-17 03:36:07 +00:00
kientzle
47f7c87c96 Update version to 2.6.901a to indicate this is synced up with r745 of
libarchive.googlecode.com (except for the lzma/xz support).
2009-03-08 06:20:35 +00:00
kientzle
26f0010266 Merge r492 from libarchive.googlecode.com: First cut at exposing the
new options mechanism to userland.  Documentation pending...
2009-03-08 06:19:28 +00:00
kientzle
ad587d0765 Match a comment to reduce differences with libarchive.googlecode.com. 2009-03-08 06:09:20 +00:00
kientzle
482c4aae45 Merge r709,r710 from libarchive.googlecode.com: More work on
Windows support.
2009-03-08 06:07:35 +00:00
kientzle
fa748c4160 Merge r687-689,691,693-701,720 from libarchive.googlecode.com:
Translate getdate.y into C for portability.  Make the get_date()
function easier to test as well:
 * Have it accept a time_t "now" to use as a reference so that test
   code can verify relative time specifications against known starting
   points.
 * Set up default date after parsing the string so that we
   can use the specified timezone (if any) instead of the local
   default.  Otherwise, local DST makes it almost impossible to
   reliably test time specifications such as "sunday UTC"
2009-03-08 06:03:15 +00:00
kientzle
9ab299b136 Merger r629-631,633-646,648,654,678,681,682 from libarchive.googlecode.com:
Many changes for Windows compatibility.  bsdtar_test now runs successfully
on both POSIX platforms and Windows.
2009-03-08 05:47:21 +00:00
kientzle
f11509af10 Merge r368,496,625,626 from libarchive.googlecode.com: A number of
style and portability tweaks to the test harness.  Most significantly,
don't use getopt().
2009-03-08 05:38:45 +00:00
kientzle
93903defed Merge r622 from libarchive.googlecode.com: Avoid warning on platforms
that lack regex.h.
2009-03-08 05:35:59 +00:00
kientzle
2016bf66ed Merge r552,r559 from libarchive.googlecode.com: High-resolution time
support on Tru64, AIX, and GNU Hurd, thanks to Björn Jacke.
2009-03-08 05:34:20 +00:00
kientzle
65c5348f79 Merge r529 from libarchive.googlecode.com: Fix how we read ext2fs_fs.h
headers on Linux.
2009-03-08 05:28:52 +00:00
kientzle
70eb245d1e Merge r435,r443 from libarchive.googlecode.com: Let the compiler options
determine how to read config.h.
2009-03-08 05:24:37 +00:00
kientzle
a6848f2b2f Merge r283,r423 from libarchive.googlecode.com: Use libarchive's new
archive_read_disk API to pull metadata off of disk.  This
removes a lot of platform-specific knowledge of things like
ACLs, file flags, and extended attributes from bsdtar.
2009-03-08 05:22:50 +00:00
kientzle
4d11395f65 Merge r374 from libarchive.googlecode.com: Stupid typo in open() call. <sigh> 2009-03-08 05:19:36 +00:00
kientzle
3b0a25ce9e Merge r369 from libarchive.googlecode.com: Test -s option. 2009-03-08 05:17:58 +00:00
kientzle
29e37907df Merge r278 from libarchive.googlecode.com: Reduce the number of
patterns tested here from 200 to 170, which seems to be the
most that Cygwin can handle.
2009-03-08 05:14:16 +00:00
kientzle
1050e75e55 Merge r273 from libarchive.googlecode.com: Use open() correctly. 2009-03-08 05:10:51 +00:00
kientzle
1885a77c0e Fix multiple -s options.
MFC after:	7 days
2009-02-08 22:04:17 +00:00
kientzle
3bdbf535c0 When copying file data to the archive, don't write more
than was read.  This seems to have only affected the shar
writer, since other formats proactively truncate output
to the originally-advertised size.

PR:		bin/131244
MFC after:	7 days
2009-02-08 22:02:46 +00:00
kientzle
664c3aeb01 Spell "substitution" correctly.
PR:		bin/128616
Submitted by:	Jaakko Heinonen
Pointy hat:	Tim Kientzle
MFC after:	30 days
2008-12-15 06:00:25 +00:00
kientzle
73b5159ecd bsdtar is synced up with 2.5.903a 2008-12-06 07:38:14 +00:00
kientzle
a57587d2f5 bsdtar always supports long options now, so we can remove
a documentation disclaimer.
2008-12-06 07:37:55 +00:00
kientzle
48226e3cb7 Only use GCC-specific __dead2 marker when building with GCC. 2008-12-06 07:37:14 +00:00
kientzle
3a229bf1d0 When deciding which characters (of a filename, for instance)
are safe to print, try to take into account the current locale.
This iterates over output strings using mbtowc() to identify
multi-byte sequences.  If iswprint() claims the corresponding
wide character is printable, the original bytes are passed
through.  Otherwise, we expand characters into C-style
\-escape sequences.

Submitted by:	Michihiro NAKAJIMA
MFC after:	30 days
2008-11-29 20:06:53 +00:00
kientzle
79862beef3 After visiting a subdirectory, we use chdir("..") or
fchdir() to return back to the parent.  If those fail,
we're just dead in the water.  Add a new error value
TREE_ERROR_FATAL to indicate that directory traversal
cannot continue.  Have write.c honor that by exiting
immediately.

MFC after:	30 days
2008-11-27 05:49:52 +00:00
kientzle
cfaf87c8f3 If we're unable to chdir() to a directory that we know exists,
that should result in a non-zero return value.

In particular, this should address the issue that David Wolfskill
ran into with a somewhat flaky NFS mount resulting in a damaged
archive even though tar returned success.

MFC after:	4 days
2008-11-27 05:14:36 +00:00
kientzle
34001f8d26 Include more detailed explanation of this case, since it's pretty
subtle why it comes out the way it does.  Once you realize that it
depends on the archiving order, it's also important to realize that
filesystem differences aren't going to break this case.  (Some of the
other tests have had to be extensively rewritten to make them
independent of the order in which a particular filesystem returns file
entries.)

(This commit also serves to note the PR number that I accidentally
omitted from the previous commit.)

PR:		bin/128562
MFC after:	30 days
2008-11-10 05:24:13 +00:00
kientzle
19a4817b26 Test --strip-components and fix it to actually work. Jaakko did a
good job writing this test; it exercises a lot of subtle cases.  The
trickiest one is that a hardlink to something that didn't get
extracted should not itself be extracted.  In some sense, this is not
the desired behavior (we'd rather restore the file), but it's the best
you can do in a single-pass restore of a tar archive.

The test here should be extended to exercise cpio and newc formats as
well, since their hardlink models are different, which will lead to
different handling of some of these edge cases.

Submitted by:	Jaakko Heinonen
MFC after:	30 days
2008-11-10 05:04:55 +00:00
kientzle
c1676b587b New command-line parser for bsdtar.
This replaces the getopt()/getopt_long() wrapper, the old-style
argument rewriter and the associated configuration glue with a more
straightforward custom command parser.  In particular, this ensures
that bsdtar will have consistent option parsing on every platform,
regardless of whether the platform supports getopt_long().

MFC after:	30 days
2008-11-08 04:43:24 +00:00
kientzle
b52c677498 When comparing, cast to the larger size, off_t in this case.
Once we know which one is smaller, then we cast to the smaller size.

Thanks to Xin Li (delphij@)
Pointy hat: /me
2008-11-05 06:40:53 +00:00
kientzle
17a8787cc8 Fix compile warnings building on amd64. This is modified slightly
from Jaakko's original patch: I have misgivings about the portability
of the 'z' printf modifier so opted to cast the arguments to (int)
instead.

PR:		bin/128561
Submitted by:	Jaakko Heinonen
MFC after:	30 days
2008-11-05 05:26:11 +00:00
kientzle
a1df7e8332 Clean up flags support just a tad: FreeBSD support depends on
HAVE_STRUCT_STAT_ST_FLAGS, Linux support depends on the
existence of the appropriate ioctl() options.  In particular,
this should fix some nagging compile errors on Linux platforms
that don't have e2fsprogs-devel installed.
2008-09-14 03:49:00 +00:00
kientzle
6d859ef6a5 Test handling of restores relative to symlinks.
In particular:
  * tar -x -P follows symlinks to existing dirs, but not without -P
  * symlinks to files are always replaced
  * broken symlinks are always replaced
2008-09-14 02:16:04 +00:00
kientzle
1168b06701 Minor cleanup of the -q test: Assert that stdout/stderr are empty for each
extraction.
2008-08-22 01:35:08 +00:00
kientzle
0b3866b2b4 Don't clean before running tests. 2008-08-22 01:31:13 +00:00
kientzle
44b73660ee Explain how the test_option_q test works. 2008-08-22 01:26:55 +00:00
kientzle
dff2aaea3a Test for -q (aka --fast-read).
Fix the error uncovered by this test.
2008-08-22 01:22:55 +00:00
kientzle
a348ba0da6 The results for test 2 here are short enough to just be included inline.
There's no need to go through the hassle of having a checked-in uuencoded
reference file for comparison.
2008-08-21 22:28:00 +00:00
kientzle
aeb6db0092 Add some more tests to verify that "./foo" matches "foo" but "/foo" does not. 2008-08-21 07:04:57 +00:00
kientzle
b25650cc12 Always display the unedited pathname in -t output.
I would like to provide a way to preview the effects of pathname edits,
but pattern selection has to happen against the unedited path, so it
seems that we have to show people the unedited path to help in
designing selection patterns.
2008-08-21 06:41:14 +00:00
kientzle
b49301b5cd Better comment the pattern tests; adjust the filenames for the
reference files to match the corresponding source.

MFC after:	3 days
2008-08-20 06:01:53 +00:00
kientzle
adc2f6a5da Fix SVN r181821 by not using FNM_LEADING_DIR where
it shouldn't be used.
2008-08-18 18:13:40 +00:00
kientzle
bcf5f4ae38 Strip leading "./" or ".//" from patterns and filenames
so that "./foo" matches "foo" (and vice versa).

This is related to PR bin/119141.

PR:		bin/119141
MFC after:	4 days
2008-08-18 04:58:54 +00:00
kientzle
7fc341305a Don't strip a leading '/' from a pattern to be matched.
This aligns the pattern-matching behavior with GNU tar
and restores the behavior of bsdtar prior to FreeBSD 6.3.

PR:		bin/117909
MFC after:	3 days
2008-08-17 19:43:45 +00:00
kientzle
393333b2ad Test updates: Handling of patterns on command line, error messages. 2008-08-15 06:12:02 +00:00
cperciva
45f0d08992 Mark functions as __dead2 in order to help the LLVM static checker
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".
2008-08-04 01:25:48 +00:00
simon
704f497080 - Fix mtree example so it works.
- Document --version.

Reviewed by:	kientzle
MFC after:	1 week
2008-07-26 17:22:40 +00:00
cperciva
b63e589760 Move duplicated code from tar_mode_[cru] into archive_write.
Fix a bug I introduced 7 minutes ago: clean up properly from archive_write
if we exit the argv-handling loop due to -C not having an argument.
2008-07-05 08:10:55 +00:00
cperciva
e2615c73e3 Use malloc in write_archive to allocate a 64kB buffer for holding file data
instead of using 64kB of stack space in copy_file_data and write_file_data.
2008-07-05 08:03:08 +00:00
cperciva
fb0369b037 Clean up write_entry by eliminating fd except in the #ifdef __linux block
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]
2008-07-05 06:05:34 +00:00
cperciva
3cb9861929 Revert CVS revision 1.68; it is now possible for entry to be NULL at the end
of write_entry.  (This was perfectly safe, since archive_entry_free(NULL) is
a no-op, but adding the check back makes the style more consistent.)
2008-07-05 02:21:51 +00:00
kientzle
0b80c05eed FreeBSD-CURRENT bsdtar is synched up with libarchive-portable 2.5.5. 2008-07-05 02:09:54 +00:00
kientzle
2d4fd5afbd Remove HAVE_STRUCT_STAT_ST_RDEV, as it's not used anywhere. 2008-07-05 02:09:13 +00:00
kientzle
b6902abe6c Stop using the deprecated linux/ext2_fs.h. 2008-07-05 02:06:55 +00:00
kientzle
a02f400469 Use %H:%M for strftime() time formatting instead of the non-portable %R. 2008-07-05 02:05:55 +00:00
kientzle
97d3a2b6f0 Pass the entry down into the core write loop, so we
can include the filename when reporting errors.

Thanks to: Dan Nelson
2008-06-25 05:01:02 +00:00
kientzle
5e6dd4bfce MfP4: Minor portability fix. 2008-06-15 10:08:16 +00:00
kientzle
a042595dbe MfP4: test harness cleanup. 2008-06-15 10:07:54 +00:00
cperciva
95bad3329f Make one-bit fields unsigned instead of signed. This has no effect,
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
2008-06-09 14:41:28 +00:00
cperciva
02aa7dcfd9 Rework code to avoid using a pointer after freeing it. Aside from the
possibility of memory becoming undereferenceable when it is freed, this
change should have no effect on bsdtar behaviour.

Found by:	Coverity Prevent
2008-06-09 14:03:55 +00:00
kientzle
e2011087ec Compatibility fix: define REG_BASIC if it isn't already. In particular,
glibc has a suitable regex implementation, but doesn't define this
constant.

Thanks to: Diego "Flameeyes" Pettenò
2008-05-27 04:44:07 +00:00
kientzle
0280e5aa49 MFp4: bsdtar 2.5.4b
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.
2008-05-26 17:10:10 +00:00
cperciva
d6da92763e The value le->name cannot be NULL when we're freeing an entry in the
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
2008-05-23 05:07:22 +00:00
cperciva
59f7395e1e Improve portability via s/struct siginfo/struct siginfo_data/. This was
running into a namespace collision on an avian operating system.
2008-05-22 21:08:36 +00:00
cperciva
a806c30ec3 Detect if argv[1] is "" and avoid calling malloc(0). Prior to this commit,
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).
2008-05-19 18:38:01 +00:00
cperciva
ee71b68b4b There's no way for entry to possibly be NULL at the end of write_entry
(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
2008-05-19 18:09:26 +00:00
cperciva
62fbb83958 Add SIGINFO (and for portability to SIGINFO-lacking systems, SIGUSR1)
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
2008-05-18 06:24:47 +00:00
cperciva
c890e8f252 Add --keep-newer-files option (as in GNU tar: When in -x mode, ignore
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
2008-05-17 15:55:29 +00:00
kientzle
3a55c1cdc9 Documentation updates:
* --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.
2008-05-02 05:40:05 +00:00
kientzle
00470f26d3 bsdtar --version should succeed. 2008-05-02 05:18:47 +00:00
kientzle
9d3427eb57 New bsdtar test harness. Still rather skimpy, but a lot easier
to run and maintain than the old scripts that used to be here.
2008-05-02 05:17:16 +00:00
kientzle
8e18686387 Allow -r with -T even if there are no files on the command line.
PR: bin/123246
MFC after: 3 days
2008-05-02 05:14:58 +00:00
kientzle
5b6560526e Fix --fast-read by decrementing the remaining patterns to be matched,
instead of incrementing.

Pointy hat: me
Thanks to: Tomasz Przygoda
MFC after: 3 days
2008-03-18 06:18:49 +00:00
kientzle
bce66ba5f4 style(9) fix to add whitespace around an '=' sign and restore
a comment that got accidentally dropped.
2008-03-15 05:08:21 +00:00
kientzle
2f15379ebc Support NetBSD's --insecure as a synonym for -P. 2008-03-15 03:28:39 +00:00
kientzle
fdbfeedacf Document --chroot. 2008-03-15 03:25:26 +00:00
kientzle
5e0e875a01 Support -q (from NetBSD) as a synonym for --fast-read (the old FreeBSD
extension to GNU tar).

Thanks to: Joerg Sonnenberger
2008-03-15 03:18:24 +00:00
kientzle
9d6da14ce1 Also accept --uncompress as a synonym for -Z.
Thanks to: Joerg Sonnenberger
2008-03-15 03:11:13 +00:00
kientzle
e3d8bdbf55 --chroot implementation thanks to Joerg Sonnenberger. 2008-03-15 03:06:46 +00:00
kientzle
0d1e934945 Support --compress as a synonym for -Z. 2008-03-15 02:45:57 +00:00
kientzle
4d2ae21512 Enable and document the -Z option for selecting "compress" compression,
now that libarchive supports it.
2008-03-15 02:41:44 +00:00
kientzle
328399da2f Allow appending to archives on block devices as well as
archives in regular files, since both are seekable.

Thanks to: Reinoud Zandijk (@netbsd.org)
2008-02-19 05:27:17 +00:00
kientzle
5ca21996e8 Make -l always have the SUSv2 meaning of "check links."
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
2008-01-22 07:23:44 +00:00
kientzle
7926f8421a Remove the old bsdtar test scripts; something much
better is almost ready to commit.
2008-01-02 00:28:44 +00:00
kientzle
6b16e2b440 A couple of miscellaneous fixes:
* 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
2008-01-02 00:27:14 +00:00
kientzle
af2a151201 Fill in the approximate date when tar(1) first appeared. 2008-01-02 00:24:10 +00:00
kientzle
4e518cef81 Include a suitable stub definition of __FBSDID() for non-FreeBSD platforms. 2008-01-02 00:23:00 +00:00
kientzle
9f949d65f6 Use archive_entry_strmode() instead of a local bsdtar_strmode().
(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.)
2008-01-02 00:21:27 +00:00
kientzle
8077de9724 Include Guido's copyright for the fnmatch() code I cribbed from.
(It's in the C source, just wasn't in the COPYING file until now.)
2008-01-02 00:19:49 +00:00
kientzle
8fc160dac0 Add --posix as a synonym for --format=pax, for GNU
tar compatibility.

Approved by: re (bmah)
2007-09-09 00:07:18 +00:00
kientzle
ffbd95e6a7 Fix for PR bin/115033. This corrects a crash when long options
are specified with the "-W option=arg" syntax and the '=' is omitted.

MFC after: 3 days
Approved by: re (rwatson)
2007-08-01 03:15:35 +00:00
kientzle
779bdfcafb Fill in some casts that are needed (according to GCC 4.1)
Thanks to: Joerg Sonnenberger
Approved by: re (hrs)
MFC after: 3 days
2007-07-20 01:27:50 +00:00
kientzle
a6f1d6d2ce Don't exit immediately on libarchive warnings, just
set the delayed return value and keep going.

Approved by: re (hrs)
MFC after: 7 days
2007-07-20 01:24:49 +00:00
kientzle
57eb78da4c bsdtar 2.2.3:
* 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
2007-05-29 05:39:10 +00:00