Update to vendor revision 3982

Obtained from:	http://libarchive.googlecode.com/svn/release/2.8
This commit is contained in:
Martin Matuska 2011-12-26 22:25:58 +00:00
parent 4b16b4e80e
commit 7691a6970b
37 changed files with 558 additions and 270 deletions

View File

@ -857,12 +857,6 @@ INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/libarchive)
IF(MSVC)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
ENDIF(MSVC)
# Especially for early development, we want to be a little
# aggressive about diagnosing build problems; this can get
# relaxed somewhat in final shipping versions.
IF ("CMAKE_C_COMPILER_ID" MATCHES "^GNU$")
ADD_DEFINITIONS(-Wall -Werror)
ENDIF ("CMAKE_C_COMPILER_ID" MATCHES "^GNU$")
IF(ENABLE_TEST)
ADD_CUSTOM_TARGET(run_all_tests)

View File

@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd December 21, 2007
.Dd September 5, 2010
.Dt BSDCPIO 1
.Os
.Sh NAME
@ -140,7 +140,7 @@ The POSIX.1 tar format.
The default format is
.Ar odc .
See
.Xr libarchive_formats 5
.Xr libarchive-formats 5
for more complete information about the
formats currently supported by the underlying
.Xr libarchive 3
@ -295,7 +295,7 @@ for more information.
.Sh EXAMPLES
The
.Nm
command is traditionally used to copy file heirarchies in conjunction
command is traditionally used to copy file hierarchies in conjunction
with the
.Xr find 1
command.

View File

@ -285,6 +285,8 @@ cpio_getopt(struct cpio *cpio)
* A period can be used instead of the colon.
*
* Sets uid/gid return as appropriate, -1 indicates uid/gid not specified.
* TODO: If the spec uses uname/gname, then return those to the caller
* as well. If the spec provides uid/gid, just return names as NULL.
*
* Returns NULL if no error, otherwise returns error string for display.
*

View File

@ -273,15 +273,21 @@ main(int argc, char *argv[])
cpio->quiet = 1;
break;
case 'R': /* GNU cpio, also --owner */
/* TODO: owner_parse should return uname/gname
* also; use that to set [ug]name_override. */
errmsg = owner_parse(cpio->optarg, &uid, &gid);
if (errmsg) {
lafe_warnc(-1, "%s", errmsg);
usage();
}
if (uid != -1)
if (uid != -1) {
cpio->uid_override = uid;
if (gid != -1)
cpio->uname_override = NULL;
}
if (gid != -1) {
cpio->gid_override = gid;
cpio->gname_override = NULL;
}
break;
case 'r': /* POSIX 1997 */
cpio->option_rename = 1;
@ -575,10 +581,14 @@ file_to_archive(struct cpio *cpio, const char *srcpath)
return (r);
}
if (cpio->uid_override >= 0)
if (cpio->uid_override >= 0) {
archive_entry_set_uid(entry, cpio->uid_override);
if (cpio->gid_override >= 0)
archive_entry_set_uname(entry, cpio->uname_override);
}
if (cpio->gid_override >= 0) {
archive_entry_set_gid(entry, cpio->gid_override);
archive_entry_set_gname(entry, cpio->gname_override);
}
/*
* Generate a destination path for this entry.

View File

@ -68,7 +68,9 @@ struct cpio {
size_t pass_destpath_alloc;
char *pass_destpath;
int uid_override;
char *uname_override;
int gid_override;
char *gname_override;
int day_first; /* true if locale prefers day/mon */
/* If >= 0, then close this when done. */

View File

@ -493,11 +493,10 @@ __LA_DECL void archive_read_extract_set_skip_file(struct archive *,
/* Close the file and release most resources. */
__LA_DECL int archive_read_close(struct archive *);
/* Release all resources and destroy the object. */
/* Note that archive_read_finish will call archive_read_close for you. */
#if ARCHIVE_VERSION_NUMBER < 2000000
/* Erroneously declared to return void in libarchive 1.x */
__LA_DECL void archive_read_finish(struct archive *);
#else
/* Note that archive_read_free will call archive_read_close for you. */
__LA_DECL int archive_read_free(struct archive *);
#if ARCHIVE_VERSION_NUMBER < 4000000
/* Synonym for archive_read_free() for backwards compatibility. */
__LA_DECL int archive_read_finish(struct archive *);
#endif
@ -514,7 +513,7 @@ __LA_DECL int archive_read_finish(struct archive *);
* - archive_write_header to write the header
* - archive_write_data to write the entry data
* 5) archive_write_close to close the output
* 6) archive_write_finish to cleanup the writer and release resources
* 6) archive_write_free to cleanup the writer and release resources
*/
__LA_DECL struct archive *archive_write_new(void);
__LA_DECL int archive_write_set_bytes_per_block(struct archive *,
@ -595,13 +594,12 @@ __LA_DECL __LA_SSIZE_T archive_write_data_block(struct archive *,
#endif
__LA_DECL int archive_write_finish_entry(struct archive *);
__LA_DECL int archive_write_close(struct archive *);
#if ARCHIVE_VERSION_NUMBER < 2000000
/* Return value was incorrect in libarchive 1.x. */
__LA_DECL void archive_write_finish(struct archive *);
#else
/* Libarchive 2.x and later returns an error if this fails. */
/* It can fail if the archive wasn't already closed, in which case
* archive_write_finish() will implicitly call archive_write_close(). */
/* This can fail if the archive wasn't already closed, in which case
* archive_write_free() will implicitly call archive_write_close(). */
__LA_DECL int archive_write_free(struct archive *);
#if ARCHIVE_VERSION_NUMBER < 4000000
/* Synonym for archive_write_free() for backwards compatibility. */
__LA_DECL int archive_write_finish(struct archive *);
#endif
@ -630,7 +628,7 @@ __LA_DECL int archive_write_set_options(struct archive *_a,
* - construct an appropriate struct archive_entry structure
* - archive_write_header to create the file/dir/etc on disk
* - archive_write_data to write the entry data
* 4) archive_write_finish to cleanup the writer and release resources
* 4) archive_write_free to cleanup the writer and release resources
*
* In particular, you can use this in conjunction with archive_read()
* to pull entries out of an archive and create them on disk.

View File

@ -25,7 +25,7 @@
.\" $FreeBSD: src/lib/libarchive/archive_entry.3,v 1.18 2008/05/26 17:00:22 kientzle Exp $
.\"
.Dd May 12, 2008
.Dt archive_entry 3
.Dt ARCHIVE_ENTRY 3
.Os
.Sh NAME
.Nm archive_entry_acl_add_entry ,

View File

@ -58,7 +58,7 @@
struct archive_vtable {
int (*archive_close)(struct archive *);
int (*archive_finish)(struct archive *);
int (*archive_free)(struct archive *);
int (*archive_write_header)(struct archive *,
struct archive_entry *);
int (*archive_write_finish_entry)(struct archive *);

View File

@ -25,7 +25,7 @@
.\" $FreeBSD: head/lib/libarchive/archive_read.3 191595 2009-04-27 20:13:13Z kientzle $
.\"
.Dd April 13, 2009
.Dt archive_read 3
.Dt ARCHIVE_READ 3
.Os
.Sh NAME
.Nm archive_read_new ,
@ -69,7 +69,7 @@
.Nm archive_read_extract2 ,
.Nm archive_read_extract_set_progress_callback ,
.Nm archive_read_close ,
.Nm archive_read_finish
.Nm archive_read_free
.Nd functions for reading streaming archives
.Sh SYNOPSIS
.In archive.h
@ -196,7 +196,7 @@
.Ft int
.Fn archive_read_close "struct archive *"
.Ft int
.Fn archive_read_finish "struct archive *"
.Fn archive_read_free "struct archive *"
.Sh DESCRIPTION
These functions provide a complete API for reading streaming archives.
The general process is to first create the
@ -457,7 +457,7 @@ object and the archive_entry object so that various statistics
can be retrieved for the progress display.
.It Fn archive_read_close
Complete the archive and invoke the close callback.
.It Fn archive_read_finish
.It Fn archive_read_free
Invokes
.Fn archive_read_close
if it was not invoked manually, then release all resources.
@ -600,7 +600,7 @@ list_archive(const char *name)
printf("%s\en",archive_entry_pathname(entry));
archive_read_data_skip(a);
}
archive_read_finish(a);
archive_read_free(a);
free(mydata);
}

