~strahinja/sbase

sbase/patches/0001-Add-n-equivalent-of-no-recursion.patch -rw-r--r-- 2.4 KiB
a373bb88Страхиња Радић Reverted patches for master branch 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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?= <contact@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: Страхиња Радић <contact@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