summaryrefslogtreecommitdiff
blob: 7f070a899d782ea00927103791b15f95c4ee7356 (plain)
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
http://bugs.gentoo.org/265425

From 1a80c89ee88357137b598fa3357b576933c5746c Mon Sep 17 00:00:00 2001
From: Andreas Gruenbacher <agruen@suse.de>
Date: Tue, 23 Jun 2009 00:17:49 +0200
Subject: [PATCH] Introduce new WALK_TREE_DEREFERENCE_TOPLEVEL flag

This flag indicates to dereference top-level symlinks. (If non
top-level symlinks should be stat()ed as well, the
WALK_TREE_DEREFERENCE flag must be specified.)
---
 include/walk_tree.h |    9 +++++----
 libmisc/walk_tree.c |    4 +++-
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/include/walk_tree.h b/include/walk_tree.h
index 53a8fc5..9f1ec34 100644
--- a/include/walk_tree.h
+++ b/include/walk_tree.h
@@ -20,10 +20,11 @@
 #ifndef __WALK_TREE_H
 #define __WALK_TREE_H
 
-#define WALK_TREE_RECURSIVE	0x1
-#define WALK_TREE_PHYSICAL	0x2
-#define WALK_TREE_LOGICAL	0x4
-#define WALK_TREE_DEREFERENCE	0x8
+#define WALK_TREE_RECURSIVE		0x01
+#define WALK_TREE_PHYSICAL		0x02
+#define WALK_TREE_LOGICAL		0x04
+#define WALK_TREE_DEREFERENCE		0x08
+#define WALK_TREE_DEREFERENCE_TOPLEVEL	0x10
 
 #define WALK_TREE_TOPLEVEL	0x100
 #define WALK_TREE_SYMLINK	0x200
diff --git a/libmisc/walk_tree.c b/libmisc/walk_tree.c
index 2777145..30ff92a 100644
--- a/libmisc/walk_tree.c
+++ b/libmisc/walk_tree.c
@@ -78,7 +78,9 @@ static int walk_tree_rec(const char *path, int walk_flags,
 		return func(path, NULL, flags | WALK_TREE_FAILED, arg);
 	if (S_ISLNK(st.st_mode)) {
 		flags |= WALK_TREE_SYMLINK;
-		if (flags & WALK_TREE_DEREFERENCE) {
+		if ((flags & WALK_TREE_DEREFERENCE) ||
+		    ((flags & WALK_TREE_TOPLEVEL) &&
+		     (flags & WALK_TREE_DEREFERENCE_TOPLEVEL))) {
 			if (stat(path, &st) != 0)
 				return func(path, NULL,
 					    flags | WALK_TREE_FAILED, arg);
-- 
1.6.3.3