2004-04-05 21:32:18 +00:00
|
|
|
/*-
|
2007-01-09 08:12:17 +00:00
|
|
|
* Copyright (c) 2003-2007 Tim Kientzle
|
2004-04-05 21:32:18 +00:00
|
|
|
* 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
|
2007-01-09 08:12:17 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer.
|
2004-04-05 21:32:18 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
2006-03-21 17:03:51 +00:00
|
|
|
#include "bsdtar_platform.h"
|
2004-04-05 21:32:18 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2004-06-07 03:19:57 +00:00
|
|
|
#define DEFAULT_BYTES_PER_BLOCK (20*512)
|
|
|
|
|
2004-04-05 21:32:18 +00:00
|
|
|
/*
|
2004-04-15 22:37:54 +00:00
|
|
|
* The internal state for the "bsdtar" program.
|
|
|
|
*
|
|
|
|
* Keeping all of the state in a structure like this simplifies memory
|
|
|
|
* leak testing (at exit, anything left on the heap is suspect). A
|
|
|
|
* pointer to this structure is passed to most bsdtar internal
|
|
|
|
* functions.
|
2004-04-05 21:32:18 +00:00
|
|
|
*/
|
|
|
|
struct bsdtar {
|
|
|
|
/* Options */
|
|
|
|
const char *filename; /* -f filename */
|
|
|
|
const char *create_format; /* -F format */
|
2004-08-08 05:50:10 +00:00
|
|
|
char *pending_chdir; /* -C dir */
|
2004-04-08 06:12:01 +00:00
|
|
|
const char *names_from_file; /* -T file */
|
2005-03-13 18:36:24 +00:00
|
|
|
time_t newer_ctime_sec; /* --newer/--newer-than */
|
|
|
|
long newer_ctime_nsec; /* --newer/--newer-than */
|
|
|
|
time_t newer_mtime_sec; /* --newer-mtime */
|
|
|
|
long newer_mtime_nsec; /* --newer-mtime-than */
|
2004-04-05 21:32:18 +00:00
|
|
|
int bytes_per_block; /* -b block_size */
|
|
|
|
int verbose; /* -v */
|
|
|
|
int extract_flags; /* Flags for extract operation */
|
2005-03-13 04:12:30 +00:00
|
|
|
int strip_components; /* Remove this many leading dirs */
|
2004-08-08 05:10:10 +00:00
|
|
|
char mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */
|
2004-04-05 21:32:18 +00:00
|
|
|
char symlink_mode; /* H or L, per BSD conventions */
|
|
|
|
char create_compression; /* j, y, or z */
|
2007-05-29 05:39:10 +00:00
|
|
|
const char *compress_program;
|
2004-04-05 21:32:18 +00:00
|
|
|
char option_absolute_paths; /* -P */
|
2008-03-15 03:06:46 +00:00
|
|
|
char option_chroot; /* --chroot */
|
2006-12-23 07:01:59 +00:00
|
|
|
char option_dont_traverse_mounts; /* --one-file-system */
|
2004-04-05 21:32:18 +00:00
|
|
|
char option_fast_read; /* --fast-read */
|
2009-04-17 03:45:15 +00:00
|
|
|
const char *option_options; /* --options */
|
2004-04-05 21:32:18 +00:00
|
|
|
char option_honor_nodump; /* --nodump */
|
|
|
|
char option_interactive; /* -w */
|
2004-07-17 04:17:50 +00:00
|
|
|
char option_no_owner; /* -o */
|
2006-12-23 07:01:59 +00:00
|
|
|
char option_no_subdirs; /* -n */
|
2004-06-27 06:29:03 +00:00
|
|
|
char option_null; /* --null */
|
2008-05-26 17:10:10 +00:00
|
|
|
char option_numeric_owner; /* --numeric-owner */
|
2006-12-23 07:01:59 +00:00
|
|
|
char option_stdout; /* -O */
|
2004-08-07 19:25:34 +00:00
|
|
|
char option_totals; /* --totals */
|
2004-05-17 03:33:06 +00:00
|
|
|
char option_unlink_first; /* -U */
|
2006-12-23 07:01:59 +00:00
|
|
|
char option_warn_links; /* --check-links */
|
2004-07-15 03:14:46 +00:00
|
|
|
char day_first; /* show day before month in -tv output */
|
2004-04-05 21:32:18 +00:00
|
|
|
|
|
|
|
/* If >= 0, then close this when done. */
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
/* Miscellaneous state information */
|
2004-06-27 06:29:03 +00:00
|
|
|
struct archive *archive;
|
2004-05-17 05:44:53 +00:00
|
|
|
const char *progname;
|
2004-04-05 21:32:18 +00:00
|
|
|
int argc;
|
|
|
|
char **argv;
|
2008-11-08 04:43:24 +00:00
|
|
|
const char *optarg;
|
2004-04-15 22:37:54 +00:00
|
|
|
size_t gs_width; /* For 'list_item' in read.c */
|
|
|
|
size_t u_width; /* for 'list_item' in read.c */
|
|
|
|
uid_t user_uid; /* UID running this program */
|
2004-05-27 04:30:59 +00:00
|
|
|
int return_value; /* Value returned by main() */
|
|
|
|
char warned_lead_slash; /* Already displayed warning */
|
2004-06-27 06:29:03 +00:00
|
|
|
char next_line_is_dir; /* Used for -C parsing in -cT */
|
2004-04-05 21:32:18 +00:00
|
|
|
|
2004-07-24 22:13:44 +00:00
|
|
|
/*
|
2004-04-15 22:37:54 +00:00
|
|
|
* Data for various subsystems. Full definitions are located in
|
|
|
|
* the file where they are used.
|
|
|
|
*/
|
2009-03-08 05:22:50 +00:00
|
|
|
struct archive *diskreader; /* for write.c */
|
|
|
|
struct archive_entry_linkresolver *resolver; /* for write.c */
|
2004-04-15 22:37:54 +00:00
|
|
|
struct archive_dir *archive_dir; /* for write.c */
|
2004-05-17 05:02:39 +00:00
|
|
|
struct name_cache *gname_cache; /* for write.c */
|
2008-07-05 08:03:08 +00:00
|
|
|
char *buff; /* for write.c */
|
2004-04-15 22:37:54 +00:00
|
|
|
struct matching *matching; /* for matching.c */
|
2004-05-02 00:43:02 +00:00
|
|
|
struct security *security; /* for read.c */
|
2004-05-17 05:02:39 +00:00
|
|
|
struct name_cache *uname_cache; /* for write.c */
|
2008-05-22 21:08:36 +00:00
|
|
|
struct siginfo_data *siginfo; /* for siginfo.c */
|
2008-05-26 17:10:10 +00:00
|
|
|
struct substitution *substitution; /* for subst.c */
|
2004-04-05 21:32:18 +00:00
|
|
|
};
|
|
|
|
|
2008-11-08 04:43:24 +00:00
|
|
|
/* Fake short equivalents for long options that otherwise lack them. */
|
|
|
|
enum {
|
|
|
|
OPTION_CHECK_LINKS = 1,
|
|
|
|
OPTION_CHROOT,
|
|
|
|
OPTION_EXCLUDE,
|
|
|
|
OPTION_FORMAT,
|
2009-04-17 03:45:15 +00:00
|
|
|
OPTION_OPTIONS,
|
2008-11-08 04:43:24 +00:00
|
|
|
OPTION_HELP,
|
|
|
|
OPTION_INCLUDE,
|
|
|
|
OPTION_KEEP_NEWER_FILES,
|
2009-04-17 03:45:15 +00:00
|
|
|
OPTION_LZMA,
|
2008-11-08 04:43:24 +00:00
|
|
|
OPTION_NEWER_CTIME,
|
|
|
|
OPTION_NEWER_CTIME_THAN,
|
|
|
|
OPTION_NEWER_MTIME,
|
|
|
|
OPTION_NEWER_MTIME_THAN,
|
|
|
|
OPTION_NODUMP,
|
|
|
|
OPTION_NO_SAME_OWNER,
|
|
|
|
OPTION_NO_SAME_PERMISSIONS,
|
|
|
|
OPTION_NULL,
|
|
|
|
OPTION_NUMERIC_OWNER,
|
|
|
|
OPTION_ONE_FILE_SYSTEM,
|
|
|
|
OPTION_POSIX,
|
2009-04-17 03:45:15 +00:00
|
|
|
OPTION_SAME_OWNER,
|
2008-11-08 04:43:24 +00:00
|
|
|
OPTION_STRIP_COMPONENTS,
|
|
|
|
OPTION_TOTALS,
|
|
|
|
OPTION_USE_COMPRESS_PROGRAM,
|
|
|
|
OPTION_VERSION
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-05-17 05:44:53 +00:00
|
|
|
void bsdtar_errc(struct bsdtar *, int _eval, int _code,
|
2008-12-06 07:37:14 +00:00
|
|
|
const char *fmt, ...) __LA_DEAD;
|
2008-11-08 04:43:24 +00:00
|
|
|
int bsdtar_getopt(struct bsdtar *);
|
2004-05-17 05:44:53 +00:00
|
|
|
void bsdtar_warnc(struct bsdtar *, int _code, const char *fmt, ...);
|
2004-04-05 21:32:18 +00:00
|
|
|
void cleanup_exclusions(struct bsdtar *);
|
2004-08-08 05:50:10 +00:00
|
|
|
void do_chdir(struct bsdtar *);
|
2005-04-17 17:20:54 +00:00
|
|
|
int edit_pathname(struct bsdtar *, struct archive_entry *);
|
2004-06-27 06:29:03 +00:00
|
|
|
int exclude(struct bsdtar *, const char *pattern);
|
|
|
|
int exclude_from_file(struct bsdtar *, const char *pathname);
|
2004-04-05 21:32:18 +00:00
|
|
|
int excluded(struct bsdtar *, const char *pathname);
|
2004-06-27 06:29:03 +00:00
|
|
|
int include(struct bsdtar *, const char *pattern);
|
|
|
|
int include_from_file(struct bsdtar *, const char *pathname);
|
2007-03-11 10:36:42 +00:00
|
|
|
int pathcmp(const char *a, const char *b);
|
2004-06-27 06:29:03 +00:00
|
|
|
int process_lines(struct bsdtar *bsdtar, const char *pathname,
|
|
|
|
int (*process)(struct bsdtar *, const char *));
|
2004-04-05 21:32:18 +00:00
|
|
|
void safe_fprintf(FILE *, const char *fmt, ...);
|
2004-08-08 05:50:10 +00:00
|
|
|
void set_chdir(struct bsdtar *, const char *newdir);
|
2008-05-18 06:24:47 +00:00
|
|
|
void siginfo_init(struct bsdtar *);
|
|
|
|
void siginfo_setinfo(struct bsdtar *, const char * oper,
|
|
|
|
const char * path, int64_t size);
|
|
|
|
void siginfo_printinfo(struct bsdtar *, off_t progress);
|
|
|
|
void siginfo_done(struct bsdtar *);
|
2004-04-05 21:32:18 +00:00
|
|
|
void tar_mode_c(struct bsdtar *bsdtar);
|
|
|
|
void tar_mode_r(struct bsdtar *bsdtar);
|
|
|
|
void tar_mode_t(struct bsdtar *bsdtar);
|
|
|
|
void tar_mode_u(struct bsdtar *bsdtar);
|
|
|
|
void tar_mode_x(struct bsdtar *bsdtar);
|
|
|
|
int unmatched_inclusions(struct bsdtar *bsdtar);
|
2008-05-26 17:10:10 +00:00
|
|
|
int unmatched_inclusions_warn(struct bsdtar *bsdtar, const char *msg);
|
2004-05-17 05:44:53 +00:00
|
|
|
void usage(struct bsdtar *);
|
2004-04-05 21:32:18 +00:00
|
|
|
int yes(const char *fmt, ...);
|
|
|
|
|
2008-05-26 17:10:10 +00:00
|
|
|
#if HAVE_REGEX_H
|
|
|
|
void add_substitution(struct bsdtar *, const char *);
|
|
|
|
int apply_substitution(struct bsdtar *, const char *, char **, int);
|
|
|
|
void cleanup_substitution(struct bsdtar *);
|
|
|
|
#endif
|