Zdenek Prikryl ac5510
--- attr-2.4.32/getfattr/getfattr.c.recursive	2006-06-20 08:51:25.000000000 +0200
Zdenek Prikryl ac5510
+++ attr-2.4.32/getfattr/getfattr.c	2007-09-11 04:00:49.000000000 +0200
Zdenek Prikryl ac5510
@@ -410,6 +410,38 @@ void help(void)
Zdenek Prikryl ac5510
 "      --help              this help text\n"));
Zdenek Prikryl ac5510
 }
Zdenek Prikryl ac5510
 
Zdenek Prikryl ac5510
+char *resolve_symlinks(const char *file)
Zdenek Prikryl ac5510
+{
Zdenek Prikryl ac5510
+	static char buffer[4096];
Zdenek Prikryl ac5510
+	struct stat stat;
Zdenek Prikryl ac5510
+	char *path = NULL;
Zdenek Prikryl ac5510
+
Zdenek Prikryl ac5510
+	if (lstat(file, &stat) == -1)
Zdenek Prikryl ac5510
+		return path;
Zdenek Prikryl ac5510
+
Zdenek Prikryl ac5510
+	if (S_ISLNK(stat.st_mode) && !opt_walk_physical)
Zdenek Prikryl ac5510
+		path = realpath(file, buffer);
Zdenek Prikryl ac5510
+	else
Zdenek Prikryl ac5510
+		path = (char *)file;    /* not a symlink, use given path */
Zdenek Prikryl ac5510
+
Zdenek Prikryl ac5510
+	return path;
Zdenek Prikryl ac5510
+}
Zdenek Prikryl ac5510
+
Zdenek Prikryl ac5510
+int walk_tree(const char *file)
Zdenek Prikryl ac5510
+{
Zdenek Prikryl ac5510
+	const char *p;
Zdenek Prikryl ac5510
+
Zdenek Prikryl ac5510
+	if ((p = resolve_symlinks(file)) == NULL) {
Zdenek Prikryl ac5510
+		fprintf(stderr, "%s: %s: %s\n", progname,
Zdenek Prikryl ac5510
+			xquote(file), strerror(errno));
Zdenek Prikryl ac5510
+		return 1;
Zdenek Prikryl ac5510
+	} else if (nftw(p, do_print, 0, opt_walk_logical? 0 : FTW_PHYS) < 0) {
Zdenek Prikryl ac5510
+		fprintf(stderr, "%s: %s: %s\n", progname, xquote(file),
Zdenek Prikryl ac5510
+			strerror(errno));
Zdenek Prikryl ac5510
+		return 1;
Zdenek Prikryl ac5510
+	}
Zdenek Prikryl ac5510
+	return 0;
Zdenek Prikryl ac5510
+}
Zdenek Prikryl ac5510
 
Zdenek Prikryl ac5510
 int main(int argc, char *argv[])
Zdenek Prikryl ac5510
 {
Zdenek Prikryl ac5510
@@ -499,12 +531,7 @@ int main(int argc, char *argv[])
Zdenek Prikryl ac5510
 	}
Zdenek Prikryl ac5510
 
Zdenek Prikryl ac5510
 	while (optind < argc) {
Zdenek Prikryl ac5510
-		if (nftw(argv[optind], do_print, 0,
Zdenek Prikryl ac5510
-			 opt_walk_physical * FTW_PHYS) < 0) {
Zdenek Prikryl ac5510
-			fprintf(stderr, "%s: %s: %s\n", progname, argv[optind],
Zdenek Prikryl ac5510
-			        strerror_ea(errno));
Zdenek Prikryl ac5510
-			had_errors++;
Zdenek Prikryl ac5510
-		}
Zdenek Prikryl ac5510
+		had_errors += walk_tree(argv[optind]);
Zdenek Prikryl ac5510
 		optind++;
Zdenek Prikryl ac5510
 	}
Zdenek Prikryl ac5510