From 7c7eabdfc213636fa1f5a7fe7e457b20a8d7defd Mon Sep 17 00:00:00 2001 From: Przemyslaw Pawelczyk Date: Tue, 8 Sep 2015 01:08:32 +0200 Subject: Add action to dump metadata in human-readable form: -d / --dump. metastore depends now on libbsd, because of strmode() function. This commit fixes issue #28. --- metaentry.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'metaentry.c') diff --git a/metaentry.c b/metaentry.c index 2064f29..f3ba692 100644 --- a/metaentry.c +++ b/metaentry.c @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include "metastore.h" #include "metaentry.h" @@ -626,3 +628,50 @@ mentries_compare(struct metahash *mhashreal, } } +/* Dumps given metadata */ +void +mentries_dump(struct metahash *mhash) +{ + const struct metaentry *mentry; + char mode[11 + 1] = ""; + char date[12 + 2 + 2 + 2*1 + 1 + 2 + 2 + 2 + 2*1 + 1] = ""; + char zone[5 + 1] = ""; + struct tm cal; + + for (int key = 0; key < HASH_INDEXES; key++) { + for (mentry = mhash->bucket[key]; mentry; mentry = mentry->next) { + strmode(mentry->mode, mode); + localtime_r(&mentry->mtime, &cal); + strftime(date, sizeof(date), "%F %T", &cal); + strftime(zone, sizeof(zone), "%z", &cal); + printf("%s\t%s\t%s\t%s.%09ld %s\t%s%s\n", + mode, + mentry->owner, mentry->group, + date, mentry->mtimensec, zone, + mentry->path, S_ISDIR(mentry->mode) ? "/" : ""); + for (int i = 0; i < mentry->xattrs; i++) { + printf("\t\t\t\t%s%s\t%s=", + mentry->path, S_ISDIR(mentry->mode) ? "/" : "", + mentry->xattr_names[i]); + ssize_t p = 0; + for (; p < mentry->xattr_lvalues[i]; p++) { + const char ch = mentry->xattr_values[i][p]; + if ((unsigned)(ch - 32) > 126 - 32) { + p = -1; + break; + } + } + if (p >= 0) + printf("\"%.*s\"\n", + (int)mentry->xattr_lvalues[i], + mentry->xattr_values[i]); + else { + printf("0x"); + for (p = 0; p < mentry->xattr_lvalues[i]; p++) + printf("%02hhx", (char)mentry->xattr_values[i][p]); + printf("\n"); + } + } + } + } +} -- cgit v1.2.1