Skip to content

Commit

Permalink
Merge branch 'vendor/LIBARCHIVE'
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Avalos committed Jul 11, 2012
2 parents 7f86d36 + 59bf705 commit f36d037
Show file tree
Hide file tree
Showing 103 changed files with 6,707 additions and 3,769 deletions.
18 changes: 7 additions & 11 deletions contrib/libarchive/NEWS
@@ -1,14 +1,10 @@
Jan 10, 2012: Issue 223: Skip atime tests if atime not supported
Jan 09, 2012: Issue 222: Errors saving sparse files to pax archives
Jan 09, 2012: Issue 221: allow archive_*_free(NULL)
Dec 31, 2011: Issue 212: configure script on Solaris
Dec 30, 2011: Issue 218: empty contents extracting Zip files with bsdcpio
Dec 30, 2011: Issue 217: fix compile warning
Dec 30, 2011: Issue 216: truncated filenames in listings
Dec 28, 2011: Issue 210: memory leak on Windows
Dec 28, 2011: Issue 206: fix hardlink tests on Windows 2000
Dec 27, 2011: Issue 208: Don't hang when using external compression
program on Windows
Mar 27, 2012: libarchive 3.0.4 released

Feb 05, 2012: libarchive development now hosted at GitHub.
http://libarchive.github.com/
Feb 05, 2012: libarchive's issue tracker remains at Google Code.
http://code.google.com/p/libarchive/issues/list
Feb 05, 2012: libarchive's mailing lists remain at Google Groups.

Dec 24, 2011: libarchive 3.0.2 released
Dec 23, 2011: Various fixes merged from FreeBSD
Expand Down
13 changes: 10 additions & 3 deletions contrib/libarchive/README
@@ -1,9 +1,14 @@
README for libarchive bundle.

Questions? Issues?
* http://libarchive.googlecode.com/ is the home for ongoing
libarchive development, including issue tracker, additional
documentation, and links to the libarchive mailing lists.
* http://libarchive.github.com/ is the home for ongoing
libarchive development, including documentation, and
links to the libarchive mailing lists.
* To report an issue, use the issue tracker at
http://code.google.com/p/libarchive/issues/list
* To submit an enhancement to libarchive, please submit
a pull request via GitHub.
https://github.com/libarchive/libarchive/pulls

This distribution bundle includes the following components:
* libarchive: a library for reading and writing streaming archives
Expand Down Expand Up @@ -66,6 +71,7 @@ Currently, the library automatically detects and reads the following fomats:
* ZIP archives (with uncompressed or "deflate" compressed entries)
* GNU and BSD 'ar' archives
* 'mtree' format
* 7-Zip archives
* Microsoft CAB format
* LHA and LZH archives
* RAR archives
Expand All @@ -92,6 +98,7 @@ The library can create archives in any of the following formats:
* GNU and BSD 'ar' archives
* 'mtree' format
* ISO9660 format
* 7-Zip archives
* XAR archives

When creating archives, the result can be filtered with any of the following:
Expand Down
2 changes: 1 addition & 1 deletion contrib/libarchive/build/version
@@ -1 +1 @@
3000003
3000004
2 changes: 1 addition & 1 deletion contrib/libarchive/cpio/bsdcpio.1
Expand Up @@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd December 21, 2007
.Dd December 24, 2011
.Dt CPIO 1
.Os
.Sh NAME
Expand Down
1 change: 1 addition & 0 deletions contrib/libarchive/cpio/cmdline.c
Expand Up @@ -346,6 +346,7 @@ owner_parse(const char *spec, int *uid, int *gid)
snprintf(errbuff, sizeof(errbuff),
"Couldn't lookup user ``%s''", user);
errbuff[sizeof(errbuff) - 1] = '\0';
free(user);
return (errbuff);
}
}
Expand Down
102 changes: 83 additions & 19 deletions contrib/libarchive/cpio/cpio.c
Expand Up @@ -82,7 +82,6 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/cpio.c,v 1.15 2008/12/06 07:30:40 kientzle
#include "cpio.h"
#include "err.h"
#include "line_reader.h"
#include "matching.h"