View File

@ -60,7 +60,7 @@ static int choose_format(struct archive_read *);
static int cleanup_filters(struct archive_read *);
static struct archive_vtable *archive_read_vtable(void);
static int _archive_read_close(struct archive *);
static int _archive_read_finish(struct archive *);
static int _archive_read_free(struct archive *);
static struct archive_vtable *
archive_read_vtable(void)
@ -69,7 +69,7 @@ archive_read_vtable(void)
static int inited = 0;
if (!inited) {
av.archive_finish = _archive_read_finish;
av.archive_free = _archive_read_free;
av.archive_close = _archive_read_close;
}
return (&av);
@ -779,7 +779,7 @@ cleanup_filters(struct archive_read *a)
* Release memory and other resources.
*/
static int
_archive_read_finish(struct archive *_a)
_archive_read_free(struct archive *_a)
{
struct archive_read *a = (struct archive_read *)_a;
int i;
@ -787,7 +787,7 @@ _archive_read_finish(struct archive *_a)
int r = ARCHIVE_OK;
__archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_ANY,
"archive_read_finish");
"archive_read_free");
if (a->archive.state != ARCHIVE_STATE_CLOSED)
r = archive_read_close(&a->archive);

View File

@ -25,7 +25,7 @@
.\" $FreeBSD: head/lib/libarchive/archive_read_disk.3 190957 2009-04-12 05:04:02Z kientzle $
.\"
.Dd March 10, 2009
.Dt archive_read_disk 3
.Dt ARCHIVE_READ_DISK 3
.Os
.Sh NAME
.Nm archive_read_disk_new ,
@ -39,7 +39,7 @@
.Nm archive_read_disk_set_gname_lookup ,
.Nm archive_read_disk_set_standard_lookup ,
.Nm archive_read_close ,
.Nm archive_read_finish
.Nm archive_read_free
.Nd functions for reading objects from disk
.Sh SYNOPSIS
.In archive.h
@ -81,7 +81,7 @@
.Ft int
.Fn archive_read_close "struct archive *"
.Ft int
.Fn archive_read_finish "struct archive *"
.Fn archive_read_free "struct archive *"
.Sh DESCRIPTION
These functions provide an API for reading information about
objects on disk.
@ -178,9 +178,9 @@ This affects the file ownership fields and ACL values in the
object.
.It Fn archive_read_close
This currently does nothing.
.It Fn archive_write_finish
.It Fn archive_read_free
Invokes
.Fn archive_write_close
.Fn archive_read_close
if it was not invoked manually, then releases all resources.
.El
More information about the
@ -213,7 +213,7 @@ file_to_archive(struct archive *a, const char *name)
while ((bytes_read = read(fd, buff, sizeof(buff))) > 0)
archive_write_data(a, buff, bytes_read);
archive_write_finish_entry(a);
archive_read_finish(ard);
archive_read_free(ard);
archive_entry_free(entry);
}
.Ed
@ -276,7 +276,7 @@ and first appeared in
The
.Nm libarchive
library was written by
.An Tim Kientzle Aq kientzle@freebsd.org .
.An Tim Kientzle Aq kientzle@FreeBSD.org .
.Sh BUGS
The
.Dq standard

View File

