libarchive_fe/err.h \
libarchive_fe/lafe_platform.h \
libarchive_fe/line_reader.c \
- libarchive_fe/line_reader.h \
- libarchive_fe/matching.c \
- libarchive_fe/matching.h
+ libarchive_fe/line_reader.h
libarchive_fe_la_CPPFLAGS= -I$(top_srcdir)/libarchive
#
../libarchive_fe/lafe_platform.h
../libarchive_fe/line_reader.c
../libarchive_fe/line_reader.h
- ../libarchive_fe/matching.c
- ../libarchive_fe/matching.h
)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../libarchive_fe)
IF(WIN32 AND NOT CYGWIN)
#include "cpio.h"
#include "err.h"
#include "line_reader.h"
-#include "matching.h"
/* Fixed size of uname/gname caches. */
#define name_cache_size 101
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;
#include "cpio_platform.h"
#include <stdio.h>
-#include "matching.h"
-
/*
* The internal state for the "cpio" program.
*
/* Create a file with the specified contents and report any failures. */
int
assertion_make_file(const char *file, int line,
- const char *path, int mode, const char *contents)
+ const char *path, int mode, int csize, const void *contents)
{
#if defined(_WIN32) && !defined(__CYGWIN__)
/* TODO: Rework this to set file mode as well. */
return (0);
}
if (contents != NULL) {
- if (strlen(contents)
- != fwrite(contents, 1, strlen(contents), f)) {
+ size_t wsize;
+
+ if (csize < 0)
+ wsize = strlen(contents);
+ else
+ wsize = (size_t)csize;
+ if (wsize != fwrite(contents, 1, wsize, f)) {
fclose(f);
failure_start(file, line,
"Could not write file %s", path);
return (0);
}
if (contents != NULL) {
- if ((ssize_t)strlen(contents)
- != write(fd, contents, strlen(contents))) {
+ ssize_t wsize;
+
+ if (csize < 0)
+ wsize = (ssize_t)strlen(contents);
+ else
+ wsize = (ssize_t)csize;
+ if (wsize != write(fd, contents, wsize)) {
close(fd);
- failure_start(file, line, "Could not write to %s", path);
+ failure_start(file, line,
+ "Could not write to %s", path);
failure_finish(NULL);
return (0);
}
return (value);
++tested;
- assertion_make_file(__FILE__, __LINE__, "canSymlink.0", 0644, "a");
+ assertion_make_file(__FILE__, __LINE__, "canSymlink.0", 0644, 1, "a");
/* Note: Cygwin has its own symlink() emulation that does not
* use the Win32 CreateSymbolicLink() function. */
#if defined(_WIN32) && !defined(__CYGWIN__)
const char *path = "cannodumptest";
struct stat sb;
- assertion_make_file(__FILE__, __LINE__, path, 0644, NULL);
+ assertion_make_file(__FILE__, __LINE__, path, 0644, 0, NULL);
if (chflags(path, UF_NODUMP) < 0)
return (0);
if (stat(path, &sb) < 0)
const char *path = "cannodumptest";
int fd, r, flags;
- assertion_make_file(__FILE__, __LINE__, path, 0644, NULL);
+ assertion_make_file(__FILE__, __LINE__, path, 0644, 0, NULL);
fd = open(path, O_RDONLY | O_NONBLOCK);
if (fd < 0)
return (0);
#define assertMakeDir(dirname, mode) \
assertion_make_dir(__FILE__, __LINE__, dirname, mode)
#define assertMakeFile(path, mode, contents) \
- assertion_make_file(__FILE__, __LINE__, path, mode, contents)
+ assertion_make_file(__FILE__, __LINE__, path, mode, -1, contents)
+#define assertMakeBinFile(path, mode, csize, contents) \
+ assertion_make_file(__FILE__, __LINE__, path, mode, csize, contents)
#define assertMakeHardlink(newfile, oldfile) \
assertion_make_hardlink(__FILE__, __LINE__, newfile, oldfile)
#define assertMakeSymlink(newfile, linkto) \
int assertion_is_reg(const char *, int, const char *, int);
int assertion_is_symlink(const char *, int, const char *, const char *);
int assertion_make_dir(const char *, int, const char *, int);
-int assertion_make_file(const char *, int, const char *, int, const char *);
+int assertion_make_file(const char *, int, const char *, int, int, const void *);
int assertion_make_hardlink(const char *, int, const char *newpath, const char *);
int assertion_make_symlink(const char *, int, const char *newpath, const char *);
int assertion_nodump(const char *, int, const char *);
__LA_DECL int archive_match_exclude_pattern(struct archive *, const char *);
__LA_DECL int archive_match_exclude_pattern_w(struct archive *,
const wchar_t *);
+/* Add exclusion pathname pattern from file. */
+__LA_DECL int archive_match_exclude_pattern_from_file(struct archive *,
+ const char *, int _nullSeparator);
+__LA_DECL int archive_match_exclude_pattern_from_file_w(struct archive *,
+ const wchar_t *, int _nullSeparator);
/* Add inclusion pathname pattern. */
__LA_DECL int archive_match_include_pattern(struct archive *, const char *);
__LA_DECL int archive_match_include_pattern_w(struct archive *,
const wchar_t *);
+/* Add inclusion pathname pattern from file. */
+__LA_DECL int archive_match_include_pattern_from_file(struct archive *,
+ const char *, int _nullSeparator);
+__LA_DECL int archive_match_include_pattern_from_file_w(struct archive *,
+ const wchar_t *, int _nullSeparator);
/*
* How to get statistic information for inclusion patterns.
*/
struct match_list inclusion_gnames;
};
+static int add_pattern_from_file(struct archive_match *,
+ struct match_list *, int, const void *, int);
static int add_entry(struct archive_match *, int,
struct archive_entry *);
static int add_owner_id(struct archive_match *, struct id_array *,
return (ARCHIVE_OK);
}
+int
+archive_match_exclude_pattern_from_file(struct archive *_a,
+ const char *pathname, int nullSeparator)
+{
+ struct archive_match *a;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_exclude_pattern_from_file");
+ a = (struct archive_match *)_a;
+
+ return add_pattern_from_file(a, &(a->exclusions), 1, pathname,
+ nullSeparator);
+}
+
+int
+archive_match_exclude_pattern_from_file_w(struct archive *_a,
+ const wchar_t *pathname, int nullSeparator)
+{
+ struct archive_match *a;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_exclude_pattern_from_file_w");
+ a = (struct archive_match *)_a;
+
+ return add_pattern_from_file(a, &(a->exclusions), 0, pathname,
+ nullSeparator);
+}
+
int
archive_match_include_pattern(struct archive *_a, const char *pattern)
{
return (ARCHIVE_OK);
}
+int
+archive_match_include_pattern_from_file(struct archive *_a,
+ const char *pathname, int nullSeparator)
+{
+ struct archive_match *a;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_include_pattern_from_file");
+ a = (struct archive_match *)_a;
+
+ return add_pattern_from_file(a, &(a->inclusions), 1, pathname,
+ nullSeparator);
+}
+
+int
+archive_match_include_pattern_from_file_w(struct archive *_a,
+ const wchar_t *pathname, int nullSeparator)
+{
+ struct archive_match *a;
+
+ archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
+ ARCHIVE_STATE_NEW, "archive_match_include_pattern_from_file_w");
+ a = (struct archive_match *)_a;
+
+ return add_pattern_from_file(a, &(a->inclusions), 0, pathname,
+ nullSeparator);
+}
+
/*
* Test functions for pathname patterns.
*
return (ARCHIVE_OK);
}
+static int
+add_pattern_from_file(struct archive_match *a, struct match_list *mlist,
+ int mbs, const void *pathname, int nullSeparator)
+{
+ struct archive *ar;
+ struct archive_entry *ae;
+ struct archive_string as;
+ const void *buff;
+ size_t size;
+ int64_t offset;
+ int r;
+
+ ar = archive_read_new();
+ if (ar == NULL) {
+ archive_set_error(&(a->archive), ENOMEM, "No memory");
+ return (ARCHIVE_FATAL);
+ }
+ r = archive_read_support_format_raw(ar);
+ if (r != ARCHIVE_OK) {
+ archive_copy_error(&(a->archive), ar);
+ archive_read_free(ar);
+ return (r);
+ }
+ if (mbs)
+ r = archive_read_open_filename(ar, pathname, 512*20);
+ else
+ r = archive_read_open_filename_w(ar, pathname, 512*20);
+ if (r != ARCHIVE_OK) {
+ archive_copy_error(&(a->archive), ar);
+ archive_read_free(ar);
+ return (r);
+ }
+ r = archive_read_next_header(ar, &ae);
+ if (r != ARCHIVE_OK) {
+ archive_copy_error(&(a->archive), ar);
+ archive_read_free(ar);
+ return (r);
+ }
+
+ archive_string_init(&as);
+
+ while ((r = archive_read_data_block(ar, &buff, &size, &offset))
+ == ARCHIVE_OK) {
+ const char *b = (const char *)buff;
+
+ while (size) {
+ const char *s = (const char *)b;
+ size_t length = 0;
+ int found_separator = 0;
+
+ while (length < size) {
+ if (nullSeparator) {
+ if (*b == '\0') {
+ found_separator = 1;
+ break;
+ }
+ } else {
+ if (*b == 0x0d || *b == 0x0a) {
+ found_separator = 1;
+ break;
+ }
+ }
+ b++;
+ length++;
+ }
+ if (!found_separator) {
+ archive_strncat(&as, s, length);
+ /* Read next data block. */
+ break;
+ }
+ b++;
+ size -= length + 1;
+ archive_strncat(&as, s, length);
+
+ /* If the line is not empty, add the pattern. */
+ if (archive_strlen(&as) > 0) {
+ /* Add pattern. */
+ r = add_pattern_mbs(a, mlist, as.s);
+ if (r != ARCHIVE_OK) {
+ archive_read_free(ar);
+ archive_string_free(&as);
+ return (r);
+ }
+ archive_string_empty(&as);
+ }
+ }
+ }
+
+ /* If something error happend, report it immediately. */
+ if (r < ARCHIVE_OK) {
+ archive_copy_error(&(a->archive), ar);
+ archive_read_free(ar);
+ archive_string_free(&as);
+ return (r);
+ }
+
+ /* If the line is not empty, add the pattern. */
+ if (r == ARCHIVE_EOF && archive_strlen(&as) > 0) {
+ /* Add pattern. */
+ r = add_pattern_mbs(a, mlist, as.s);
+ if (r != ARCHIVE_OK) {
+ archive_read_free(ar);
+ archive_string_free(&as);
+ return (r);
+ }
+ }
+ archive_read_free(ar);
+ archive_string_free(&as);
+ return (ARCHIVE_OK);
+}
+
/*
* Test if pathname is excluded by inclusion/exclusion patterns.
*/
/* Create a file with the specified contents and report any failures. */
int
assertion_make_file(const char *file, int line,
- const char *path, int mode, const char *contents)
+ const char *path, int mode, int csize, const void *contents)
{
#if defined(_WIN32) && !defined(__CYGWIN__)
/* TODO: Rework this to set file mode as well. */
return (0);
}
if (contents != NULL) {
- if (strlen(contents)
- != fwrite(contents, 1, strlen(contents), f)) {
+ size_t wsize;
+
+ if (csize < 0)
+ wsize = strlen(contents);
+ else
+ wsize = (size_t)csize;
+ if (wsize != fwrite(contents, 1, wsize, f)) {
fclose(f);
failure_start(file, line,
"Could not write file %s", path);
return (0);
}
if (contents != NULL) {
- if ((ssize_t)strlen(contents)
- != write(fd, contents, strlen(contents))) {
+ ssize_t wsize;
+
+ if (csize < 0)
+ wsize = (ssize_t)strlen(contents);
+ else
+ wsize = (ssize_t)csize;
+ if (wsize != write(fd, contents, wsize)) {
close(fd);
- failure_start(file, line, "Could not write to %s", path);
+ failure_start(file, line,
+ "Could not write to %s", path);
failure_finish(NULL);
return (0);
}
return (value);
++tested;
- assertion_make_file(__FILE__, __LINE__, "canSymlink.0", 0644, "a");
+ assertion_make_file(__FILE__, __LINE__, "canSymlink.0", 0644, 1, "a");
/* Note: Cygwin has its own symlink() emulation that does not
* use the Win32 CreateSymbolicLink() function. */
#if defined(_WIN32) && !defined(__CYGWIN__)
const char *path = "cannodumptest";
struct stat sb;
- assertion_make_file(__FILE__, __LINE__, path, 0644, NULL);
+ assertion_make_file(__FILE__, __LINE__, path, 0644, 0, NULL);
if (chflags(path, UF_NODUMP) < 0)
return (0);
if (stat(path, &sb) < 0)
const char *path = "cannodumptest";
int fd, r, flags;
- assertion_make_file(__FILE__, __LINE__, path, 0644, NULL);
+ assertion_make_file(__FILE__, __LINE__, path, 0644, 0, NULL);
fd = open(path, O_RDONLY | O_NONBLOCK);
if (fd < 0)
return (0);
#define assertMakeDir(dirname, mode) \
assertion_make_dir(__FILE__, __LINE__, dirname, mode)
#define assertMakeFile(path, mode, contents) \
- assertion_make_file(__FILE__, __LINE__, path, mode, contents)
+ assertion_make_file(__FILE__, __LINE__, path, mode, -1, contents)
+#define assertMakeBinFile(path, mode, csize, contents) \
+ assertion_make_file(__FILE__, __LINE__, path, mode, csize, contents)
#define assertMakeHardlink(newfile, oldfile) \
assertion_make_hardlink(__FILE__, __LINE__, newfile, oldfile)
#define assertMakeSymlink(newfile, linkto) \
int assertion_is_reg(const char *, int, const char *, int);
int assertion_is_symlink(const char *, int, const char *, const char *);
int assertion_make_dir(const char *, int, const char *, int);
-int assertion_make_file(const char *, int, const char *, int, const char *);
+int assertion_make_file(const char *, int, const char *, int, int, const void *);
int assertion_make_hardlink(const char *, int, const char *newpath, const char *);
int assertion_make_symlink(const char *, int, const char *newpath, const char *);
int assertion_nodump(const char *, int, const char *);
archive_match_free(m);
}
+static void
+exclusion_from_file(struct archive *m)
+{
+ struct archive_entry *ae;
+
+ if (!assert((ae = archive_entry_new()) != NULL)) {
+ archive_match_free(m);
+ return;
+ }
+
+ /* Test with 'first', which should not be excluded. */
+ archive_entry_copy_pathname(ae, "first");
+ failure("'first' should not be excluded");
+ assertEqualInt(0, archive_match_path_excluded(m, ae));
+ assertEqualInt(0, archive_match_excluded(m, ae));
+ archive_entry_clear(ae);
+ archive_entry_copy_pathname_w(ae, L"first");
+ failure("'first' should not be excluded");
+ assertEqualInt(0, archive_match_path_excluded(m, ae));
+ assertEqualInt(0, archive_match_excluded(m, ae));
+
+ /* Test with 'second', which should be excluded. */
+ archive_entry_copy_pathname(ae, "second");
+ failure("'second' should be excluded");
+ assertEqualInt(1, archive_match_path_excluded(m, ae));
+ assertEqualInt(1, archive_match_excluded(m, ae));
+ archive_entry_clear(ae);
+ archive_entry_copy_pathname_w(ae, L"second");
+ failure("'second' should be excluded");
+ assertEqualInt(1, archive_match_path_excluded(m, ae));
+ assertEqualInt(1, archive_match_excluded(m, ae));
+
+ /* Test with 'third', which should not be excluded. */
+ archive_entry_copy_pathname(ae, "third");
+ failure("'third' should not be excluded");
+ assertEqualInt(0, archive_match_path_excluded(m, ae));
+ assertEqualInt(0, archive_match_excluded(m, ae));
+ archive_entry_clear(ae);
+ archive_entry_copy_pathname_w(ae, L"third");
+ failure("'third' should not be excluded");
+ assertEqualInt(0, archive_match_path_excluded(m, ae));
+ assertEqualInt(0, archive_match_excluded(m, ae));
+
+ /* Test with 'four', which should be excluded. */
+ archive_entry_copy_pathname(ae, "four");
+ failure("'four' should be excluded");
+ assertEqualInt(1, archive_match_path_excluded(m, ae));
+ assertEqualInt(1, archive_match_excluded(m, ae));
+ archive_entry_clear(ae);
+ archive_entry_copy_pathname_w(ae, L"four");
+ failure("'four' should be excluded");
+ assertEqualInt(1, archive_match_path_excluded(m, ae));
+ assertEqualInt(1, archive_match_excluded(m, ae));
+
+ /* Clean up. */
+ archive_entry_free(ae);
+}
+
+static void
+test_exclusion_from_file_mbs(void)
+{
+ struct archive *m;
+
+ /* Test1: read exclusion patterns from file */
+ if (!assert((m = archive_match_new()) != NULL))
+ return;
+ assertEqualIntA(m, 0,
+ archive_match_exclude_pattern_from_file(m, "exclusion", 0));
+ exclusion_from_file(m);
+ /* Clean up. */
+ archive_match_free(m);
+
+ /* Test2: read exclusion patterns in a null separator from file */
+ if (!assert((m = archive_match_new()) != NULL))
+ return;
+ /* Test for pattern reading from file */
+ assertEqualIntA(m, 0,
+ archive_match_exclude_pattern_from_file(m, "exclusion_null", 1));
+ exclusion_from_file(m);
+ /* Clean up. */
+ archive_match_free(m);
+}
+
+static void
+test_exclusion_from_file_wcs(void)
+{
+ struct archive *m;
+
+ /* Test1: read exclusion patterns from file */
+ if (!assert((m = archive_match_new()) != NULL))
+ return;
+ assertEqualIntA(m, 0,
+ archive_match_exclude_pattern_from_file_w(m, L"exclusion", 0));
+ exclusion_from_file(m);
+ /* Clean up. */
+ archive_match_free(m);
+
+ /* Test2: read exclusion patterns in a null separator from file */
+ if (!assert((m = archive_match_new()) != NULL))
+ return;
+ /* Test for pattern reading from file */
+ assertEqualIntA(m, 0,
+ archive_match_exclude_pattern_from_file_w(m, L"exclusion_null", 1));
+ exclusion_from_file(m);
+ /* Clean up. */
+ archive_match_free(m);
+}
+
static void
test_inclusion_mbs(void)
{
archive_match_free(m);
}
+static void
+test_inclusion_from_file_mbs(void)
+{
+ struct archive *m;
+
+ /* Test1: read inclusion patterns from file */
+ if (!assert((m = archive_match_new()) != NULL))
+ return;
+ assertEqualIntA(m, 0,
+ archive_match_include_pattern_from_file(m, "inclusion", 0));
+ exclusion_from_file(m);
+ /* Clean up. */
+ archive_match_free(m);
+
+ /* Test2: read inclusion patterns in a null separator from file */
+ if (!assert((m = archive_match_new()) != NULL))
+ return;
+ assertEqualIntA(m, 0,
+ archive_match_include_pattern_from_file(m, "inclusion_null", 1));
+ exclusion_from_file(m);
+ /* Clean up. */
+ archive_match_free(m);
+}
+
+static void
+test_inclusion_from_file_wcs(void)
+{
+ struct archive *m;
+
+ /* Test1: read inclusion patterns from file */
+ if (!assert((m = archive_match_new()) != NULL))
+ return;
+ /* Test for pattern reading from file */
+ assertEqualIntA(m, 0,
+ archive_match_include_pattern_from_file_w(m, L"inclusion", 0));
+ exclusion_from_file(m);
+ /* Clean up. */
+ archive_match_free(m);
+
+ /* Test2: read inclusion patterns in a null separator from file */
+ if (!assert((m = archive_match_new()) != NULL))
+ return;
+ /* Test for pattern reading from file */
+ assertEqualIntA(m, 0,
+ archive_match_include_pattern_from_file_w(m, L"inclusion_null", 1));
+ exclusion_from_file(m);
+ /* Clean up. */
+ archive_match_free(m);
+}
+
static void
test_exclusion_and_inclusion(void)
{
DEFINE_TEST(test_archive_match_path)
{
+ /* Make exclusion sample files which contain exclusion patterns. */
+ assertMakeFile("exclusion", 0666, "second\nfour\n");
+ assertMakeBinFile("exclusion_null", 0666, 12, "second\0four\0");
+ /* Make inclusion sample files which contain inclusion patterns. */
+ assertMakeFile("inclusion", 0666, "first\nthird\n");
+ assertMakeBinFile("inclusion_null", 0666, 12, "first\0third\0");
+
test_exclusion_mbs();
test_exclusion_wcs();
+ test_exclusion_from_file_mbs();
+ test_exclusion_from_file_wcs();
test_inclusion_mbs();
test_inclusion_wcs();
+ test_inclusion_from_file_mbs();
+ test_inclusion_from_file_wcs();
test_exclusion_and_inclusion();
}
+++ /dev/null
-/*-
- * Copyright (c) 2003-2007 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 "lafe_platform.h"
-__FBSDID("$FreeBSD: src/usr.bin/cpio/matching.c,v 1.2 2008/06/21 02:20:20 kientzle Exp $");
-
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
-
-#include "archive.h"
-#include "err.h"
-#include "line_reader.h"
-#include "matching.h"
-
-/*
- * Utility functions to manage exclusion/inclusion patterns
- */
-
-int
-lafe_exclude_from_file(struct archive *matching, const char *pathname)
-{
- struct lafe_line_reader *lr;
- const char *p;
- int ret = 0;
-
- lr = lafe_line_reader(pathname, 0);
- while ((p = lafe_line_reader_next(lr)) != NULL) {
- ret = archive_match_exclude_pattern(matching, p);
- if (ret == ARCHIVE_FATAL)
- lafe_errc(1, errno, "Out of memory");
- }
- lafe_line_reader_free(lr);
- return (ret);
-}
-
-int
-lafe_include_from_file(struct archive *matching, const char *pathname,
- int nullSeparator)
-{
- struct lafe_line_reader *lr;
- const char *p;
- int ret = 0;
-
- lr = lafe_line_reader(pathname, nullSeparator);
- while ((p = lafe_line_reader_next(lr)) != NULL) {
- ret = archive_match_include_pattern(matching, p);
- if (ret == ARCHIVE_FATAL)
- lafe_errc(1, errno, "Out of memory");
- }
- lafe_line_reader_free(lr);
- return (ret);
-}
-
+++ /dev/null
-/*-
- * Copyright (c) 2003-2007 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
- * in this position and unchanged.
- * 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$
- */
-
-#ifndef MATCHING_H
-#define MATCHING_H
-
-#include "archive.h"
-
-int lafe_exclude_from_file(struct archive *, const char *pathname);
-int lafe_include_from_file(struct archive *,
- const char *pathname, int nullSeparator);
-
-#endif
../libarchive_fe/lafe_platform.h
../libarchive_fe/line_reader.c
../libarchive_fe/line_reader.h
- ../libarchive_fe/matching.c
- ../libarchive_fe/matching.h
)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../libarchive_fe)
IF(WIN32 AND NOT CYGWIN)
bsdtar->option_interactive = 1;
break;
case 'X': /* GNU tar */
- if (lafe_exclude_from_file(bsdtar->matching,
- bsdtar->argument))
- lafe_errc(1, 0,
- "failed to process exclusions from file %s",
- bsdtar->argument);
+ 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));
break;
case 'x': /* SUSv2 */
set_mode(bsdtar, opt);
#include "bsdtar_platform.h"
#include <stdio.h>
-#include "matching.h"
-
#define DEFAULT_BYTES_PER_BLOCK (20*512)
/*
}
if (bsdtar->names_from_file != NULL)
- lafe_include_from_file(bsdtar->matching,
- bsdtar->names_from_file, bsdtar->option_null);
+ if (archive_match_include_pattern_from_file(
+ bsdtar->matching, bsdtar->names_from_file,
+ bsdtar->option_null) != ARCHIVE_OK)
+ lafe_errc(1, 0, "Error inclusion pattern: %s",
+ archive_error_string(bsdtar->matching));
a = archive_read_new();
if (bsdtar->compress_program != NULL)
/* Create a file with the specified contents and report any failures. */
int
assertion_make_file(const char *file, int line,
- const char *path, int mode, const char *contents)
+ const char *path, int mode, int csize, const void *contents)
{
#if defined(_WIN32) && !defined(__CYGWIN__)
/* TODO: Rework this to set file mode as well. */
return (0);
}
if (contents != NULL) {
- if (strlen(contents)
- != fwrite(contents, 1, strlen(contents), f)) {
+ size_t wsize;
+
+ if (csize < 0)
+ wsize = strlen(contents);
+ else
+ wsize = (size_t)csize;
+ if (wsize != fwrite(contents, 1, wsize, f)) {
fclose(f);
failure_start(file, line,
"Could not write file %s", path);
return (0);
}
if (contents != NULL) {
- if ((ssize_t)strlen(contents)
- != write(fd, contents, strlen(contents))) {
+ ssize_t wsize;
+
+ if (csize < 0)
+ wsize = (ssize_t)strlen(contents);
+ else
+ wsize = (ssize_t)csize;
+ if (wsize != write(fd, contents, wsize)) {
close(fd);
- failure_start(file, line, "Could not write to %s", path);
+ failure_start(file, line,
+ "Could not write to %s", path);
failure_finish(NULL);
return (0);
}
return (value);
++tested;
- assertion_make_file(__FILE__, __LINE__, "canSymlink.0", 0644, "a");
+ assertion_make_file(__FILE__, __LINE__, "canSymlink.0", 0644, 1, "a");
/* Note: Cygwin has its own symlink() emulation that does not
* use the Win32 CreateSymbolicLink() function. */
#if defined(_WIN32) && !defined(__CYGWIN__)
const char *path = "cannodumptest";
struct stat sb;
- assertion_make_file(__FILE__, __LINE__, path, 0644, NULL);
+ assertion_make_file(__FILE__, __LINE__, path, 0644, 0, NULL);
if (chflags(path, UF_NODUMP) < 0)
return (0);
if (stat(path, &sb) < 0)
const char *path = "cannodumptest";
int fd, r, flags;
- assertion_make_file(__FILE__, __LINE__, path, 0644, NULL);
+ assertion_make_file(__FILE__, __LINE__, path, 0644, 0, NULL);
fd = open(path, O_RDONLY | O_NONBLOCK);
if (fd < 0)
return (0);
#define assertMakeDir(dirname, mode) \
assertion_make_dir(__FILE__, __LINE__, dirname, mode)
#define assertMakeFile(path, mode, contents) \
- assertion_make_file(__FILE__, __LINE__, path, mode, contents)
+ assertion_make_file(__FILE__, __LINE__, path, mode, -1, contents)
+#define assertMakeBinFile(path, mode, csize, contents) \
+ assertion_make_file(__FILE__, __LINE__, path, mode, csize, contents)
#define assertMakeHardlink(newfile, oldfile) \
assertion_make_hardlink(__FILE__, __LINE__, newfile, oldfile)
#define assertMakeSymlink(newfile, linkto) \
int assertion_is_reg(const char *, int, const char *, int);
int assertion_is_symlink(const char *, int, const char *, const char *);
int assertion_make_dir(const char *, int, const char *, int);
-int assertion_make_file(const char *, int, const char *, int, const char *);
+int assertion_make_file(const char *, int, const char *, int, int, const void *);
int assertion_make_hardlink(const char *, int, const char *newpath, const char *);
int assertion_make_symlink(const char *, int, const char *newpath, const char *);
int assertion_nodump(const char *, int, const char *);