Skip to content

Commit 66fabe6

Browse files
committed
Allow tar -T /dev/null to create an empty archive.
1 parent 1f4ac17 commit 66fabe6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

tests/tar.test

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ testing "-T newline" "$TAR -T input | LST" \
4343
"-rw-rw-r-- root/sys 0 2009-02-13 23:31 file1\n-rw-rw-r-- root/sys 0 2009-02-13 23:31 file2\n" "file1\nfile2\n" ""
4444
testing "-T null" "$TAR --null -T input | LST" \
4545
"-rw-rw-r-- root/sys 0 2009-02-13 23:31 file1\n-rw-rw-r-- root/sys 0 2009-02-13 23:31 file2\n" "file1\0file2\0" ""
46+
testing "empty -T creates empty tarball" "tar c | SUM 2" \
47+
"da39a3ee5e6b4b0d3255bfef95601890afd80709\n" "" ""
4648

4749
# User "root" is UID 0 and group "sys" is GID 3 (on Linux, BSD, and Mac),
4850
# inherited from Bell Labs Unix v7

toys/posix/tar.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ void tar_main(void)
10451045

10461046
// If include file list empty, don't create empty archive
10471047
if (FLAG(c)) {
1048-
if (!TT.incl) error_exit("empty archive");
1048+
if (!TT.incl && !FLAG(T)) error_exit("empty archive");
10491049
TT.fd = 1;
10501050
}
10511051

@@ -1194,7 +1194,7 @@ void tar_main(void)
11941194
close(TT.fd);
11951195
TT.fd = pipefd[0];
11961196
}
1197-
do {
1197+
if (dl) do {
11981198
TT.warn = 1;
11991199
dirtree_flagread(dl->data,
12001200
DIRTREE_SYMFOLLOW*FLAG(h)|DIRTREE_BREADTH*(FLAG(sort)|FLAG(s)),

0 commit comments

Comments
 (0)