@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_disk.c 189429 2009-03-06 04
#include "archive_private.h"
#include "archive_read_disk_private.h"
static int _archive_read_finish(struct archive *);
static int _archive_read_free(struct archive *);
static int _archive_read_close(struct archive *);
static const char *trivial_lookup_gname(void *, gid_t gid);
static const char *trivial_lookup_uname(void *, uid_t uid);
@ -45,7 +45,7 @@ archive_read_disk_vtable(void)
static int inited = 0;
if (!inited) {
av.archive_finish = _archive_read_finish;
av.archive_free = _archive_read_free;
av.archive_close = _archive_read_close;
}
return (&av);
@ -129,7 +129,7 @@ archive_read_disk_new(void)
}
static int
_archive_read_finish(struct archive *_a)
_archive_read_free(struct archive *_a)
{
struct archive_read_disk *a = (struct archive_read_disk *)_a;

View File

@ -173,10 +173,7 @@ archive_read_extract_cleanup(struct archive_read *a)
{
int ret = ARCHIVE_OK;
#if ARCHIVE_API_VERSION > 1
ret =
#endif
archive_write_finish(a->extract->ad);
ret = archive_write_free(a->extract->ad);
free(a->extract);
a->extract = NULL;
return (ret);

View File

@ -42,6 +42,10 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_cpio.c 20116
#include "archive_private.h"
#include "archive_read_private.h"
#ifdef _MSC_VER
#define __packed
#pragma pack(push, 1)
#endif
struct cpio_bin_header {
unsigned char c_magic[2];
unsigned char c_dev[2];
@ -54,7 +58,7 @@ struct cpio_bin_header {
unsigned char c_mtime[4];
unsigned char c_namesize[2];
unsigned char c_filesize[4];
};
} __packed;
struct cpio_odc_header {
char c_magic[6];
@ -68,7 +72,7 @@ struct cpio_odc_header {
char c_mtime[11];
char c_namesize[6];
char c_filesize[11];
};
} __packed;
struct cpio_newc_header {
char c_magic[6];
@ -85,7 +89,12 @@ struct cpio_newc_header {
char c_rdevminor[8];
char c_namesize[8];
char c_crc[8];
};
} __packed;
#ifdef _MSC_VER
#undef __packed
#pragma pack(pop)
#endif
struct links_entry {
struct links_entry *next;

View File

@ -302,8 +302,6 @@ struct file_info {
struct file_info *first;
struct file_info **last;
} rede_files;
/* To check a ininity loop. */
struct file_info *loop_by;
};
struct heap_queue {
@ -1799,26 +1797,82 @@ parse_file_info(struct archive_read *a, struct file_info *parent,
file->re = 0;
parent->subdirs--;
} else if (file->re) {
/* This file's parent is not rr_moved, clear invalid
* "RE" mark. */
if (parent == NULL || parent->rr_moved == 0)
file->re = 0;
else if ((flags & 0x02) == 0) {
file->rr_moved_has_re_only = 0;
file->re = 0;
/*
* Sanity check: file's parent is rr_moved.
*/
if (parent == NULL || parent->rr_moved == 0) {
archive_set_error(&a->archive,
ARCHIVE_ERRNO_MISC,
"Invalid Rockridge RE");
return (NULL);
}
/*
* Sanity check: file does not have "CL" extension.
*/
if (file->cl_offset) {
archive_set_error(&a->archive,
ARCHIVE_ERRNO_MISC,
"Invalid Rockridge RE and CL");
return (NULL);
}
/*
* Sanity check: The file type must be a directory.
*/
if ((flags & 0x02) == 0) {
archive_set_error(&a->archive,
ARCHIVE_ERRNO_MISC,
"Invalid Rockridge RE");
return (NULL);
}
} else if (parent != NULL && parent->rr_moved)
file->rr_moved_has_re_only = 0;
else if (parent != NULL && (flags & 0x02) &&
(parent->re || parent->re_descendant))
file->re_descendant = 1;
if (file->cl_offset != 0) {
if (file->cl_offset) {
struct file_info *p;
if (parent == NULL || parent->parent == NULL) {
archive_set_error(&a->archive,
ARCHIVE_ERRNO_MISC,
"Invalid Rockridge CL");
return (NULL);
}
/*
* Sanity check: The file type must be a regular file.
*/
if ((flags & 0x02) != 0) {
archive_set_error(&a->archive,
ARCHIVE_ERRNO_MISC,
"Invalid Rockridge CL");
return (NULL);
}
parent->subdirs++;
/* Overwrite an offset and a number of this "CL" entry
* to appear before other dirs. "+1" to those is to
* make sure to appear after "RE" entry which this
* "CL" entry should be connected with. */
file->offset = file->number = file->cl_offset + 1;
/*
* Sanity check: cl_offset does not point at its
* the parents or itself.
*/
for (p = parent; p; p = p->parent) {
if (p->offset == file->cl_offset) {
archive_set_error(&a->archive,
ARCHIVE_ERRNO_MISC,
"Invalid Rockridge CL");
return (NULL);
}
}
if (file->cl_offset == file->offset ||
parent->rr_moved) {
archive_set_error(&a->archive,
ARCHIVE_ERRNO_MISC,
"Invalid Rockridge CL");
return (NULL);
}
}
}
@ -1922,6 +1976,13 @@ parse_rockridge(struct archive_read *a, struct file_info *file,
*/
break;
}
if (p[0] == 'P' && p[1] == 'L') {
/*
* PL extension won't appear;
* contents are always ignored.
*/
break;
}
if (p[0] == 'P' && p[1] == 'N') {
if (version == 1 && data_length == 16) {
file->rdev = toi(data,4);
@ -2697,15 +2758,12 @@ rede_add_entry(struct file_info *file)
{
struct file_info *re;
/*
* Find "RE" entry.
*/
re = file->parent;
while (re != NULL && !re->re) {
/* Sanity check to prevent a infinity loop
* cause by a currupted iso file. */
if (re->loop_by == file)
return (-1);
re->loop_by = file;
while (re != NULL && !re->re)
re = re->parent;
}
if (re == NULL)
return (-1);

View File

@ -128,6 +128,7 @@ static int archive_read_format_zip_read_data(struct archive_read *,
static int archive_read_format_zip_read_data_skip(struct archive_read *a);
static int archive_read_format_zip_read_header(struct archive_read *,
struct archive_entry *);
static int search_next_signature(struct archive_read *);
static int zip_read_data_deflate(struct archive_read *a, const void **buff,
size_t *size, off_t *offset);
static int zip_read_data_none(struct archive_read *a, const void **buff,
@ -317,10 +318,17 @@ archive_read_format_zip_read_header(struct archive_read *a,
signature = (const char *)h;
}
/* If we don't see a PK signature here, scan forward. */
if (signature[0] != 'P' || signature[1] != 'K') {
archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
"Bad ZIP file");
return (ARCHIVE_FATAL);
r = search_next_signature(a);
if (r != ARCHIVE_OK) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
"Bad ZIP file");
return (ARCHIVE_FATAL);
}
if ((h = __archive_read_ahead(a, 4, NULL)) == NULL)
return (ARCHIVE_FATAL);
signature = (const char *)h;
}
/*
@ -374,6 +382,42 @@ archive_read_format_zip_read_header(struct archive_read *a,
return (ARCHIVE_FATAL);
}
static int
search_next_signature(struct archive_read *a)
{
const void *h;
const char *p, *q;
size_t skip;
ssize_t bytes;
int64_t skipped = 0;
for (;;) {
h = __archive_read_ahead(a, 4, &bytes);
if (h == NULL)
return (ARCHIVE_FATAL);
p = h;
q = p + bytes;
while (p + 4 <= q) {
if (p[0] == 'P' && p[1] == 'K') {
if ((p[2] == '\001' && p[3] == '\002')
|| (p[2] == '\003' && p[3] == '\004')
|| (p[2] == '\005' && p[3] == '\006')
|| (p[2] == '\007' && p[3] == '\010')
|| (p[2] == '0' && p[3] == '0')) {
skip = p - (const char *)h;
__archive_read_consume(a, skip);
return (ARCHIVE_OK);
}
}
++p;
}
skip = p - (const char *)h;
__archive_read_consume(a, skip);
skipped += skip;
}
}
static int
zip_read_file_header(struct archive_read *a, struct archive_entry *entry,
struct zip *zip)
@ -888,6 +932,9 @@ process_extra(const void* extra, struct zip* zip)
if (datasize >= 4)
zip->gid = archive_le16dec(p + offset + 2);
break;
case 0x7875:
/* Info-Zip Unix Extra Field (type 3) "ux". */
break;
default:
break;
}

View File

@ -25,7 +25,7 @@
.\" $FreeBSD: head/lib/libarchive/archive_util.3 201098 2009-12-28 02:58:14Z kientzle $
.\"
.Dd January 8, 2005
.Dt archive_util 3
.Dt ARCHIVE_UTIL 3
.Os
.Sh NAME
.Nm archive_clear_error ,

View File

@ -42,26 +42,35 @@ archive_read_close(struct archive *a)
return ((a->vtable->archive_close)(a));
}
#if ARCHIVE_API_VERSION > 1
int
archive_write_free(struct archive *a)
{
return ((a->vtable->archive_free)(a));
}
#if ARCHIVE_VERSION_NUMBER < 4000000
/* For backwards compatibility; will be removed with libarchive 4.0. */
int
archive_write_finish(struct archive *a)
{
return ((a->vtable->archive_finish)(a));
}
#else
/* Temporarily allow library to compile with either 1.x or 2.0 API. */
void
archive_write_finish(struct archive *a)
{
(void)(a->vtable->archive_finish)(a);
return ((a->vtable->archive_free)(a));
}
#endif
int
archive_read_free(struct archive *a)
{
return ((a->vtable->archive_free)(a));
}
#if ARCHIVE_VERSION_NUMBER < 4000000
/* For backwards compatibility; will be removed with libarchive 4.0. */
int
archive_read_finish(struct archive *a)
{
return ((a->vtable->archive_finish)(a));
return ((a->vtable->archive_free)(a));
}
#endif
int
archive_write_header(struct archive *a, struct archive_entry *entry)
@ -76,12 +85,7 @@ archive_write_finish_entry(struct archive *a)
return ((a->vtable->archive_write_finish_entry)(a));
}
#if ARCHIVE_API_VERSION > 1
ssize_t
#else
/* Temporarily allow library to compile with either 1.x or 2.0 API. */
int
#endif
archive_write_data(struct archive *a, const void *buff, size_t s)
{
return ((a->vtable->archive_write_data)(a, buff, s));

View File

@ -25,7 +25,7 @@
.\" $FreeBSD: head/lib/libarchive/archive_write.3 201110 2009-12-28 03:31:29Z kientzle $
.\"
.Dd May 11, 2008
.Dt archive_write 3
.Dt ARCHIVE_WRITE 3
.Os
.Sh NAME
.Nm archive_write_new ,
@ -55,7 +55,7 @@
.Nm archive_write_data ,
.Nm archive_write_finish_entry ,
.Nm archive_write_close ,
.Nm archive_write_finish
.Nm archive_write_free
.Nd functions for creating archives
.Sh SYNOPSIS
.In archive.h
@ -125,7 +125,7 @@
.Ft int
.Fn archive_write_close "struct archive *"
.Ft int
.Fn archive_write_finish "struct archive *"
.Fn archive_write_free "struct archive *"
.Sh DESCRIPTION
These functions provide a complete API for creating streaming
archive files.
@ -363,16 +363,16 @@ and
as needed.
.It Fn archive_write_close
Complete the archive and invoke the close callback.
.It Fn archive_write_finish
.It Fn archive_write_free
Invokes
.Fn archive_write_close
if it was not invoked manually, then releases all resources.
Note that this function was declared to return
.Ft void
in libarchive 1.x, which made it impossible to detect errors when
if necessary, then releases all resources.
If you need detailed information about
.Fn archive_write_close
was invoked implicitly from this function.
This is corrected beginning with libarchive 2.0.
failures, you should be careful to call it separately, as
you cannot obtain error information after
.Fn archive_write_free
returns.
.El
More information about the
.Va struct archive
@ -529,7 +529,7 @@ write_archive(const char *outname, const char **filename)
archive_entry_free(entry);
filename++;
}
archive_write_finish(a);
archive_write_free(a);
}
int main(int argc, const char **argv)
@ -580,7 +580,7 @@ may include
.Fn archive_write_data ,
.Fn archive_write_close ,
or
.Fn archive_write_finish .
.Fn archive_write_free .
The client callback can call
.Fn archive_set_error
to provide values that can then be retrieved by

View File

@ -60,7 +60,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write.c 201099 2009-12-28 03:03:
static struct archive_vtable *archive_write_vtable(void);
static int _archive_write_close(struct archive *);
static int _archive_write_finish(struct archive *);
static int _archive_write_free(struct archive *);
static int _archive_write_header(struct archive *, struct archive_entry *);
static int _archive_write_finish_entry(struct archive *);
static ssize_t _archive_write_data(struct archive *, const void *, size_t);
@ -73,7 +73,7 @@ archive_write_vtable(void)
if (!inited) {
av.archive_close = _archive_write_close;
av.archive_finish = _archive_write_finish;
av.archive_free = _archive_write_free;
av.archive_write_header = _archive_write_header;
av.archive_write_finish_entry = _archive_write_finish_entry;
av.archive_write_data = _archive_write_data;
@ -383,13 +383,13 @@ _archive_write_close(struct archive *_a)
* Destroy the archive structure.
*/
static int
_archive_write_finish(struct archive *_a)
_archive_write_free(struct archive *_a)
{
struct archive_write *a = (struct archive_write *)_a;
int r = ARCHIVE_OK;
__archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
ARCHIVE_STATE_ANY, "archive_write_finish");
ARCHIVE_STATE_ANY, "archive_write_free");
if (a->archive.state != ARCHIVE_STATE_CLOSED)
r = archive_write_close(&a->archive);

View File

@ -25,7 +25,7 @@
.\" $FreeBSD: src/lib/libarchive/archive_write_disk.3,v 1.4 2008/09/04 05:22:00 kientzle Exp $
.\"
.Dd August 5, 2008
.Dt archive_write_disk 3
.Dt ARCHIVE_WRITE_DISK 3
.Os
.Sh NAME
.Nm archive_write_disk_new ,
@ -38,7 +38,7 @@
.Nm archive_write_data ,
.Nm archive_write_finish_entry ,
.Nm archive_write_close ,
.Nm archive_write_finish
.Nm archive_write_free
.Nd functions for creating objects on disk
.Sh SYNOPSIS
.In archive.h
@ -73,7 +73,7 @@
.Ft int
.Fn archive_write_close "struct archive *"
.Ft int
.Fn archive_write_finish "struct archive *"
.Fn archive_write_free "struct archive *"
.Sh DESCRIPTION
These functions provide a complete API for creating objects on
disk from
@ -239,7 +239,7 @@ The
.Nm
library maintains a list of all such deferred attributes and
sets them when this function is invoked.
.It Fn archive_write_finish
.It Fn archive_write_free
Invokes
.Fn archive_write_close
if it was not invoked manually, then releases all resources.
@ -339,7 +339,7 @@ In particular, the directory
.Pa aa
is created as well as the final object
.Pa bb .
In theory, this can be exploited to create an entire directory heirarchy
In theory, this can be exploited to create an entire directory hierarchy
with a single request.
Of course, this does not work if the
.Cm ARCHIVE_EXTRACT_NODOTDOT
@ -371,5 +371,5 @@ compact implementation when appropriate.
.Pp
There should be a corresponding
.Nm archive_read_disk
interface that walks a directory heirarchy and returns archive
interface that walks a directory hierarchy and returns archive
entry objects.

View File

@ -252,7 +252,7 @@ static ssize_t write_data_block(struct archive_write_disk *,
static struct archive_vtable *archive_write_disk_vtable(void);
static int _archive_write_close(struct archive *);
static int _archive_write_finish(struct archive *);
static int _archive_write_free(struct archive *);
static int _archive_write_header(struct archive *, struct archive_entry *);
static int _archive_write_finish_entry(struct archive *);
static ssize_t _archive_write_data(struct archive *, const void *, size_t);
@ -291,7 +291,7 @@ archive_write_disk_vtable(void)
if (!inited) {
av.archive_close = _archive_write_close;
av.archive_finish = _archive_write_finish;
av.archive_free = _archive_write_free;
av.archive_write_header = _archive_write_header;
av.archive_write_finish_entry = _archive_write_finish_entry;
av.archive_write_data = _archive_write_data;
@ -1295,7 +1295,7 @@ _archive_write_close(struct archive *_a)
}
static int
_archive_write_finish(struct archive *_a)
_archive_write_free(struct archive *_a)
{
struct archive_write_disk *a = (struct archive_write_disk *)_a;
int ret;

View File

@ -62,6 +62,11 @@ struct cpio {
size_t ino_list_next;
};
#ifdef _MSC_VER
#define __packed
#pragma pack(push, 1)
#endif
struct cpio_header {
char c_magic[6];
char c_dev[6];
@ -74,7 +79,12 @@ struct cpio_header {
char c_mtime[11];
char c_namesize[6];
char c_filesize[11];
};
} __packed;
#ifdef _MSC_VER
#undef __packed
#pragma pack(pop)
#endif
/*
* Set output format to 'cpio' format.

View File

@ -268,31 +268,6 @@ data, including ACLs and extended attributes, as special
entries in cpio archives.
.Pp
XXX Others? XXX
.Sh BUGS
The
.Dq CRC
format is mis-named, as it uses a simple checksum and
not a cyclic redundancy check.
.Pp
The old binary format is limited to 16 bits for user id,
group id, device, and inode numbers.
It is limited to 4 gigabyte file sizes.
.Pp
The old ASCII format is limited to 18 bits for
the user id, group id, device, and inode numbers.
It is limited to 8 gigabyte file sizes.
.Pp
The new ASCII format is limited to 4 gigabyte file sizes.
.Pp
None of the cpio formats store user or group names,
which are essential when moving files between systems with
dissimilar user or group numbering.
.Pp
Especially when writing older cpio variants, it may be necessary
to map actual device/inode values to synthesized values that
fit the available fields.
With very large filesystems, this may be necessary even for
the newer formats.
.Sh SEE ALSO
.Xr cpio 1 ,
.Xr tar 5
@ -323,3 +298,28 @@ license.
The character format was adopted as part of
.St -p1003.1-88 .
XXX when did "newc" appear? Who invented it? When did HP come out with their variant? When did Sun introduce ACLs and extended attributes? XXX
.Sh BUGS
The
.Dq CRC
format is mis-named, as it uses a simple checksum and
not a cyclic redundancy check.
.Pp
The old binary format is limited to 16 bits for user id,
group id, device, and inode numbers.
It is limited to 4 gigabyte file sizes.
.Pp
The old ASCII format is limited to 18 bits for
the user id, group id, device, and inode numbers.
It is limited to 8 gigabyte file sizes.
.Pp
The new ASCII format is limited to 4 gigabyte file sizes.
.Pp
None of the cpio formats store user or group names,
which are essential when moving files between systems with
dissimilar user or group numbering.
.Pp
Especially when writing older cpio variants, it may be necessary
to map actual device/inode values to synthesized values that
fit the available fields.
With very large filesystems, this may be necessary even for
the newer formats.

View File

@ -25,7 +25,7 @@
.\" $FreeBSD: head/lib/libarchive/libarchive-formats.5 201077 2009-12-28 01:50:23Z kientzle $
.\"
.Dd December 27, 2009
.Dt libarchive-formats 5
.Dt LIBARCHIVE-FORMATS 5
.Os
.Sh NAME
.Nm libarchive-formats

View File

@ -24,7 +24,7 @@
.\"
.\" $FreeBSD: src/lib/libarchive/libarchive.3,v 1.11 2007/01/09 08:05:56 kientzle Exp $
.\"
.Dd August 19, 2006
.Dd July 17, 2010
.Dt LIBARCHIVE 3
.Os
.Sh NAME
@ -61,13 +61,14 @@ GNU-format tar archives,
.It
most common cpio archive formats,
.It
ISO9660 CD images (with or without RockRidge extensions),
ISO9660 CD images (including RockRidge and Joliet extensions),
.It
Zip archives.
.El
The library automatically detects archives compressed with
.Xr gzip 1 ,
.Xr bzip2 1 ,
.Xr xz 1 ,
or
.Xr compress 1
and decompresses them transparently.
@ -87,6 +88,8 @@ archives,
.It
POSIX octet-oriented cpio archives,
.It
Zip archive,
.It
two different variants of shar archives.
.El
Pax interchange format is an extension of the tar archive format that
@ -168,12 +171,12 @@ You can use
(which works much like the
.Xr read 2
system call)
to read this data from the archive.
to read this data from the archive, or
.Fn archive_read_data_block
which provides a slightly more efficient interface.
You may prefer to use the higher-level
.Fn archive_read_data_skip ,
which reads and discards the data for this entry,
.Fn archive_read_data_to_buffer ,
which reads the data into an in-memory buffer,
.Fn archive_read_data_to_file ,
which copies the data to the provided file descriptor, or
.Fn archive_read_extract ,
@ -192,7 +195,7 @@ Once you have finished reading data from the archive, you
should call
.Fn archive_read_close
to close the archive, then call
.Fn archive_read_finish
.Fn archive_read_free
to release all resources, including all memory allocated by the library.
.Pp
The
@ -230,12 +233,34 @@ You can then use
to write the actual data.
.Pp
After all entries have been written, use the
.Fn archive_write_finish
.Fn archive_write_free
function to release all resources.
.Pp
The
.Xr archive_write 3
manual page provides more detailed calling information for this API.
.Sh WRITING ENTRIES TO DISK
The
.Xr archive_write_disk 3
API allows you to write
.Xr archive_entry 3
objects to disk using the same API used by
.Xr archive_write 3 .
The
.Xr archive_write_disk 3
API is used internally by
.Fn archive_read_extract ;
using it directly can provide greater control over how entries
get written to disk.
This API also makes it possible to share code between
archive-to-archive copy and archive-to-disk extraction
operations.
.Sh READING ENTRIES FROM DISK
The
.Xr archive_read_disk 3
provides some support for populating
.Xr archive_entry 3
objects from information in the filesystem.
.Sh DESCRIPTION
Detailed descriptions of each function are provided by the
corresponding manual pages.
@ -259,7 +284,9 @@ In particular, pax interchange format can easily accommodate pathnames
in arbitrary character sets that exceed
.Va PATH_MAX .
.Sh RETURN VALUES
Most functions return zero on success, non-zero on error.
Most functions return
.Cm ARCHIVE_OK
(zero) on success, non-zero on error.
The return value indicates the general severity of the error, ranging
from
.Cm ARCHIVE_WARN ,
@ -329,3 +356,14 @@ stored in an
is supported by all formats.
For example, cpio formats do not support nanosecond timestamps;
old tar formats do not support large device numbers.
.Pp
The
.Xr archive_read_disk 3
API should support iterating over filesystems;
that would make it possible to share code among
disk-to-archive, archive-to-archive, archive-to-disk,
and disk-to-disk operations.
Currently, it only supports reading the
information for a single file.
(Which is still quite useful, as it hides a lot
of system-specific details.)

View File

@ -25,7 +25,7 @@
.\" $FreeBSD: head/lib/libarchive/tar.5 201077 2009-12-28 01:50:23Z kientzle $
.\"
.Dd December 27, 2009
.Dt tar 5
.Dt TAR 5
.Os
.Sh NAME
.Nm tar

View File

@ -220,6 +220,11 @@ DEFINE_TEST(test_acl_freebsd)
skipping("ACL tests require that ACL support be enabled on the filesystem");
return;
}
if (n != 0 && errno == EINVAL) {
close(fd);
skipping("POSIX.1e ACL tests require that POSIX.1e ACL support be enabled on the filesystem");
return;
}
failure("acl_set_fd(): errno = %d (%s)",
errno, strerror(errno));
assertEqualInt(0, n);

View File

@ -71,10 +71,43 @@ test_compat_zip_1(void)
#endif
}
/*
* Verify that we skip junk between entries. The compat_zip_2.zip file
* has several bytes of junk between 'file1' and 'file2'. Such
* junk is routinely introduced by some Zip writers when they manipulate
* existing zip archives.
*/
static void
test_compat_zip_2(void)
{
char name[] = "test_compat_zip_2.zip";
struct archive_entry *ae;
struct archive *a;
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
extract_reference_file(name);
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
/* Read first entry. */
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualString("file1", archive_entry_pathname(ae));
/* Read first entry. */
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualString("file2", archive_entry_pathname(ae));
assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
assertEqualInt(ARCHIVE_OK, archive_read_close(a));
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
}
DEFINE_TEST(test_compat_zip)
{
test_compat_zip_1();
test_compat_zip_2();
}

View File

@ -0,0 +1,10 @@
$FreeBSD$
begin 644 test_compat_zip_2.zip
M4$L#!`H``````'V59CT````````````````%````9FEL93$M2E5.2RU02P,$
M"@``````@95F/<>D!,D&````!@````4```!F:6QE,F9I;&4R"E!+`0(>`PH`
M`````'V59CT````````````````%``````````````"D@0````!F:6QE,5!+
M`0(>`PH``````(&59CW'I`3)!@````8````%``````````````"D@2D```!F
::6QE,E!+!08``````@`"`&8```!2````````
`
end

View File

@ -35,7 +35,7 @@ __FBSDID("$FreeBSD$");
/*
* Check whether a character 'c' is matched by a list specification [...]:
* * Leading '!' negates the class.
* * Leading '!' or '^' negates the class.
* * <char>-<char> is a range of characters
* * \<char> removes any special meaning for <char>
*
@ -60,7 +60,7 @@ pm_list(const char *start, const char *end, const char c, int flags)
(void)flags; /* UNUSED */
/* If this is a negated class, return success for nomatch. */
if (*p == '!' && p < end) {
if ((*p == '!' || *p == '^') && p < end) {
match = 0;
nomatch = 1;
++p;

View File

@ -50,8 +50,8 @@
.Sh DESCRIPTION
.Nm
creates and manipulates streaming archive files.
This implementation can extract from tar, pax, cpio, zip, jar, ar,
and ISO 9660 cdrom images and can create tar, pax, cpio, ar,
This implementation can extract from tar, pax, cpio, zip, jar, ar, xar,
rpm and ISO 9660 cdrom images and can create tar, pax, cpio, ar, zip,
and shar archives.
.Pp
The first synopsis form shows a
@ -67,6 +67,8 @@ is a mode indicator from the following list:
.Bl -tag -compact -width indent
.It Fl c
Create a new archive containing the specified items.
The long option form is
.Fl Fl create .
.It Fl r
Like
.Fl c ,
@ -75,8 +77,12 @@ Note that this only works on uncompressed archives stored in regular files.
The
.Fl f
option is required.
The long option form is
.Fl Fl append .
.It Fl t
List archive contents to stdout.
The long option form is
.Fl Fl list .
.It Fl u
Like
.Fl r ,
@ -86,11 +92,15 @@ Note that this only works on uncompressed archives stored in regular files.
The
.Fl f
option is required.
The long form is
.Fl Fl update .
.It Fl x
Extract to disk from the archive.
If a file with the same name appears more than once in the archive,
each copy will be extracted, with later copies overwriting (replacing)
earlier copies.
The long option form is
.Fl Fl extract .
.El
.Pp
In
@ -127,14 +137,18 @@ In contrast,
.Dl Nm Fl c Fl f Pa - Pa newfile Pa original.tar
creates a new archive with only two entries.
Similarly,
.Dl Nm Fl czf Pa - Fl -format Cm pax Cm @ Ns Pa -
.Dl Nm Fl czf Pa - Fl Fl format Cm pax Cm @ Ns Pa -
reads an archive from standard input (whose format will be determined
automatically) and converts it into a gzip-compressed
pax-format archive on stdout.
In this way,
.Nm
can be used to convert archives from one format to another.
.It Fl b Ar blocksize
.It Fl B , Fl Fl read-full-blocks
Ignored for compatibility with other
.Xr tar 1
implementations.
.It Fl b Ar blocksize , Fl Fl block-size Ar blocksize
Specify the block size, in 512-byte records, for tape drive I/O.
As a rule, this argument is only needed when reading from or writing
to tape drives, and usually not even then as the default block size of
@ -144,21 +158,22 @@ In c and r mode, this changes the directory before adding
the following files.
In x mode, change directories after opening the archive
but before extracting entries from the archive.
.It Fl -check-links
(c and r modes only)
Issue a warning message unless all links to each file are archived.
.It Fl -chroot
.It Fl Fl chroot
(x mode only)
.Fn chroot
to the current directory after processing any
.Fl C
options and before extracting any files.
.It Fl -exclude Ar pattern
.It Fl Fl disable-copyfile
Mac OS X specific.
Disable the use of
.Xr copyfile 3 .
.It Fl Fl exclude Ar pattern
Do not process files or directories that match the
specified pattern.
Note that exclusions take precedence over patterns or filenames
specified on the command line.
.It Fl -format Ar format
.It Fl Fl format Ar format
(c, r, u mode only)
Use the specified format for the created archive.
Supported formats include
@ -172,16 +187,18 @@ Other formats may also be supported; see
for more information about currently-supported formats.
In r and u modes, when extending an existing archive, the format specified
here must be compatible with the format of the existing archive on disk.
.It Fl f Ar file
.It Fl f Ar file , Fl Fl file Ar file
Read the archive from or write the archive to the specified file.
The filename can be
.Pa -
for standard input or standard output.
If not specified, the default tape device will be used.
(On
The default varies by system;
on
.Fx ,
the default tape device is
.Pa /dev/sa0 . )
the default is
.Pa /dev/sa0 ;
on Linux, the default is
.Pa /dev/st0 .
.It Fl Fl gid Ar id
Use the provided group id number.
On extract, this overrides the group id in the archive;
@ -214,25 +231,36 @@ Synonym for
.It Fl I
Synonym for
.Fl T .
.It Fl -include Ar pattern
.It Fl Fl help
Show usage.
.It Fl Fl include Ar pattern
Process only files or directories that match the specified pattern.
Note that exclusions specified with
.Fl -exclude
.Fl Fl exclude
take precedence over inclusions.
If no inclusions are explicitly specified, all entries are processed by
default.
The
.Fl -include
.Fl Fl include
option is especially useful when filtering archives.
For example, the command
.Dl Nm Fl c Fl f Pa new.tar Fl -include='*foo*' Cm @ Ns Pa old.tgz
.Dl Nm Fl c Fl f Pa new.tar Fl Fl include='*foo*' Cm @ Ns Pa old.tgz
creates a new archive
.Pa new.tar
containing only the entries from
.Pa old.tgz
containing the string
.Sq foo .
.It Fl j
.It Fl J , Fl Fl xz
(c mode only)
Compress the resulting archive with
.Xr xz 1 .
In extract or list modes, this option is ignored.
Note that, unlike other
.Nm tar
implementations, this implementation recognizes XZ compression
automatically when reading archives.
.It Fl j , Fl Fl bzip , Fl Fl bzip2 , Fl Fl bunzip2
(c mode only)
Compress the resulting archive with
.Xr bzip2 1 .
@ -241,68 +269,71 @@ Note that, unlike other
.Nm tar
implementations, this implementation recognizes bzip2 compression
automatically when reading archives.
.It Fl k
.It Fl k , Fl Fl keep-old-files
(x mode only)
Do not overwrite existing files.
In particular, if a file appears more than once in an archive,
later copies will not overwrite earlier copies.
.It Fl -keep-newer-files
.It Fl Fl keep-newer-files
(x mode only)
Do not overwrite existing files that are newer than the
versions appearing in the archive being extracted.
.It Fl L
.It Fl L , Fl Fl dereference
(c and r mode only)
All symbolic links will be followed.
Normally, symbolic links are archived as such.
With this option, the target of the link will be archived instead.
.It Fl l
This is a synonym for the
.Fl -check-links
option.
.It Fl m
.It Fl l , Fl Fl check-links
(c and r modes only)
Issue a warning message unless all links to each file are archived.
.It Fl Fl lzma
(c mode only) Compress the resulting archive with the original LZMA algorithm.
Use of this option is discouraged and new archives should be created with
.Fl Fl xz
instead.
Note that, unlike other
.Nm tar
implementations, this implementation recognizes LZMA compression
automatically when reading archives.
.It Fl m , Fl Fl modification-time
(x mode only)
Do not extract modification time.
By default, the modification time is set to the time stored in the archive.
.It Fl n
.It Fl n , Fl Fl norecurse , Fl Fl no-recursion
(c, r, u modes only)
Do not recursively archive the contents of directories.
.It Fl -newer Ar date
.It Fl Fl newer Ar date
(c, r, u modes only)
Only include files and directories newer than the specified date.
This compares ctime entries.
.It Fl -newer-mtime Ar date
.It Fl Fl newer-mtime Ar date
(c, r, u modes only)
Like
.Fl -newer ,
.Fl Fl newer ,
except it compares mtime entries instead of ctime entries.
.It Fl -newer-than Pa file
.It Fl Fl newer-than Pa file
(c, r, u modes only)
Only include files and directories newer than the specified file.
This compares ctime entries.
.It Fl -newer-mtime-than Pa file
.It Fl Fl newer-mtime-than Pa file
(c, r, u modes only)
Like
.Fl -newer-than ,
.Fl Fl newer-than ,
except it compares mtime entries instead of ctime entries.
.It Fl -nodump
.It Fl Fl nodump
(c and r modes only)
Honor the nodump file flag by skipping this file.
.It Fl -null
.It Fl Fl null
(use with
.Fl I ,
.Fl T ,
.Fl I
or
.Fl X )
.Fl T )
Filenames or patterns are separated by null characters,
not by newlines.
This is often used to read filenames output by the
.Fl print0
option to
.Xr find 1 .
.It Fl -numeric-owner
(x mode only)
Ignore symbolic user and group names when restoring archives to disk,
only numeric uid and gid values will be obeyed.
.It Fl Fl no-same-owner
(x mode only)
Do not extract owner and group IDs.
@ -330,7 +361,7 @@ On extract, it causes user and group names in the archive
to be ignored in favor of the numeric user and group ids.
On create, it causes user and group names to not be stored
in the archive.
.It Fl O
.It Fl O , Fl Fl to-stdout
(x, t modes only)
In extract (-x) mode, files will be written to standard out rather than
being extracted to disk.
@ -349,11 +380,11 @@ the archive will be discarded.
.It Fl o
(c, r, u mode)
A synonym for
.Fl -format Ar ustar
.It Fl -one-file-system
.Fl Fl format Ar ustar
.It Fl Fl one-file-system
(c, r, and u modes)
Do not cross mount points.
.It Fl -options Ar options
.It Fl Fl options Ar options
Select optional behaviors for particular modules.
The argument is a text string containing comma-separated
keywords and values.
@ -424,7 +455,7 @@ Supported values are store (uncompressed) and deflate (gzip algorithm).
.El
If a provided option is not supported by any module, that
is a fatal error.
.It Fl P
.It Fl P , Fl Fl absolute-paths
Preserve pathnames.
By default, absolute pathnames (those that begin with a /
character) have the leading slash removed both when creating archives
@ -435,21 +466,22 @@ will refuse to extract archive entries whose pathnames contain
.Pa ..
or whose target directory would be altered by a symlink.
This option suppresses these behaviors.
.It Fl p
.It Fl p , Fl Fl insecure , Fl Fl preserve-permissions
(x mode only)
Preserve file permissions.
Attempt to restore the full permissions, including owner, file modes, file
flags and ACLs, if available, for each item extracted from the archive.
By default, newly-created files are owned by the user running
.Nm ,
the file mode is restored for newly-created regular files, and
all other types of entries receive default permissions.
If
This is the default, if
.Nm
is being run by root, the default is to restore the owner unless the
.Fl o
option is also specified.
.It Fl q ( Fl -fast-read )
is being run by root and can be overriden by also specifying
.Fl Fl no-same-owner
and
.Fl Fl no-same-permissions .
.It Fl Fl posix
(c, r, u mode only)
Synonym for
.Fl Fl format Ar pax
.It Fl q , Fl Fl fast-read
(x and t mode only)
Extract or list only the first archive entry that matches each pattern
or filename operand.
@ -463,8 +495,16 @@ This option is provided as a performance optimization.
Extract files as sparse files.
For every block on disk, check first if it contains only NULL bytes and seek
over it otherwise.
This works similiar to the conv=sparse option of dd.
.It Fl -strip-components Ar count
This works similar to the conv=sparse option of dd.
.It Fl Fl same-owner
(x mode only)
Extract owner and group IDs.
This is the reverse of
.Fl Fl no-same-owner
and the default behavior if
.Nm
is run as root.
.It Fl Fl strip-components Ar count
(x mode only)
Remove the specified number of leading path elements.
Pathnames with fewer elements will be silently skipped.
@ -496,7 +536,7 @@ of symbolic links.
The optional trailing p specifies that after a successful substitution
the original path name and the new path name should be printed to
standard error.
.It Fl T Ar filename
.It Fl T Ar filename , Fl Fl files-from Ar filename
In x or t mode,
.Nm
will read the list of names to be extracted from
@ -510,20 +550,26 @@ The special name
on a line by itself will cause the current directory to be changed to
the directory specified on the following line.
Names are terminated by newlines unless
.Fl -null
.Fl Fl null
is specified.
Note that
.Fl -null
.Fl Fl null
also disables the special handling of lines containing
.Dq -C .
.It Fl U
.It Fl Fl totals
(c, r, u mode only)
After archiving all files, print a summary to stderr.
.It Fl U , Fl Fl unlink , Fl Fl unlink-first
(x mode only)
Unlink files before creating them.
Without this option,
This can be a minor performance optimization if most files
already exist, but can make things slower if most files
do not already exist.
This flag also causes
.Nm
overwrites existing files, which preserves existing hardlinks.
With this option, existing hardlinks will be broken, as will any
symlink that would affect the location of an extracted file.
to remove intervening directory symlinks instead of
reporting an error.
See the SECURITY section below for more details.
.It Fl Fl uid Ar id
Use the provided user id number and ignore the user
name from the archive.
@ -547,7 +593,7 @@ the name is not verified against the system user database.
Pipe the input (in x or t mode) or the output (in c mode) through
.Pa program
instead of using the builtin compression support.
.It Fl v
.It Fl v , Fl Fl verbose
Produce verbose output.
In create and extract modes,
.Nm
@ -560,18 +606,18 @@ will produce output similar to that of
Additional
.Fl v
options will provide additional detail.
.It Fl -version
.It Fl Fl version
Print version of
.Nm
and
.Nm libarchive ,
and exit.
.It Fl w
.It Fl w , Fl Fl confirmation , Fl Fl interactive
Ask for confirmation for every action.
.It Fl X Ar filename
.It Fl X Ar filename , Fl Fl exclude-from Ar filename
Read a list of exclusion patterns from the specified file.
See
.Fl -exclude
.Fl Fl exclude
for more information about the handling of exclusions.
.It Fl y
(c mode only)
@ -582,16 +628,7 @@ Note that, unlike other
.Nm tar
implementations, this implementation recognizes bzip2 compression
automatically when reading archives.
.It Fl z
(c mode only)
Compress the resulting archive with
.Xr gzip 1 .
In extract or list modes, this option is ignored.
Note that, unlike other
.Nm tar
implementations, this implementation recognizes gzip compression
automatically when reading archives.
.It Fl Z
.It Fl Z , Fl Fl compress , Fl Fl uncompress
(c mode only)
Compress the resulting archive with
.Xr compress 1 .
@ -600,9 +637,16 @@ Note that, unlike other
.Nm tar
implementations, this implementation recognizes compress compression
automatically when reading archives.
.It Fl z , Fl Fl gunzip , Fl Fl gzip
(c mode only)
Compress the resulting archive with
.Xr gzip 1 .
In extract or list modes, this option is ignored.
Note that, unlike other
.Nm tar
implementations, this implementation recognizes gzip compression
automatically when reading archives.
.El
.Sh EXIT STATUS
.Ex -std
.Sh ENVIRONMENT
The following environment variables affect the execution of
.Nm :
@ -613,25 +657,21 @@ See
.Xr environ 7
for more information.
.It Ev TAPE
The default tape device.
The default device.
The
.Fl f
option overrides this.
Please see the description of the
.Fl f
option above for more details.
.It Ev TZ
The timezone to use when displaying dates.
See
.Xr environ 7
for more information.
.El
.Sh FILES
.Bl -tag -width ".Ev BLOCKSIZE"
.It Pa /dev/sa0
The default tape device, if not overridden by the
.Ev TAPE
environment variable or the
.Fl f
option.
.El
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES
The following creates a new archive
called
@ -694,9 +734,9 @@ permissions, or names that differ from existing data on disk:
.Dl $ tar -cvf output.tar @input.mtree
.Pp
The
.Fl -newer
.Fl Fl newer
and
.Fl -newer-mtime
.Fl Fl newer-mtime
switches accept a variety of common date and time specifications, including
.Dq 12 Mar 2005 7:14:29pm ,
.Dq 2005-03-12 19:14 ,
@ -705,7 +745,7 @@ and
.Dq 19:14 PST May 1 .
.Pp
The
.Fl -options
.Fl Fl options
argument can be used to control various details of archive generation
or reading.
For example, you can generate mtree output which only contains
@ -713,9 +753,9 @@ For example, you can generate mtree output which only contains
and
.Cm uid
keywords:
.Dl Nm Fl cf Pa file.tar Fl -format=mtree Fl -options='!all,type,time,uid' Pa dir
.Dl Nm Fl cf Pa file.tar Fl Fl format=mtree Fl Fl options='!all,type,time,uid' Pa dir
or you can set the compression level used by gzip or xz compression:
.Dl Nm Fl czf Pa file.tar Fl -options='compression-level=9' .
.Dl Nm Fl czf Pa file.tar Fl Fl options='compression-level=9' .
For more details, see the explanation of the
.Fn archive_read_set_options
and
@ -861,6 +901,7 @@ components, or symlinks to other directories.
.Xr mt 1 ,
.Xr pax 1 ,
.Xr shar 1 ,
.Xr xz 1 ,
.Xr libarchive 3 ,
.Xr libarchive-formats 5 ,
.Xr tar 5
@ -870,7 +911,7 @@ in
.St -p1003.1-96
but was dropped from
.St -p1003.1-2001 .
The options used by this implementation were developed by surveying a
The options supported by this implementation were developed by surveying a
number of existing tar implementations as well as the old POSIX specification
for tar and the current POSIX specification for pax.
.Pp
@ -896,6 +937,9 @@ beginning with
This is a complete re-implementation based on the
.Xr libarchive 3
library.
It was first released with
.Fx 5.4
in May, 2005.
.Sh BUGS
This program follows
.St -p1003.1-96
@ -905,7 +949,7 @@ option.
Note that GNU tar prior to version 1.15 treated
.Fl l
as a synonym for the
.Fl -one-file-system
.Fl Fl one-file-system
option.
.Pp
The
@ -983,6 +1027,3 @@ Converting between dissimilar archive formats (such as tar and cpio) using the
convention can cause hard link information to be lost.
(This is a consequence of the incompatible ways that different archive
formats store hardlink information.)
.Pp
There are alternative long options for many of the short options that
are deliberately not documented.

View File

@ -103,6 +103,7 @@ progress_func(void *cookie)
struct archive *a = progress_data->archive;
struct archive_entry *entry = progress_data->entry;
uint64_t comp, uncomp;
int compression;
if (!need_report())
return;
@ -112,9 +113,13 @@ progress_func(void *cookie)
if (a != NULL) {
comp = archive_position_compressed(a);
uncomp = archive_position_uncompressed(a);
if (comp > uncomp)
compression = 0;
else
compression = (int)((uncomp - comp) * 100 / uncomp);
fprintf(stderr,
"In: %s bytes, compression %d%%;",
tar_i64toa(comp), (int)((uncomp - comp) * 100 / uncomp));
tar_i64toa(comp), compression);
fprintf(stderr, " Out: %d files, %s bytes\n",
archive_file_count(a), tar_i64toa(uncomp));
}
@ -214,7 +219,7 @@ read_archive(struct bsdtar *bsdtar, char mode)
}
if (bsdtar->uname)
archive_entry_set_uname(entry, bsdtar->uname);
if (bsdtar->gname >= 0)
if (bsdtar->gname)
archive_entry_set_gname(entry, bsdtar->gname);
/*

View File

@ -44,7 +44,7 @@ DEFINE_TEST(test_option_s)
{
struct stat st;
/* Create a sample file heirarchy. */
/* Create a sample file hierarchy. */
assertMakeDir("in", 0755);
assertMakeDir("in/d1", 0755);
assertEqualInt(0, mkfile("in/d1/foo", "foo"));

View File

@ -401,7 +401,7 @@ tree_next(struct tree *t)
* violation. Just crash now. */
if (t->visit_type == TREE_ERROR_FATAL) {
fprintf(stderr, "Unable to continue traversing"
" directory heirarchy after a fatal error.");
" directory hierarchy after a fatal error.");
abort();
}

View File

@ -226,7 +226,11 @@ yes(const char *fmt, ...)
fflush(stderr);
l = read(2, buff, sizeof(buff) - 1);
if (l <= 0)
if (l < 0) {
fprintf(stderr, "Keyboard read failed\n");
exit(1);
}
if (l == 0)
return (0);
buff[l] = 0;

View File

@ -751,6 +751,9 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
break;
}
if (bsdtar->option_no_subdirs)
descend = 0;
/*
* Are we about to cross to a new filesystem?
*/
@ -763,7 +766,6 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
} else if (descend == 0) {
/* We're not descending, so no need to check. */
} else if (bsdtar->option_dont_traverse_mounts) {
/* User has asked us not to cross mount points. */
descend = 0;
} else {
/* We're prepared to cross a mount point. */
@ -790,8 +792,15 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
* In -u mode, check that the file is newer than what's
* already in the archive; in all modes, obey --newerXXX flags.
*/
if (!new_enough(bsdtar, name, st))
if (!new_enough(bsdtar, name, st)) {
if (!descend)
continue;
if (bsdtar->option_interactive &&
!yes("add '%s'", name))
continue;
tree_descend(tree);
continue;
}
archive_entry_free(entry);
entry = archive_entry_new();
@ -885,8 +894,7 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
!yes("add '%s'", name))
continue;
/* Note: if user vetoes, we won't descend. */
if (descend && !bsdtar->option_no_subdirs)
if (descend)
tree_descend(tree);
/*
@ -936,6 +944,7 @@ write_entry_backend(struct bsdtar *bsdtar, struct archive *a,
const char *pathname = archive_entry_sourcepath(entry);
fd = open(pathname, O_RDONLY | O_BINARY);
if (fd == -1) {
bsdtar->return_value = 1;
if (!bsdtar->verbose)
lafe_warnc(errno,
"%s: could not open file", pathname);
@ -982,15 +991,21 @@ report_write(struct bsdtar *bsdtar, struct archive *a,
struct archive_entry *entry, int64_t progress)
{
uint64_t comp, uncomp;
int compression;
if (bsdtar->verbose)
fprintf(stderr, "\n");
comp = archive_position_compressed(a);
uncomp = archive_position_uncompressed(a);
fprintf(stderr, "In: %d files, %s bytes;",
archive_file_count(a), tar_i64toa(uncomp));
if (comp > uncomp)
compression = 0;
else
compression = (int)((uncomp - comp) * 100 / uncomp);
fprintf(stderr,
" Out: %s bytes, compression %d%%\n",
tar_i64toa(comp), (int)((uncomp - comp) * 100 / uncomp));
tar_i64toa(comp), compression);
/* Can't have two calls to tar_i64toa() pending, so split the output. */
safe_fprintf(stderr, "Current: %s (%s",
archive_entry_pathname(entry),
@ -1031,6 +1046,12 @@ write_file_data(struct bsdtar *bsdtar, struct archive *a,
progress += bytes_written;
bytes_read = read(fd, bsdtar->buff, FILEDATABUFLEN);
}
if (bytes_read < 0) {
lafe_warnc(errno,
"%s: Read error",
archive_entry_pathname(entry));
bsdtar->return_value = 1;
}
return 0;
}