/* Fixed size of uname/gname caches. */
#define name_cache_size 101
Expand Down Expand Up @@ -119,6 +118,7 @@ static void mode_in(struct cpio *);
static void mode_list(struct cpio *);
static void mode_out(struct cpio *);
static void mode_pass(struct cpio *, const char *);
static const char *remove_leading_slash(const char *);
static int restore_time(struct cpio *, struct archive_entry *,
const char *, int fd);
static void usage(void);
Expand Down Expand Up @@ -155,9 +155,9 @@ main(int argc, char *argv[])
else {
#if defined(_WIN32) && !defined(__CYGWIN__)
lafe_progname = strrchr(*argv, '\\');
#else
lafe_progname = strrchr(*argv, '/');
if (strrchr(*argv, '/') > lafe_progname)
#endif
lafe_progname = strrchr(*argv, '/');
if (lafe_progname != NULL)
lafe_progname++;
else
Expand Down Expand Up @@ -189,6 +189,10 @@ main(int argc, char *argv[])
cpio->bytes_per_block = 512;
cpio->filename = NULL;

cpio->matching = archive_match_new();
if (cpio->matching == NULL)
lafe_errc(1, 0, "Out of memory");

while ((opt = cpio_getopt(cpio)) != -1) {
switch (opt) {
case '0': /* GNU convention: --null, -0 */
Expand All @@ -215,14 +219,20 @@ main(int argc, char *argv[])
cpio->extract_flags &= ~ARCHIVE_EXTRACT_NO_AUTODIR;
break;
case 'E': /* NetBSD/OpenBSD */
lafe_include_from_file(&cpio->matching,
cpio->argument, cpio->option_null);
if (archive_match_include_pattern_from_file(
cpio->matching, cpio->argument,
cpio->option_null) != ARCHIVE_OK)
lafe_errc(1, 0, "Error : %s",
archive_error_string(cpio->matching));
break;
case 'F': /* NetBSD/OpenBSD/GNU cpio */
cpio->filename = cpio->argument;
break;
case 'f': /* POSIX 1997 */
lafe_exclude(&cpio->matching, cpio->argument);
if (archive_match_exclude_pattern(cpio->matching,
cpio->argument) != ARCHIVE_OK)
lafe_errc(1, 0, "Error : %s",
archive_error_string(cpio->matching));
break;
case 'H': /* GNU cpio (also --format) */
cpio->format = cpio->argument;
Expand Down Expand Up @@ -366,9 +376,6 @@ main(int argc, char *argv[])
if (cpio->option_link && cpio->mode != 'p')
lafe_errc(1, 0, "Option -l requires -p");
/* -v overrides -V */
if (cpio->dot && cpio->verbose)
cpio->dot = 0;
/* -v overrides -V */
if (cpio->dot && cpio->verbose)
cpio->dot = 0;
/* TODO: Flag other nonsensical combinations. */
Expand All @@ -384,7 +391,10 @@ main(int argc, char *argv[])
break;
case 'i':
while (*cpio->argv != NULL) {
lafe_include(&cpio->matching, *cpio->argv);
if (archive_match_include_pattern(cpio->matching,
*cpio->argv) != ARCHIVE_OK)
lafe_errc(1, 0, "Error : %s",
archive_error_string(cpio->matching));
--cpio->argc;
++cpio->argv;
}
Expand All @@ -404,6 +414,7 @@ main(int argc, char *argv[])
"Must specify at least one of -i, -o, or -p");
}

archive_match_free(cpio->matching);
free_cache(cpio->gname_cache);
free_cache(cpio->uname_cache);
return (cpio->return_value);
Expand Down Expand Up @@ -574,6 +585,49 @@ mode_out(struct cpio *cpio)
archive_write_free(cpio->archive);
}

static const char *
remove_leading_slash(const char *p)
{
const char *rp;

/* Remove leading "//./" or "//?/" or "//?/UNC/"
* (absolute path prefixes used by Windows API) */
if ((p[0] == '/' || p[0] == '\\') &&
(p[1] == '/' || p[1] == '\\') &&
(p[2] == '.' || p[2] == '?') &&
(p[3] == '/' || p[3] == '\\'))
{
if (p[2] == '?' &&
(p[4] == 'U' || p[4] == 'u') &&
(p[5] == 'N' || p[5] == 'n') &&
(p[6] == 'C' || p[6] == 'c') &&
(p[7] == '/' || p[7] == '\\'))
p += 8;
else
p += 4;
}
do {
rp = p;
/* Remove leading drive letter from archives created
* on Windows. */
if (((p[0] >= 'a' && p[0] <= 'z') ||
(p[0] >= 'A' && p[0] <= 'Z')) &&
p[1] == ':') {
p += 2;
}
/* Remove leading "/../", "//", etc. */
while (p[0] == '/' || p[0] == '\\') {
if (p[1] == '.' && p[2] == '.' &&
(p[3] == '/' || p[3] == '\\')) {
p += 3; /* Remove "/..", leave "/"
* for next pass. */
} else
p += 1; /* Remove "/". */
}
} while (rp != p);
return (p);
}

