Commit Graph

271 Commits

Author SHA1 Message Date
Tim Kientzle
5d42c42369 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
Tim Kientzle
2c2029ada9 bsdtar is synced up with 2.5.903a 2008-12-06 07:38:14 +00:00
Tim Kientzle
286e81aeb0 bsdtar always supports long options now, so we can remove
a documentation disclaimer.
2008-12-06 07:37:55 +00:00
Tim Kientzle
d47cf339f4 Only use GCC-specific __dead2 marker when building with GCC. 2008-12-06 07:37:14 +00:00
Tim Kientzle
5af3583731 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
Tim Kientzle
2f01c75815 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
Tim Kientzle
e4504a7d06 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
Tim Kientzle
8666079cdb 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
Tim Kientzle
c4a52c7226 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
Tim Kientzle
85ae3122e9 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
Tim Kientzle
025b20f6e5 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
Tim Kientzle
f4e24c4e7a 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
Tim Kientzle
8cd2f9bcd0 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
Tim Kientzle
1756b590c9 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
Tim Kientzle
83cb61fa3a Minor cleanup of the -q test: Assert that stdout/stderr are empty for each
extraction.
2008-08-22 01:35:08 +00:00
Tim Kientzle
ca926f6fbd Don't clean before running tests. 2008-08-22 01:31:13 +00:00
Tim Kientzle
ba1a633912 Explain how the test_option_q test works. 2008-08-22 01:26:55 +00:00
Tim Kientzle
3873424684 Test for -q (aka --fast-read).
Fix the error uncovered by this test.
2008-08-22 01:22:55 +00:00
Tim Kientzle
b1feec2392 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
Tim Kientzle
503b743566 Add some more tests to verify that "./foo" matches "foo" but "/foo" does not. 2008-08-21 07:04:57 +00:00
Tim Kientzle
e0e53b4111 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
Tim Kientzle
b14f19cf97 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
Tim Kientzle
651eea9aa8 Fix SVN r181821 by not using FNM_LEADING_DIR where
it shouldn't be used.
2008-08-18 18:13:40 +00:00
Tim Kientzle
0f4b98311a 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
Tim Kientzle
ac2dcb729f 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
Tim Kientzle
8eccad56d9 Test updates: Handling of patterns on command line, error messages. 2008-08-15 06:12:02 +00:00
Colin Percival
f9bcf9cabf 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 L. B. Nielsen
1640935f0b - Fix mtree example so it works.
- Document --version.

Reviewed by:	kientzle
MFC after:	1 week
2008-07-26 17:22:40 +00:00
Colin Percival
a6d7fc3469 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
Colin Percival
d47b2ddb21 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
Colin Percival
85f32b2087 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
Colin Percival
9af6e14a8c 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
Tim Kientzle
6481fd43de FreeBSD-CURRENT bsdtar is synched up with libarchive-portable 2.5.5. 2008-07-05 02:09:54 +00:00
Tim Kientzle
aec34fd22e Remove HAVE_STRUCT_STAT_ST_RDEV, as it's not used anywhere. 2008-07-05 02:09:13 +00:00
Tim Kientzle
f12440da1e Stop using the deprecated linux/ext2_fs.h. 2008-07-05 02:06:55 +00:00
Tim Kientzle
fe8c1d9768 Use %H:%M for strftime() time formatting instead of the non-portable %R. 2008-07-05 02:05:55 +00:00
Tim Kientzle
634d062e6a 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
Tim Kientzle
48ee9a828d MfP4: Minor portability fix. 2008-06-15 10:08:16 +00:00
Tim Kientzle
669a9b2e92 MfP4: test harness cleanup. 2008-06-15 10:07:54 +00:00
Colin Percival
f6dd73207f 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
Colin Percival
af58f6feff 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
Tim Kientzle
aabccf4a0d 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
Tim Kientzle
eb36031906 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
Colin Percival
29d10c76f9 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
Colin Percival
990662f170 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
Colin Percival
2dc4c8e0e5 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
Colin Percival
1eef28bb67 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
Colin Percival
06a047f0f1 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
Colin Percival
54c81d4f92 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
Tim Kientzle
01770c7983 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