enable only including files and directories older than specified date or file.
tar/test/test_option_n.c \
tar/test/test_option_newer_than.c \
tar/test/test_option_nodump.c \
+ tar/test/test_option_older_than.c \
tar/test/test_option_q.c \
tar/test/test_option_r.c \
tar/test/test_option_s.c \
.\"
.\" $FreeBSD$
.\"
-.Dd December 24, 2011
+.Dd October 3, 2012
.Dt TAR 1
.Os
.Sh NAME
(c, r, u mode)
A synonym for
.Fl Fl format Ar ustar
+.It Fl Fl older Ar date
+(c, r, u modes only)
+Only include files and directories older than the specified date.
+This compares ctime entries.
+.It Fl Fl older-mtime Ar date
+(c, r, u modes only)
+Like
+.Fl Fl older ,
+except it compares mtime entries instead of ctime entries.
+.It Fl Fl older-than Pa file
+(c, r, u modes only)
+Only include files and directories older than the specified file.
+This compares ctime entries.
+.It Fl Fl older-mtime-than Pa file
+(c, r, u modes only)
+Like
+.Fl Fl older-than ,
+except it compares mtime entries instead of ctime entries.
.It Fl Fl one-file-system
(c, r, and u modes)
Do not cross mount points.
* --newer-?time='date' Only files newer than 'date'
* --newer-?time-than='file' Only files newer than time
* on specified file (useful for incremental backups)
- * TODO: Add corresponding "older" options to reverse these.
*/
case OPTION_NEWER_CTIME: /* GNU tar */
if (archive_match_include_date(bsdtar->matching,
case 'o': /* SUSv2 and GNU conflict here, but not fatally */
option_o = 1; /* Record it and resolve it later. */
break;
+ /*
+ * 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;
case OPTION_ONE_FILE_SYSTEM: /* GNU tar */
bsdtar->readdisk_flags |=
ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS;
OPTION_NO_SAME_PERMISSIONS,
OPTION_NULL,
OPTION_NUMERIC_OWNER,
+ OPTION_OLDER_CTIME,
+ OPTION_OLDER_CTIME_THAN,
+ OPTION_OLDER_MTIME,
+ OPTION_OLDER_MTIME_THAN,
OPTION_ONE_FILE_SYSTEM,
OPTION_OPTIONS,
OPTION_POSIX,
{ "norecurse", 0, 'n' },
{ "null", 0, OPTION_NULL },
{ "numeric-owner", 0, OPTION_NUMERIC_OWNER },
+ { "older", 1, OPTION_OLDER_CTIME },
+ { "older-ctime", 1, OPTION_OLDER_CTIME },
+ { "older-ctime-than", 1, OPTION_OLDER_CTIME_THAN },
+ { "older-mtime", 1, OPTION_OLDER_MTIME },
+ { "older-mtime-than", 1, OPTION_OLDER_MTIME_THAN },
+ { "older-than", 1, OPTION_OLDER_CTIME_THAN },
{ "one-file-system", 0, OPTION_ONE_FILE_SYSTEM },
{ "options", 1, OPTION_OPTIONS },
{ "posix", 0, OPTION_POSIX },
test_option_n.c
test_option_newer_than.c
test_option_nodump.c
+ test_option_older_than.c
test_option_q.c
test_option_r.c
test_option_s.c
--- /dev/null
+/*-
+ * Copyright (c) 2010 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * 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 "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_older_than)
+{
+ struct stat st;
+
+ /*
+ * Basic test of --older-than.
+ * First, create three files with different mtimes.
+ * Create test1.tar with --older-than, test2.tar without.
+ */
+ assertMakeDir("test1in", 0755);
+ assertChdir("test1in");
+ assertMakeDir("a", 0755);
+ assertMakeDir("a/b", 0755);
+ assertMakeFile("old.txt", 0644, "old.txt");
+ assertMakeFile("a/b/old.txt", 0644, "old file in old directory");
+ assertEqualInt(0, stat("old.txt", &st));
+ sleepUntilAfter(st.st_mtime);
+ assertMakeFile("middle.txt", 0644, "middle.txt");
+ assertEqualInt(0, stat("middle.txt", &st));
+ sleepUntilAfter(st.st_mtime);
+ assertMakeFile("new.txt", 0644, "new");
+ assertMakeFile("a/b/new.txt", 0644, "new file in old directory");
+
+ /* Test --older-than on create */
+ assertEqualInt(0,
+ systemf("%s -cf ../test1.tar --older-than middle.txt *.txt a",
+ testprog));
+ assertEqualInt(0, systemf("%s -cf ../test2.tar *.txt a", testprog));
+ assertChdir("..");
+
+ /* Extract test1.tar to a clean dir and verify what got archived. */
+ assertMakeDir("test1out", 0755);
+ assertChdir("test1out");
+ assertEqualInt(0, systemf("%s xf ../test1.tar", testprog));
+ assertFileNotExists("new.txt");
+ assertFileNotExists("a/b/new.txt");
+ assertFileNotExists("middle.txt");
+ assertFileExists("old.txt");
+ assertFileExists("a/b/old.txt");
+ assertChdir("..");
+
+ /* Extract test2.tar to a clean dir with --older-than and verify. */
+ assertMakeDir("test2out", 0755);
+ assertChdir("test2out");
+ assertEqualInt(0,
+ systemf("%s xf ../test2.tar --older-than ../test1in/middle.txt",
+ testprog));
+ assertFileNotExists("new.txt");
+ assertFileNotExists("a/b/new.txt");
+ assertFileNotExists("middle.txt");
+ assertFileExists("old.txt");
+ assertFileExists("a/b/old.txt");
+ assertChdir("..");
+}