2011-12-20 22:47:56 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2003-2008 Tim Kientzle
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bsdtar_platform.h"
|
|
|
|
__FBSDID("$FreeBSD: src/usr.bin/tar/bsdtar.c,v 1.93 2008/11/08 04:43:24 kientzle Exp $");
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
2012-02-08 12:53:14 +00:00
|
|
|
#ifdef HAVE_COPYFILE_H
|
|
|
|
#include <copyfile.h>
|
|
|
|
#endif
|
2011-12-20 22:47:56 +00:00
|
|
|
#ifdef HAVE_ERRNO_H
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LANGINFO_H
|
|
|
|
#include <langinfo.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LOCALE_H
|
|
|
|
#include <locale.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_PATHS_H
|
|
|
|
#include <paths.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SIGNAL_H
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_TIME_H
|
|
|
|
#include <time.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "bsdtar.h"
|
|
|
|
#include "err.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Per POSIX.1-1988, tar defaults to reading/writing archives to/from
|
|
|
|
* the default tape device for the system. Pick something reasonable here.
|
|
|
|
*/
|
|
|
|
#ifdef __linux
|
|
|
|
#define _PATH_DEFTAPE "/dev/st0"
|
|
|
|
#endif
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
#define _PATH_DEFTAPE "\\\\.\\tape0"
|
|
|
|
#endif
|
2012-02-08 12:53:14 +00:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
#undef _PATH_DEFTAPE
|
|
|
|
#define _PATH_DEFTAPE "-" /* Mac OS has no tape support, default to stdio. */
|
|
|
|
#endif
|
2011-12-20 22:47:56 +00:00
|
|
|
|
|
|
|
#ifndef _PATH_DEFTAPE
|
|
|
|
#define _PATH_DEFTAPE "/dev/tape"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __MINGW32__
|
|
|
|
int _CRT_glob = 0; /* Disable broken CRT globbing. */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_SIGACTION) && (defined(SIGINFO) || defined(SIGUSR1))
|
|
|
|
static volatile int siginfo_occurred;
|
|
|
|
|
|
|
|
static void
|
|
|
|
siginfo_handler(int sig)
|
|
|
|
{
|
|
|
|
(void)sig; /* UNUSED */
|
|
|
|
siginfo_occurred = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
need_report(void)
|
|
|
|
{
|
|
|
|
int r = siginfo_occurred;
|
|
|
|
siginfo_occurred = 0;
|
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
int
|
|
|
|
need_report(void)
|
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void long_help(void);
|
|
|
|
static void only_mode(struct bsdtar *, const char *opt,
|
|
|
|
const char *valid);
|
|
|
|
static void set_mode(struct bsdtar *, char opt);
|
|
|
|
static void version(void);
|
|
|
|
|
|
|
|
/* A basic set of security flags to request from libarchive. */
|
|
|
|
#define SECURITY \
|
|
|
|
(ARCHIVE_EXTRACT_SECURE_SYMLINKS \
|
|
|
|
| ARCHIVE_EXTRACT_SECURE_NODOTDOT)
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct bsdtar *bsdtar, bsdtar_storage;
|
|
|
|
int opt, t;
|
2013-03-21 18:59:02 +00:00
|
|
|
char compression, compression2;
|
|
|
|
const char *compression_name, *compression2_name;
|
|
|
|
const char *compress_program;
|
|
|
|
char option_a, option_o;
|
2011-12-20 22:47:56 +00:00
|
|
|
char possible_help_request;
|
|
|
|
char buff[16];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use a pointer for consistency, but stack-allocated storage
|
|
|
|
* for ease of cleanup.
|
|
|
|
*/
|
2012-02-08 12:53:14 +00:00
|
|
|
bsdtar = &bsdtar_storage;
|
2011-12-20 22:47:56 +00:00
|
|
|
memset(bsdtar, 0, sizeof(*bsdtar));
|
|
|
|
bsdtar->fd = -1; /* Mark as "unused" */
|
|
|
|
bsdtar->gid = -1;
|
|
|
|
bsdtar->uid = -1;
|
2013-03-21 18:59:02 +00:00
|
|
|
option_a = option_o = 0;
|
|
|
|
compression = compression2 = '\0';
|
|
|
|
compression_name = compression2_name = NULL;
|
|
|
|
compress_program = NULL;
|
2011-12-20 22:47:56 +00:00
|
|
|
|
2012-02-08 12:53:14 +00:00
|
|
|
#if defined(HAVE_SIGACTION)
|
|
|
|
{ /* Set up signal handling. */
|
2011-12-20 22:47:56 +00:00
|
|
|
struct sigaction sa;
|
|
|
|
sa.sa_handler = siginfo_handler;
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
sa.sa_flags = 0;
|
|
|
|
#ifdef SIGINFO
|
|
|
|
if (sigaction(SIGINFO, &sa, NULL))
|
|
|
|
lafe_errc(1, errno, "sigaction(SIGINFO) failed");
|
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR1
|
|
|
|
/* ... and treat SIGUSR1 the same way as SIGINFO. */
|
|
|
|
if (sigaction(SIGUSR1, &sa, NULL))
|
|
|
|
lafe_errc(1, errno, "sigaction(SIGUSR1) failed");
|
2012-02-08 12:53:14 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPIPE
|
|
|
|
/* Ignore SIGPIPE signals. */
|
|
|
|
sa.sa_handler = SIG_IGN;
|
|
|
|
sigaction(SIGPIPE, &sa, NULL);
|
2011-12-20 22:47:56 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* Need lafe_progname before calling lafe_warnc. */
|
|
|
|
if (*argv == NULL)
|
|
|
|
lafe_progname = "bsdtar";
|
|
|
|
else {
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
lafe_progname = strrchr(*argv, '\\');
|
2012-02-25 00:16:00 +00:00
|
|
|
if (strrchr(*argv, '/') > lafe_progname)
|
2011-12-20 22:47:56 +00:00
|
|
|
#endif
|
2012-02-25 00:16:00 +00:00
|
|
|
lafe_progname = strrchr(*argv, '/');
|
2011-12-20 22:47:56 +00:00
|
|
|
if (lafe_progname != NULL)
|
|
|
|
lafe_progname++;
|
|
|
|
else
|
|
|
|
lafe_progname = *argv;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if HAVE_SETLOCALE
|
|
|
|
if (setlocale(LC_ALL, "") == NULL)
|
|
|
|
lafe_warnc(0, "Failed to set default locale");
|
|
|
|
#endif
|
|
|
|
#if defined(HAVE_NL_LANGINFO) && defined(HAVE_D_MD_ORDER)
|
|
|
|
bsdtar->day_first = (*nl_langinfo(D_MD_ORDER) == 'd');
|
|
|
|
#endif
|
|
|
|
possible_help_request = 0;
|
|
|
|
|
|
|
|
/* Look up uid of current user for future reference */
|
|
|
|
bsdtar->user_uid = geteuid();
|
|
|
|
|
|
|
|
/* Default: open tape drive. */
|
|
|
|
bsdtar->filename = getenv("TAPE");
|
|
|
|
if (bsdtar->filename == NULL)
|
|
|
|
bsdtar->filename = _PATH_DEFTAPE;
|
|
|
|
|
2012-02-08 12:53:14 +00:00
|
|
|
/* Default block size settings. */
|
|
|
|
bsdtar->bytes_per_block = DEFAULT_BYTES_PER_BLOCK;
|
|
|
|
/* Allow library to default this unless user specifies -b. */
|
|
|
|
bsdtar->bytes_in_last_block = -1;
|
|
|
|
|
2011-12-20 22:47:56 +00:00
|
|
|
/* Default: preserve mod time on extract */
|
|
|
|
bsdtar->extract_flags = ARCHIVE_EXTRACT_TIME;
|
|
|
|
|
|
|
|
/* Default: Perform basic security checks. */
|
|
|
|
bsdtar->extract_flags |= SECURITY;
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
/* On POSIX systems, assume --same-owner and -p when run by
|
|
|
|
* the root user. This doesn't make any sense on Windows. */
|
|
|
|
if (bsdtar->user_uid == 0) {
|
|
|
|
/* --same-owner */
|
|
|
|
bsdtar->extract_flags |= ARCHIVE_EXTRACT_OWNER;
|
|
|
|
/* -p */
|
|
|
|
bsdtar->extract_flags |= ARCHIVE_EXTRACT_PERM;
|
|
|
|
bsdtar->extract_flags |= ARCHIVE_EXTRACT_ACL;
|
|
|
|
bsdtar->extract_flags |= ARCHIVE_EXTRACT_XATTR;
|
|
|
|
bsdtar->extract_flags |= ARCHIVE_EXTRACT_FFLAGS;
|
2012-02-08 12:53:14 +00:00
|
|
|
bsdtar->extract_flags |= ARCHIVE_EXTRACT_MAC_METADATA;
|
2011-12-20 22:47:56 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-02-08 12:53:14 +00:00
|
|
|
/*
|
|
|
|
* Enable Mac OS "copyfile()" extension by default.
|
|
|
|
* This has no effect on other platforms.
|
|
|
|
*/
|
2012-07-27 08:24:12 +00:00
|
|
|
bsdtar->readdisk_flags |= ARCHIVE_READDISK_MAC_COPYFILE;
|
2012-02-08 12:53:14 +00:00
|
|
|
#ifdef COPYFILE_DISABLE_VAR
|
|
|
|
if (getenv(COPYFILE_DISABLE_VAR))
|
2012-07-27 08:24:12 +00:00
|
|
|
bsdtar->readdisk_flags &= ~ARCHIVE_READDISK_MAC_COPYFILE;
|
2012-02-08 12:53:14 +00:00
|
|
|
#endif
|
2012-07-27 08:24:12 +00:00
|
|
|
bsdtar->matching = archive_match_new();
|
|
|
|
if (bsdtar->matching == NULL)
|
|
|
|
lafe_errc(1, errno, "Out of memory");
|
2013-03-21 18:59:02 +00:00
|
|
|
bsdtar->cset = cset_new();
|
|
|
|
if (bsdtar->cset == NULL)
|
|
|
|
lafe_errc(1, errno, "Out of memory");
|
2012-02-08 12:53:14 +00:00
|
|
|
|
2011-12-20 22:47:56 +00:00
|
|
|
bsdtar->argv = argv;
|
|
|
|
bsdtar->argc = argc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Comments following each option indicate where that option
|
|
|
|
* originated: SUSv2, POSIX, GNU tar, star, etc. If there's
|
|
|
|
* no such comment, then I don't know of anyone else who
|
|
|
|
* implements that option.
|
|
|
|
*/
|
|
|
|
while ((opt = bsdtar_getopt(bsdtar)) != -1) {
|
|
|
|
switch (opt) {
|
2013-03-21 18:59:02 +00:00
|
|
|
case 'a': /* GNU tar */
|
|
|
|
option_a = 1; /* Record it and resolve it later. */
|
|
|
|
break;
|
2011-12-20 22:47:56 +00:00
|
|
|
case 'B': /* GNU tar */
|
|
|
|
/* libarchive doesn't need this; just ignore it. */
|
|
|
|
break;
|
|
|
|
case 'b': /* SUSv2 */
|
2012-02-08 12:53:14 +00:00
|
|
|
t = atoi(bsdtar->argument);
|
2011-12-20 22:47:56 +00:00
|
|
|
if (t <= 0 || t > 8192)
|
|
|
|
lafe_errc(1, 0,
|
|
|
|
"Argument to -b is out of range (1..8192)");
|
|
|
|
bsdtar->bytes_per_block = 512 * t;
|
2012-02-08 12:53:14 +00:00
|
|
|
/* Explicit -b forces last block size. */
|
|
|
|
bsdtar->bytes_in_last_block = bsdtar->bytes_per_block;
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
2013-03-21 18:59:02 +00:00
|
|
|
case OPTION_B64ENCODE:
|
|
|
|
if (compression2 != '\0')
|
|
|
|
lafe_errc(1, 0,
|
|
|
|
"Can't specify both --uuencode and "
|
|
|
|
"--b64encode");
|
|
|
|
compression2 = opt;
|
|
|
|
compression2_name = "b64encode";
|
|
|
|
break;
|
2011-12-20 22:47:56 +00:00
|
|
|
case 'C': /* GNU tar */
|
2012-02-08 12:53:14 +00:00
|
|
|
if (strlen(bsdtar->argument) == 0)
|
|
|
|
lafe_errc(1, 0,
|
|
|
|
"Meaningless option: -C ''");
|
|
|
|
|
|
|
|
set_chdir(bsdtar, bsdtar->argument);
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case 'c': /* SUSv2 */
|
|
|
|
set_mode(bsdtar, opt);
|
|
|
|
break;
|
|
|
|
case OPTION_CHECK_LINKS: /* GNU tar */
|
|
|
|
bsdtar->option_warn_links = 1;
|
|
|
|
break;
|
|
|
|
case OPTION_CHROOT: /* NetBSD */
|
|
|
|
bsdtar->option_chroot = 1;
|
|
|
|
break;
|
2012-02-08 12:53:14 +00:00
|
|
|
case OPTION_DISABLE_COPYFILE: /* Mac OS X */
|
2012-07-27 08:24:12 +00:00
|
|
|
bsdtar->readdisk_flags &= ~ARCHIVE_READDISK_MAC_COPYFILE;
|
2012-02-08 12:53:14 +00:00
|
|
|
break;
|
2011-12-20 22:47:56 +00:00
|
|
|
case OPTION_EXCLUDE: /* GNU tar */
|
2012-07-27 08:24:12 +00:00
|
|
|
if (archive_match_exclude_pattern(
|
|
|
|
bsdtar->matching, bsdtar->argument) != ARCHIVE_OK)
|
2011-12-20 22:47:56 +00:00
|
|
|
lafe_errc(1, 0,
|
2012-02-08 12:53:14 +00:00
|
|
|
"Couldn't exclude %s\n", bsdtar->argument);
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case OPTION_FORMAT: /* GNU tar, others */
|
2013-03-21 18:59:02 +00:00
|
|
|
cset_set_format(bsdtar->cset, bsdtar->argument);
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case 'f': /* SUSv2 */
|
2012-02-08 12:53:14 +00:00
|
|
|
bsdtar->filename = bsdtar->argument;
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case OPTION_GID: /* cpio */
|
2012-02-08 12:53:14 +00:00
|
|
|
t = atoi(bsdtar->argument);
|
2011-12-20 22:47:56 +00:00
|
|
|
if (t < 0)
|
|
|
|
lafe_errc(1, 0,
|
|
|
|
"Argument to --gid must be positive");
|
|
|
|
bsdtar->gid = t;
|
|
|
|
break;
|
|
|
|
case OPTION_GNAME: /* cpio */
|
2012-02-08 12:53:14 +00:00
|
|
|
bsdtar->gname = bsdtar->argument;
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
2013-03-21 18:59:02 +00:00
|
|
|
case OPTION_GRZIP:
|
|
|
|
if (compression != '\0')
|
|
|
|
lafe_errc(1, 0,
|
|
|
|
"Can't specify both -%c and -%c", opt,
|
|
|
|
compression);
|
|
|
|
compression = opt;
|
|
|
|
compression_name = "grzip";
|
|
|
|
break;
|
2011-12-20 22:47:56 +00:00
|
|
|
case 'H': /* BSD convention */
|
|
|
|
bsdtar->symlink_mode = 'H';
|
|
|
|
break;
|
|
|
|
case 'h': /* Linux Standards Base, gtar; synonym for -L */
|
|
|
|
bsdtar->symlink_mode = 'L';
|
|
|
|
/* Hack: -h by itself is the "help" command. */
|
|
|
|
possible_help_request = 1;
|
|
|
|
break;
|
|
|
|
case OPTION_HELP: /* GNU tar, others */
|
|
|
|
long_help();
|
|
|
|
exit(0);
|
|
|
|
break;
|
2013-03-21 18:59:02 +00:00
|
|
|
case OPTION_HFS_COMPRESSION: /* Mac OS X v10.6 or later */
|
|
|
|
bsdtar->extract_flags |=
|
|
|
|
ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED;
|
|
|
|
break;
|
2011-12-20 22:47:56 +00:00
|
|
|
case 'I': /* GNU tar */
|
|
|
|
/*
|
|
|
|
* TODO: Allow 'names' to come from an archive,
|
|
|
|
* not just a text file. Design a good UI for
|
|
|
|
* allowing names and mode/owner to be read
|
|
|
|
* from an archive, with contents coming from
|
|
|
|
* disk. This can be used to "refresh" an
|
|
|
|
* archive or to design archives with special
|
|
|
|
* permissions without having to create those
|
|
|
|
* permissions on disk.
|
|
|
|
*/
|
2012-02-08 12:53:14 +00:00
|
|
|
bsdtar->names_from_file = bsdtar->argument;
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case OPTION_INCLUDE:
|
|
|
|
/*
|
2012-02-08 12:53:14 +00:00
|
|
|
* No one else has the @archive extension, so
|
|
|
|
* no one else needs this to filter entries
|
2011-12-20 22:47:56 +00:00
|
|
|
* when transforming archives.
|
|
|
|
*/
|
2012-07-27 08:24:12 +00:00
|
|
|
if (archive_match_include_pattern(bsdtar->matching,
|
|
|
|
bsdtar->argument) != ARCHIVE_OK)
|
2011-12-20 22:47:56 +00:00
|
|
|
lafe_errc(1, 0,
|
|
|
|
"Failed to add %s to inclusion list",
|
2012-02-08 12:53:14 +00:00
|
|
|
bsdtar->argument);
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case 'j': /* GNU tar */
|
2013-03-21 18:59:02 +00:00
|
|
|
if (compression != '\0')
|
2011-12-20 22:47:56 +00:00
|
|
|
lafe_errc(1, 0,
|
|
|
|
"Can't specify both -%c and -%c", opt,
|
2013-03-21 18:59:02 +00:00
|
|
|
compression);
|
|
|
|
compression = opt;
|
|
|
|
compression_name = "bzip2";
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case 'J': /* GNU tar 1.21 and later */
|
2013-03-21 18:59:02 +00:00
|
|
|
if (compression != '\0')
|
2011-12-20 22:47:56 +00:00
|
|
|
lafe_errc(1, 0,
|
|
|
|
"Can't specify both -%c and -%c", opt,
|
2013-03-21 18:59:02 +00:00
|
|
|
compression);
|
|
|
|
compression = opt;
|
|
|
|
compression_name = "xz";
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case 'k': /* GNU tar */
|
|
|
|
bsdtar->extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE;
|
|
|
|
break;
|
|
|
|
case OPTION_KEEP_NEWER_FILES: /* GNU tar */
|
|
|
|
bsdtar->extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER;
|
|
|
|
break;
|
|
|
|
case 'L': /* BSD convention */
|
|
|
|
bsdtar->symlink_mode = 'L';
|
|
|
|
break;
|
|
|
|
case 'l': /* SUSv2 and GNU tar beginning with 1.16 */
|
|
|
|
/* GNU tar 1.13 used -l for --one-file-system */
|
|
|
|
bsdtar->option_warn_links = 1;
|
|
|
|
break;
|
2013-03-21 18:59:02 +00:00
|
|
|
case OPTION_LRZIP:
|
2012-02-08 12:53:14 +00:00
|
|
|
case OPTION_LZIP: /* GNU tar beginning with 1.23 */
|
|
|
|
case OPTION_LZMA: /* GNU tar beginning with 1.20 */
|
2013-03-21 18:59:02 +00:00
|
|
|
case OPTION_LZOP: /* GNU tar beginning with 1.21 */
|
|
|
|
if (compression != '\0')
|
2011-12-20 22:47:56 +00:00
|
|
|
lafe_errc(1, 0,
|
|
|
|
"Can't specify both -%c and -%c", opt,
|
2013-03-21 18:59:02 +00:00
|
|
|
compression);
|
|
|
|
compression = opt;
|
|
|
|
switch (opt) {
|
|
|
|
case OPTION_LRZIP: compression_name = "lrzip"; break;
|
|
|
|
case OPTION_LZIP: compression_name = "lzip"; break;
|
|
|
|
case OPTION_LZMA: compression_name = "lzma"; break;
|
|
|
|
case OPTION_LZOP: compression_name = "lzop"; break;
|
|
|
|
}
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case 'm': /* SUSv2 */
|
|
|
|
bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_TIME;
|
|
|
|
break;
|
|
|
|
case 'n': /* GNU tar */
|
|
|
|
bsdtar->option_no_subdirs = 1;
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* Selecting files by time:
|
|
|
|
* --newer-?time='date' Only files newer than 'date'
|
|
|
|
* --newer-?time-than='file' Only files newer than time
|
|
|
|
* on specified file (useful for incremental backups)
|
|
|
|
*/
|
|
|
|
case OPTION_NEWER_CTIME: /* GNU tar */
|
2012-07-27 08:24:12 +00:00
|
|
|
if (archive_match_include_date(bsdtar->matching,
|
|
|
|
ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_NEWER,
|
|
|
|
bsdtar->argument) != ARCHIVE_OK)
|
|
|
|
lafe_errc(1, 0, "Error : %s",
|
|
|
|
archive_error_string(bsdtar->matching));
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case OPTION_NEWER_CTIME_THAN:
|
2012-07-27 08:24:12 +00:00
|
|
|
if (archive_match_include_file_time(bsdtar->matching,
|
|
|
|
ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_NEWER,
|
|
|
|
bsdtar->argument) != ARCHIVE_OK)
|
|
|
|
lafe_errc(1, 0, "Error : %s",
|
|
|
|
archive_error_string(bsdtar->matching));
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case OPTION_NEWER_MTIME: /* GNU tar */
|
2012-07-27 08:24:12 +00:00
|
|
|
if (archive_match_include_date(bsdtar->matching,
|
|
|
|
ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_NEWER,
|
|
|
|
bsdtar->argument) != ARCHIVE_OK)
|
|
|
|
lafe_errc(1, 0, "Error : %s",
|
|
|
|
archive_error_string(bsdtar->matching));
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case OPTION_NEWER_MTIME_THAN:
|
2012-07-27 08:24:12 +00:00
|
|
|
if (archive_match_include_file_time(bsdtar->matching,
|
|
|
|
ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_NEWER,
|
|
|
|
bsdtar->argument) != ARCHIVE_OK)
|
|
|
|
lafe_errc(1, 0, "Error : %s",
|
|
|
|
archive_error_string(bsdtar->matching));
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case OPTION_NODUMP: /* star */
|
2012-07-27 08:24:12 +00:00
|
|
|
bsdtar->readdisk_flags |= ARCHIVE_READDISK_HONOR_NODUMP;
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
2013-03-21 18:59:02 +00:00
|
|
|
case OPTION_NOPRESERVE_HFS_COMPRESSION:
|
|
|
|
/* Mac OS X v10.6 or later */
|
|
|
|
bsdtar->extract_flags |=
|
|
|
|
ARCHIVE_EXTRACT_NO_HFS_COMPRESSION;
|
|
|
|
break;
|
2011-12-20 22:47:56 +00:00
|
|
|
case OPTION_NO_SAME_OWNER: /* GNU tar */
|
|
|
|
bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_OWNER;
|
|
|
|
break;
|
|
|
|
case OPTION_NO_SAME_PERMISSIONS: /* GNU tar */
|
|
|
|
bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_PERM;
|
|
|
|
bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_ACL;
|
|
|
|
bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_XATTR;
|
|
|
|
bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_FFLAGS;
|
2012-02-08 12:53:14 +00:00
|
|
|
bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_MAC_METADATA;
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case OPTION_NULL: /* GNU tar */
|
|
|
|
bsdtar->option_null++;
|
|
|
|
break;
|
|
|
|
case OPTION_NUMERIC_OWNER: /* GNU tar */
|
|
|
|
bsdtar->uname = "";
|
|
|
|
bsdtar->gname = "";
|
2012-02-08 12:53:14 +00:00
|
|
|
bsdtar->option_numeric_owner++;
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case 'O': /* GNU tar */
|
|
|
|
bsdtar->option_stdout = 1;
|
|
|
|
break;
|
|
|
|
case 'o': /* SUSv2 and GNU conflict here, but not fatally */
|
|
|
|
option_o = 1; /* Record it and resolve it later. */
|
|
|
|
break;
|
2013-03-21 18:59:02 +00:00
|
|
|
/*
|
|
|
|
* Selecting files by time:
|
|
|
|
* --older-?time='date' Only files older than 'date'
|
|
|
|
* --older-?time-than='file' Only files older than time
|
|
|
|
* on specified file
|
|
|
|
*/
|
|
|
|
case OPTION_OLDER_CTIME:
|
|
|
|
if (archive_match_include_date(bsdtar->matching,
|
|
|
|
ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_OLDER,
|
|
|
|
bsdtar->argument) != ARCHIVE_OK)
|
|
|
|
lafe_errc(1, 0, "Error : %s",
|
|
|
|
archive_error_string(bsdtar->matching));
|
|
|
|
break;
|
|
|
|
case OPTION_OLDER_CTIME_THAN:
|
|
|
|
if (archive_match_include_file_time(bsdtar->matching,
|
|
|
|
ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_OLDER,
|
|
|
|
bsdtar->argument) != ARCHIVE_OK)
|
|
|
|
lafe_errc(1, 0, "Error : %s",
|
|
|
|
archive_error_string(bsdtar->matching));
|
|
|
|
break;
|
|
|
|
case OPTION_OLDER_MTIME:
|
|
|
|
if (archive_match_include_date(bsdtar->matching,
|
|
|
|
ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER,
|
|
|
|
bsdtar->argument) != ARCHIVE_OK)
|
|
|
|
lafe_errc(1, 0, "Error : %s",
|
|
|
|
archive_error_string(bsdtar->matching));
|
|
|
|
break;
|
|
|
|
case OPTION_OLDER_MTIME_THAN:
|
|
|
|
if (archive_match_include_file_time(bsdtar->matching,
|
|
|
|
ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER,
|
|
|
|
bsdtar->argument) != ARCHIVE_OK)
|
|
|
|
lafe_errc(1, 0, "Error : %s",
|
|
|
|
archive_error_string(bsdtar->matching));
|
|
|
|
break;
|
2011-12-20 22:47:56 +00:00
|
|
|
case OPTION_ONE_FILE_SYSTEM: /* GNU tar */
|
2012-07-27 08:24:12 +00:00
|
|
|
bsdtar->readdisk_flags |=
|
|
|
|
ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS;
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case OPTION_OPTIONS:
|
2012-02-08 12:53:14 +00:00
|
|
|
bsdtar->option_options = bsdtar->argument;
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* The common BSD -P option is not necessary, since
|
|
|
|
* our default is to archive symlinks, not follow
|
|
|
|
* them. This is convenient, as -P conflicts with GNU
|
|
|
|
* tar anyway.
|
|
|
|
*/
|
|
|
|
case 'P': /* BSD convention */
|
|
|
|
/* Default behavior, no option necessary. */
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case 'P': /* GNU tar */
|
|
|
|
bsdtar->extract_flags &= ~SECURITY;
|
|
|
|
bsdtar->option_absolute_paths = 1;
|
|
|
|
break;
|
|
|
|
case 'p': /* GNU tar, star */
|
|
|
|
bsdtar->extract_flags |= ARCHIVE_EXTRACT_PERM;
|
|
|
|
bsdtar->extract_flags |= ARCHIVE_EXTRACT_ACL;
|
|
|
|
bsdtar->extract_flags |= ARCHIVE_EXTRACT_XATTR;
|
|
|
|
bsdtar->extract_flags |= ARCHIVE_EXTRACT_FFLAGS;
|
2012-02-08 12:53:14 +00:00
|
|
|
bsdtar->extract_flags |= ARCHIVE_EXTRACT_MAC_METADATA;
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case OPTION_POSIX: /* GNU tar */
|
2013-03-21 18:59:02 +00:00
|
|
|
cset_set_format(bsdtar->cset, "pax");
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case 'q': /* FreeBSD GNU tar --fast-read, NetBSD -q */
|
|
|
|
bsdtar->option_fast_read = 1;
|
|
|
|
break;
|
|
|
|
case 'r': /* SUSv2 */
|
|
|
|
set_mode(bsdtar, opt);
|
|
|
|
break;
|
|
|
|
case 'S': /* NetBSD pax-as-tar */
|
|
|
|
bsdtar->extract_flags |= ARCHIVE_EXTRACT_SPARSE;
|
|
|
|
break;
|
|
|
|
case 's': /* NetBSD pax-as-tar */
|
2013-03-21 18:59:02 +00:00
|
|
|
#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
|
2012-02-08 12:53:14 +00:00
|
|
|
add_substitution(bsdtar, bsdtar->argument);
|
2011-12-20 22:47:56 +00:00
|
|
|
#else
|
|
|
|
lafe_warnc(0,
|
|
|
|
"-s is not supported by this version of bsdtar");
|
|
|
|
usage();
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case OPTION_SAME_OWNER: /* GNU tar */
|
|
|
|
bsdtar->extract_flags |= ARCHIVE_EXTRACT_OWNER;
|
|
|
|
break;
|
|
|
|
case OPTION_STRIP_COMPONENTS: /* GNU tar 1.15 */
|
2012-02-08 12:53:14 +00:00
|
|
|
errno = 0;
|
|
|
|
bsdtar->strip_components = strtol(bsdtar->argument,
|
|
|
|
NULL, 0);
|
|
|
|
if (errno)
|
|
|
|
lafe_errc(1, 0,
|
|
|
|
"Invalid --strip-components argument: %s",
|
|
|
|
bsdtar->argument);
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case 'T': /* GNU tar */
|
2012-02-08 12:53:14 +00:00
|
|
|
bsdtar->names_from_file = bsdtar->argument;
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case 't': /* SUSv2 */
|
|
|
|
set_mode(bsdtar, opt);
|
|
|
|
bsdtar->verbose++;
|
|
|
|
break;
|
|
|
|
case OPTION_TOTALS: /* GNU tar */
|
|
|
|
bsdtar->option_totals++;
|
|
|
|
break;
|
|
|
|
case 'U': /* GNU tar */
|
|
|
|
bsdtar->extract_flags |= ARCHIVE_EXTRACT_UNLINK;
|
|
|
|
bsdtar->option_unlink_first = 1;
|
|
|
|
break;
|
|
|
|
case 'u': /* SUSv2 */
|
|
|
|
set_mode(bsdtar, opt);
|
|
|
|
break;
|
|
|
|
case OPTION_UID: /* cpio */
|
2012-02-08 12:53:14 +00:00
|
|
|
t = atoi(bsdtar->argument);
|
2011-12-20 22:47:56 +00:00
|
|
|
if (t < 0)
|
|
|
|
lafe_errc(1, 0,
|
|
|
|
"Argument to --uid must be positive");
|
|
|
|
bsdtar->uid = t;
|
|
|
|
break;
|
|
|
|
case OPTION_UNAME: /* cpio */
|
2012-02-08 12:53:14 +00:00
|
|
|
bsdtar->uname = bsdtar->argument;
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
2013-03-21 18:59:02 +00:00
|
|
|
case OPTION_UUENCODE:
|
|
|
|
if (compression2 != '\0')
|
|
|
|
lafe_errc(1, 0,
|
|
|
|
"Can't specify both --uuencode and "
|
|
|
|
"--b64encode");
|
|
|
|
compression2 = opt;
|
|
|
|
compression2_name = "uuencode";
|
|
|
|
break;
|
2011-12-20 22:47:56 +00:00
|
|
|
case 'v': /* SUSv2 */
|
|
|
|
bsdtar->verbose++;
|
|
|
|
break;
|
|
|
|
case OPTION_VERSION: /* GNU convention */
|
|
|
|
version();
|
|
|
|
break;
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* The -W longopt feature is handled inside of
|
|
|
|
* bsdtar_getopt(), so -W is not available here.
|
|
|
|
*/
|
|
|
|
case 'W': /* Obscure GNU convention. */
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case 'w': /* SUSv2 */
|
|
|
|
bsdtar->option_interactive = 1;
|
|
|
|
break;
|
|
|
|
case 'X': /* GNU tar */
|
2012-07-27 08:24:12 +00:00
|
|
|
if (archive_match_exclude_pattern_from_file(
|
|
|
|
bsdtar->matching, bsdtar->argument, 0)
|
|
|
|
!= ARCHIVE_OK)
|
|
|
|
lafe_errc(1, 0, "Error : %s",
|
|
|
|
archive_error_string(bsdtar->matching));
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case 'x': /* SUSv2 */
|
|
|
|
set_mode(bsdtar, opt);
|
|
|
|
break;
|
|
|
|
case 'y': /* FreeBSD version of GNU tar */
|
2013-03-21 18:59:02 +00:00
|
|
|
if (compression != '\0')
|
2011-12-20 22:47:56 +00:00
|
|
|
lafe_errc(1, 0,
|
|
|
|
"Can't specify both -%c and -%c", opt,
|
2013-03-21 18:59:02 +00:00
|
|
|
compression);
|
|
|
|
compression = opt;
|
|
|
|
compression_name = "bzip2";
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case 'Z': /* GNU tar */
|
2013-03-21 18:59:02 +00:00
|
|
|
if (compression != '\0')
|
2011-12-20 22:47:56 +00:00
|
|
|
lafe_errc(1, 0,
|
|
|
|
"Can't specify both -%c and -%c", opt,
|
2013-03-21 18:59:02 +00:00
|
|
|
compression);
|
|
|
|
compression = opt;
|
|
|
|
compression_name = "compress";
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case 'z': /* GNU tar, star, many others */
|
2013-03-21 18:59:02 +00:00
|
|
|
if (compression != '\0')
|
2011-12-20 22:47:56 +00:00
|
|
|
lafe_errc(1, 0,
|
|
|
|
"Can't specify both -%c and -%c", opt,
|
2013-03-21 18:59:02 +00:00
|
|
|
compression);
|
|
|
|
compression = opt;
|
|
|
|
compression_name = "gzip";
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
case OPTION_USE_COMPRESS_PROGRAM:
|
2013-03-21 18:59:02 +00:00
|
|
|
compress_program = bsdtar->argument;
|
2011-12-20 22:47:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sanity-check options.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* If no "real" mode was specified, treat -h as --help. */
|
|
|
|
if ((bsdtar->mode == '\0') && possible_help_request) {
|
|
|
|
long_help();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, a mode is required. */
|
|
|
|
if (bsdtar->mode == '\0')
|
|
|
|
lafe_errc(1, 0,
|
|
|
|
"Must specify one of -c, -r, -t, -u, -x");
|
|
|
|
|
|
|
|
/* Check boolean options only permitted in certain modes. */
|
2013-03-21 18:59:02 +00:00
|
|
|
if (option_a)
|
|
|
|
only_mode(bsdtar, "-a", "c");
|
2012-07-27 08:24:12 +00:00
|
|
|
if (bsdtar->readdisk_flags & ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS)
|
2011-12-20 22:47:56 +00:00
|
|
|
only_mode(bsdtar, "--one-file-system", "cru");
|
|
|
|
if (bsdtar->option_fast_read)
|
|
|
|
only_mode(bsdtar, "--fast-read", "xt");
|
2013-03-21 18:59:02 +00:00
|
|
|
if (bsdtar->extract_flags & ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED)
|
|
|
|
only_mode(bsdtar, "--hfsCompression", "x");
|
|
|
|
if (bsdtar->extract_flags & ARCHIVE_EXTRACT_NO_HFS_COMPRESSION)
|
|
|
|
only_mode(bsdtar, "--nopreserveHFSCompression", "x");
|
2012-07-27 08:24:12 +00:00
|
|
|
if (bsdtar->readdisk_flags & ARCHIVE_READDISK_HONOR_NODUMP)
|
2011-12-20 22:47:56 +00:00
|
|
|
only_mode(bsdtar, "--nodump", "cru");
|
|
|
|
if (option_o > 0) {
|
|
|
|
switch (bsdtar->mode) {
|
|
|
|
case 'c':
|
|
|
|
/*
|
|
|
|
* In GNU tar, -o means "old format." The
|
|
|
|
* "ustar" format is the closest thing
|
|
|
|
* supported by libarchive.
|
|
|
|
*/
|
2013-03-21 18:59:02 +00:00
|
|
|
cset_set_format(bsdtar->cset, "ustar");
|
2011-12-20 22:47:56 +00:00
|
|
|
/* TODO: bsdtar->create_format = "v7"; */
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
/* POSIX-compatible behavior. */
|
|
|
|
bsdtar->option_no_owner = 1;
|
|
|
|
bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_OWNER;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
only_mode(bsdtar, "-o", "xc");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bsdtar->option_no_subdirs)
|
|
|
|
only_mode(bsdtar, "-n", "cru");
|
|
|
|
if (bsdtar->option_stdout)
|
|
|
|
only_mode(bsdtar, "-O", "xt");
|
|
|
|
if (bsdtar->option_unlink_first)
|
|
|
|
only_mode(bsdtar, "-U", "x");
|
|
|
|
if (bsdtar->option_warn_links)
|
|
|
|
only_mode(bsdtar, "--check-links", "cr");
|
|
|
|
|
2013-03-21 18:59:02 +00:00
|
|
|
if (option_a && cset_auto_compress(bsdtar->cset, bsdtar->filename)) {
|
|
|
|
/* Ignore specified compressions if auto-compress works. */
|
|
|
|
compression = '\0';
|
|
|
|
compression2 = '\0';
|
|
|
|
}
|
2011-12-20 22:47:56 +00:00
|
|
|
/* Check other parameters only permitted in certain modes. */
|
2013-03-21 18:59:02 +00:00
|
|
|
if (compress_program != NULL) {
|
|
|
|
only_mode(bsdtar, "--use-compress-program", "cxt");
|
|
|
|
cset_add_filter_program(bsdtar->cset, compress_program);
|
|
|
|
/* Ignore specified compressions. */
|
|
|
|
compression = '\0';
|
|
|
|
compression2 = '\0';
|
|
|
|
}
|
|
|
|
if (compression != '\0') {
|
|
|
|
switch (compression) {
|
|
|
|
case 'J': case 'j': case 'y': case 'Z': case 'z':
|
|
|
|
strcpy(buff, "-?");
|
|
|
|
buff[1] = compression;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strcpy(buff, "--");
|
|
|
|
strcat(buff, compression_name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
only_mode(bsdtar, buff, "cxt");
|
|
|
|
cset_add_filter(bsdtar->cset, compression_name);
|
|
|
|
}
|
|
|
|
if (compression2 != '\0') {
|
|
|
|
strcpy(buff, "--");
|
|
|
|
strcat(buff, compression2_name);
|
2011-12-20 22:47:56 +00:00
|
|
|
only_mode(bsdtar, buff, "cxt");
|
2013-03-21 18:59:02 +00:00
|
|
|
cset_add_filter(bsdtar->cset, compression2_name);
|
2011-12-20 22:47:56 +00:00
|
|
|
}
|
2013-03-21 18:59:02 +00:00
|
|
|
if (cset_get_format(bsdtar->cset) != NULL)
|
2011-12-20 22:47:56 +00:00
|
|
|
only_mode(bsdtar, "--format", "cru");
|
|
|
|
if (bsdtar->symlink_mode != '\0') {
|
|
|
|
strcpy(buff, "-?");
|
|
|
|
buff[1] = bsdtar->symlink_mode;
|
|
|
|
only_mode(bsdtar, buff, "cru");
|
|
|
|
}
|
2012-02-08 12:53:14 +00:00
|
|
|
|
|
|
|
/* Filename "-" implies stdio. */
|
|
|
|
if (strcmp(bsdtar->filename, "-") == 0)
|
|
|
|
bsdtar->filename = NULL;
|
2011-12-20 22:47:56 +00:00
|
|
|
|
|
|
|
switch(bsdtar->mode) {
|
|
|
|
case 'c':
|
|
|
|
tar_mode_c(bsdtar);
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
tar_mode_r(bsdtar);
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
tar_mode_t(bsdtar);
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
tar_mode_u(bsdtar);
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
tar_mode_x(bsdtar);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-07-27 08:24:12 +00:00
|
|
|
archive_match_free(bsdtar->matching);
|
2013-03-21 18:59:02 +00:00
|
|
|
#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
|
2011-12-20 22:47:56 +00:00
|
|
|
cleanup_substitution(bsdtar);
|
|
|
|
#endif
|
2013-03-21 18:59:02 +00:00
|
|
|
cset_free(bsdtar->cset);
|
2011-12-20 22:47:56 +00:00
|
|
|
|
|
|
|
if (bsdtar->return_value != 0)
|
|
|
|
lafe_warnc(0,
|
|
|
|
"Error exit delayed from previous errors.");
|
|
|
|
return (bsdtar->return_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_mode(struct bsdtar *bsdtar, char opt)
|
|
|
|
{
|
|
|
|
if (bsdtar->mode != '\0' && bsdtar->mode != opt)
|
|
|
|
lafe_errc(1, 0,
|
|
|
|
"Can't specify both -%c and -%c", opt, bsdtar->mode);
|
|
|
|
bsdtar->mode = opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify that the mode is correct.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
only_mode(struct bsdtar *bsdtar, const char *opt, const char *valid_modes)
|
|
|
|
{
|
|
|
|
if (strchr(valid_modes, bsdtar->mode) == NULL)
|
|
|
|
lafe_errc(1, 0,
|
|
|
|
"Option %s is not permitted in mode -%c",
|
|
|
|
opt, bsdtar->mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
p = lafe_progname;
|
|
|
|
|
|
|
|
fprintf(stderr, "Usage:\n");
|
|
|
|
fprintf(stderr, " List: %s -tf <archive-filename>\n", p);
|
|
|
|
fprintf(stderr, " Extract: %s -xf <archive-filename>\n", p);
|
|
|
|
fprintf(stderr, " Create: %s -cf <archive-filename> [filenames...]\n", p);
|
|
|
|
fprintf(stderr, " Help: %s --help\n", p);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
version(void)
|
|
|
|
{
|
|
|
|
printf("bsdtar %s - %s\n",
|
|
|
|
BSDTAR_VERSION_STRING,
|
2012-02-08 12:53:14 +00:00
|
|
|
archive_version_string());
|
2011-12-20 22:47:56 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *long_help_msg =
|
|
|
|
"First option must be a mode specifier:\n"
|
|
|
|
" -c Create -r Add/Replace -t List -u Update -x Extract\n"
|
|
|
|
"Common Options:\n"
|
|
|
|
" -b # Use # 512-byte records per I/O block\n"
|
|
|
|
" -f <filename> Location of archive (default " _PATH_DEFTAPE ")\n"
|
|
|
|
" -v Verbose\n"
|
|
|
|
" -w Interactive\n"
|
|
|
|
"Create: %p -c [options] [<file> | <dir> | @<archive> | -C <dir> ]\n"
|
|
|
|
" <file>, <dir> add these items to archive\n"
|
|
|
|
" -z, -j, -J, --lzma Compress archive with gzip/bzip2/xz/lzma\n"
|
|
|
|
" --format {ustar|pax|cpio|shar} Select archive format\n"
|
|
|
|
" --exclude <pattern> Skip files that match pattern\n"
|
|
|
|
" -C <dir> Change to <dir> before processing remaining files\n"
|
|
|
|
" @<archive> Add entries from <archive> to output\n"
|
|
|
|
"List: %p -t [options] [<patterns>]\n"
|
|
|
|
" <patterns> If specified, list only entries that match\n"
|
|
|
|
"Extract: %p -x [options] [<patterns>]\n"
|
|
|
|
" <patterns> If specified, extract only entries that match\n"
|
|
|
|
" -k Keep (don't overwrite) existing files\n"
|
|
|
|
" -m Don't restore modification times\n"
|
|
|
|
" -O Write entries to stdout, don't restore to disk\n"
|
|
|
|
" -p Restore permissions (including ACLs, owner, file flags)\n";
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that the word 'bsdtar' will always appear in the first line
|
|
|
|
* of output.
|
|
|
|
*
|
|
|
|
* In particular, /bin/sh scripts that need to test for the presence
|
|
|
|
* of bsdtar can use the following template:
|
|
|
|
*
|
|
|
|
* if (tar --help 2>&1 | grep bsdtar >/dev/null 2>&1 ) then \
|
|
|
|
* echo bsdtar; else echo not bsdtar; fi
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
long_help(void)
|
|
|
|
{
|
|
|
|
const char *prog;
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
prog = lafe_progname;
|
|
|
|
|
|
|
|
fflush(stderr);
|
|
|
|
|
|
|
|
p = (strcmp(prog,"bsdtar") != 0) ? "(bsdtar)" : "";
|
|
|
|
printf("%s%s: manipulate archive files\n", prog, p);
|
|
|
|
|
|
|
|
for (p = long_help_msg; *p != '\0'; p++) {
|
|
|
|
if (*p == '%') {
|
|
|
|
if (p[1] == 'p') {
|
|
|
|
fputs(prog, stdout);
|
|
|
|
p++;
|
|
|
|
} else
|
|
|
|
putchar('%');
|
|
|
|
} else
|
|
|
|
putchar(*p);
|
|
|
|
}
|
|
|
|
version();
|
|
|
|
}
|