I have made another patch for tar, this is more "quality of life" oriented. It adds the option -n to tar, which is equivalent to GNU tar's --no-recursion. This comes in handy when tar is used together with find(1) to filter and hand-pick the list of files to be archived.
The patch is here: https://git.sr.ht/~strahinja/sbase/tree/master/item/patches/0001-Add-n-equivalent-of-no-recursion.patch and I have also attached it to this message for review.
From 3c58d0ce54200f001309da369a54cb58a4e7ddf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D1=80=D0=B0=D1=85=D0=B8=D1=9A=D0=B0=20=D0=A0?= =?UTF-8?q?=D0=B0=D0=B4=D0=B8=D1=9B?= <cont...@strahinja.org> Date: Mon, 1 Aug 2022 09:21:08 +0200 Subject: [PATCH] Add -n (equivalent of --no-recursion) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Страхиња Радић <cont...@strahinja.org> --- tar.1 | 5 +++++ tar.c | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/tar.1 b/tar.1 index be2ebea..f7d27a0 100644 --- a/tar.1 +++ b/tar.1 @@ -15,6 +15,7 @@ .Op Fl C Ar dir .Op Fl J | Fl Z | Fl a | Fl j | Fl z .Op Fl h +.Op Fl n .Fl c Ar path ... .Op Fl f Ar file .Sh DESCRIPTION @@ -36,6 +37,10 @@ as input | output archive instead of stdin | stdout. If '-', stdin | stdout is used. .It Fl m Do not preserve modification time. +.It Fl n +Do not recurse into directories. This flag is an extension to standard, +equivalent to GNU tar's +.Fl -no-recursion . .It Fl t List all files in the archive. .It Fl x diff --git a/tar.c b/tar.c index d3a9f3b..3f8daf9 100644 --- a/tar.c +++ b/tar.c @@ -63,7 +63,7 @@ static int tarfd; static ino_t tarinode; static dev_t tardev; -static int mflag, vflag; +static int mflag, nflag, vflag; static int filtermode; static const char *filtertool; @@ -374,7 +374,7 @@ c(int dirfd, const char *name, struct stat *st, void *data, struct recursor *r) if (vflag) puts(r->path); - if (S_ISDIR(st->st_mode)) + if (S_ISDIR(st->st_mode) && !nflag) recurse(dirfd, name, NULL, r); } @@ -507,7 +507,7 @@ usage(void) { eprintf("usage: %s [-C dir] [-J | -Z | -a | -j | -z] -x [-m | -t] " "[-f file] [file ...]\n" - " %s [-C dir] [-J | -Z | -a | -j | -z] [-h] -c path ... " + " %s [-C dir] [-J | -Z | -a | -j | -z] [-h] [-n] -c path ... " "[-f file]\n", argv0, argv0); } @@ -534,6 +534,9 @@ main(int argc, char *argv[]) case 'm': mflag = 1; break; + case 'n': + nflag = 1; + break; case 'J': case 'Z': case 'a': @@ -577,7 +580,12 @@ main(int argc, char *argv[]) if (chdir(dir) < 0) eprintf("chdir %s:", dir); for (; *argv; argc--, argv++) - recurse(AT_FDCWD, *argv, NULL, &r); + { + if (!nflag) + recurse(AT_FDCWD, *argv, NULL, &r); + else + archive(*argv); + } break; case 't': case 'x': -- 2.37.1
signature.asc
Description: PGP signature