[PATCH v2 6/7] src/fssum: Allow single file input

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]



Allow regular links and symlinks to be passed as input to fssum.

Signed-off-by: Arvind Raghavan <raghavan.arvind@xxxxxxxxx>
Signed-off-by: Jayashree Mohan <jaya@xxxxxxxxxxxxx>
Signed-off-by: Vijay Chidambaram <vijay@xxxxxxxxxxxxx>
---
Since v1:
	- Simplified logic by using sum_one
 src/fssum.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/fssum.c b/src/fssum.c
index 26b0096c..c5c27486 100644
--- a/src/fssum.c
+++ b/src/fssum.c
@@ -29,6 +29,7 @@
 #include <inttypes.h>
 #include <assert.h>
 #include <endian.h>
+#include <libgen.h>
 
 #define CS_SIZE 16
 #define CHUNKS	128
@@ -600,7 +601,8 @@ sum_one(int dirfd, int level, sum_t *dircs, char *path_prefix,
 			goto out;
 	}
 
-	ret = fstatat64(dirfd, name, &st, AT_SYMLINK_NOFOLLOW);
+	ret = fstatat64(dirfd, name, &st, AT_SYMLINK_NOFOLLOW |
+			AT_EMPTY_PATH);
 	if (ret) {
 		fprintf(stderr, "stat failed for %s/%s: %s\n",
 			path_prefix, path, strerror(errno));
@@ -890,8 +892,23 @@ main(int argc, char *argv[])
 	if (gen_manifest)
 		fprintf(out_fp, "Flags: %s\n", flagstring);
 
+	struct stat64 path_st;
+	if (fstat64(fd, &path_st)) {
+		perror("fstat");
+		exit(-1);
+	}
+
 	sum_init(&cs);
-	sum(fd, 1, &cs, path, "");
+
+	if (S_ISDIR(path_st.st_mode)) {
+		sum(fd, 1, &cs, path, "");
+	} else if (S_ISREG(path_st.st_mode) || S_ISLNK(path_st.st_mode)) {
+		sum_one(fd, 1, &cs, path, "", "");
+	} else {
+		fprintf(stderr, "path must be file or dir: %s", path);
+		exit(-1);
+	}
+
 	sum_fini(&cs);
 
 	close(fd);
-- 
2.20.1




[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux