Commit graph

96 commits

Author SHA1 Message Date
Tim Kientzle 0c1bca0fd2 If the compressed data is larger than the uncompressed,
report the compression ratio as 0% instead of displaying
nonsense triggered by numeric overflow.  This is common
when dealing with uncompressed files when the I/O blocking
causes there to be small transient differences in the
accounting.

Thanks to:  Boris Samorodov
2010-06-14 02:56:45 +00:00
Tim Kientzle f5f9acdd61 Consistently specify O_BINARY when opening files. 2010-04-11 01:32:30 +00:00
Tim Kientzle 3b7dbff339 Merge a bunch of refactoring from Joerg Sonnenberger to
isolate common code used by tar and cpio (and useful to other
libarchive clients).  The functions here are prefixed with
"lafe" (libarchive front-end) to indicate their use.
2010-02-07 02:00:26 +00:00
Tim Kientzle bb2f2a4024 Style & Portability: Use archive_entry methods to examine
file information, change some functions to static, remove
some unused headers.
2010-02-07 01:35:28 +00:00
Tim Kientzle 37ae97d43e Various portability workarounds for non-FreeBSD platforms. 2010-02-07 01:26:45 +00:00
Tim Kientzle 1ce4beea44 Restructure the logic that determines when we're crossing a mount
point.  In particular, this carves out a place for detecting and
excluding synthetic or network filesystems.
2010-02-07 01:22:55 +00:00
Tim Kientzle 2d9fd7eea6 Trim out some unused configuration variables, remove
some unused headers, etc.
2010-02-07 01:07:58 +00:00
Tim Kientzle d180e2b3d4 Fill in some missing error handling, be a little more careful about
error reporting, prefer int64_t to off_t.
2010-02-06 20:41:25 +00:00
Tim Kientzle c92560005d bsdtar doesn't actually know what compression is supported by libarchive
and it should not pretend that it does.  It should just pass along the
user's request and handle an error if it's not supported.
2010-02-06 20:36:14 +00:00
Tim Kientzle 12d4db7c3f Refactor the siginfo/sigusr1 handling. The read/write reporting
is sufficiently different that it was simpler to just put separate
reporting functions into read.c and write.c rather than try to have
a single all-purpose reporting function.
Switch to a custom function for converting int64_t to a string; in
the portable version, this saves a lot of configuration headaches
trying to decipher the platform printf().
2010-02-06 20:27:36 +00:00
Tim Kientzle ae41a0ad92 Diff reduction compared to portable bsdtar 2.8: Move the
program name into a global, which eliminates an extra
argument from a lot of places.
2010-02-06 19:44:37 +00:00
Tim Kientzle 5191e7b552 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
Tim Kientzle abe5b073f4 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
Tim Kientzle 74d5acaf4c 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
Tim Kientzle 709693c65a Merge r529 from libarchive.googlecode.com: Fix how we read ext2fs_fs.h
headers on Linux.
2009-03-08 05:28:52 +00:00
Tim Kientzle 3ae673ed49 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
Tim Kientzle ec9d8e0b01 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
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 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
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 f12440da1e Stop using the deprecated linux/ext2_fs.h. 2008-07-05 02:06: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 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 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
Tim Kientzle a0a88a1e98 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
Tim Kientzle 53f3a9d49f Enable and document the -Z option for selecting "compress" compression,
now that libarchive supports it.
2008-03-15 02:41:44 +00:00
Tim Kientzle 2372ae680f 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
Tim Kientzle a38d1d4c8b 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
Colin Percival c85ac10468 If lstat(2) fails, have bsdtar return a non-zero exit code if the
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
2007-05-03 04:33:11 +00:00
Colin Percival 35c2dd3d05 Clean up error handling in archive_append to match how errors are
handled in write_hierarchy.

Approved by:	kientzle
2007-04-09 08:22:34 +00:00
Colin Percival 0260ab4f4e Split the append_archive function (used for processing @<archive> directives)
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
2007-03-31 10:14:03 +00:00
Colin Percival fa21517ed8 Remove pathlen argument from write_entry function. It has never been used.
Approved by:	kientzle
MFC after:	3 days
2007-03-17 19:18:29 +00:00
Colin Percival 486641fcc5 Fix logic bug; we want to do_chdir if arg doesn't start with / _and_ it
doesn't start with @/ either.

This unbreaks "tar -c -C /no/such/directory @/path/to/archive".

MFC after:	3 days
2007-03-17 16:17:14 +00:00
Colin Percival 5e85b65e97 Don't consider an lstat(2) failure to be an error (in the sense of
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
2007-03-15 10:11:38 +00:00
Colin Percival 4d41b13b4e Reduce the risk of inducing heart attacks, by printing the right path when
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
2007-03-14 07:30:51 +00:00
Tim Kientzle 45d4d7ac8c bsdtar 2.0.23:
* 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.
2007-03-11 10:36:42 +00:00
Tim Kientzle 6bf00d8bc7 Andrew and Colin each pointed out to me that truncating the backup
of a growing file should not be considered a "bad thing."

PR: bin/108990
MFC after: 7 days
Pointy hat: /me
2007-02-18 06:23:57 +00:00
Tim Kientzle effb1b7fcb Correctly handle writes beyond the end of the archive entry
(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.
2007-02-14 08:16:08 +00:00
Tim Kientzle d00914ea85 Update -r handling:
* 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.
2007-02-08 07:25:53 +00:00
Tim Kientzle dbd5adf0d9 Correct the copyright messages: Make this a standard vanilla
2-clause BSD license, update the year to 2007.
2007-01-09 08:12:17 +00:00
Colin Percival 161b2956bb If append_archive fails while writing an archive header, output the error
message from the archive being written (not the message from the archive
being read, where no error has occurred).

MFC after:	3 days
2007-01-05 16:20:21 +00:00
Colin Percival 1b720f2a86 Clean up the struct archive used for reading an archive in the handling
of @archive commands.  This bug should be harmless as long as you don't
use an excessive number of @archive commands.

MFC after:	1 week
2007-01-02 15:03:38 +00:00
Colin Percival d82088b28f Handle errors which occur during archive_write_data and archive_write_close
by printing an error message and exiting with a non-zero status code.

MFC after:	1 week
2007-01-02 12:24:14 +00:00
Tim Kientzle fc1e63e49b Remove two unused variables.
Thanks to: Stefan Farfeleder
2006-07-31 04:57:46 +00:00