/*
* This is used by both out mode (to copy objects from disk into
* an archive) and pass mode (to copy objects from disk to
Expand All @@ -585,7 +639,6 @@ file_to_archive(struct cpio *cpio, const char *srcpath)
const char *destpath;
struct archive_entry *entry, *spare;
size_t len;
const char *p;
int r;

/*
Expand Down Expand Up @@ -639,10 +692,7 @@ file_to_archive(struct cpio *cpio, const char *srcpath)
"Can't allocate path buffer");
}
strcpy(cpio->pass_destpath, cpio->destdir);
p = srcpath;
while (p[0] == '/')
++p;
strcat(cpio->pass_destpath, p);
strcat(cpio->pass_destpath, remove_leading_slash(srcpath));
destpath = cpio->pass_destpath;
}
if (cpio->option_rename)
Expand Down Expand Up @@ -869,7 +919,7 @@ mode_in(struct cpio *cpio)
lafe_errc(1, archive_errno(a),
"%s", archive_error_string(a));
}
if (lafe_excluded(cpio->matching, archive_entry_pathname(entry)))
if (archive_match_path_excluded(cpio->matching, entry))
continue;
if (cpio->option_rename) {
destpath = cpio_rename(archive_entry_pathname(entry));
Expand Down Expand Up @@ -971,7 +1021,7 @@ mode_list(struct cpio *cpio)
lafe_errc(1, archive_errno(a),
"%s", archive_error_string(a));
}
if (lafe_excluded(cpio->matching, archive_entry_pathname(entry)))
if (archive_match_path_excluded(cpio->matching, entry))
continue;
if (cpio->verbose)
list_item_verbose(cpio, entry);
Expand Down Expand Up @@ -1139,12 +1189,24 @@ cpio_rename(const char *name)
static char buff[1024];
FILE *t;
char *p, *ret;
#if defined(_WIN32) && !defined(__CYGWIN__)
FILE *to;

t = fopen("CONIN$", "r");
if (t == NULL)
return (name);
to = fopen("CONOUT$", "w");
if (to == NULL)
return (name);
fprintf(to, "%s (Enter/./(new name))? ", name);
fclose(to);
#else
t = fopen("/dev/tty", "r+");
if (t == NULL)
return (name);
fprintf(t, "%s (Enter/./(new name))? ", name);
fflush(t);
#endif

p = fgets(buff, sizeof(buff), t);
fclose(t);
Expand Down Expand Up @@ -1254,7 +1316,8 @@ lookup_uname_helper(struct cpio *cpio, const char **name, id_t id)
if (pwent == NULL) {
*name = NULL;
if (errno != 0 && errno != ENOENT)
lafe_warnc(errno, "getpwuid(%d) failed", id);
lafe_warnc(errno, "getpwuid(%s) failed",
cpio_i64toa((int64_t)id));
return (errno);
}

Expand All @@ -1281,7 +1344,8 @@ lookup_gname_helper(struct cpio *cpio, const char **name, id_t id)
if (grent == NULL) {
*name = NULL;
if (errno != 0)
lafe_warnc(errno, "getgrgid(%d) failed", id);
lafe_warnc(errno, "getgrgid(%s) failed",
cpio_i64toa((int64_t)id));
return (errno);
}

Expand Down
4 changes: 1 addition & 3 deletions contrib/libarchive/cpio/cpio.h
Expand Up @@ -31,8 +31,6 @@
#include "cpio_platform.h"
#include <stdio.h>

#include "matching.h"

/*
* The internal state for the "cpio" program.
*
Expand Down Expand Up @@ -88,7 +86,7 @@ struct cpio {
struct name_cache *gname_cache;

/* Work data. */
struct lafe_matching *matching;
struct archive *matching;
char *buff;
size_t buff_size;
};
Expand Down

0 comments on commit f36d037

Please sign in to comment.