diff options
-rw-r--r-- | tests/getfattr.test | 9 | ||||
-rw-r--r-- | toys/pending/getfattr.c | 15 |
2 files changed, 16 insertions, 8 deletions
diff --git a/tests/getfattr.test b/tests/getfattr.test index cb0f9475..ae33d766 100644 --- a/tests/getfattr.test +++ b/tests/getfattr.test @@ -8,14 +8,19 @@ mkdir attrs touch attrs/file setfattr -n user.empty attrs/file setfattr -n user.data -v hello attrs/file +setfattr -n user.more -v world attrs/file testing "" "getfattr attrs/file" \ - "# file: attrs/file\nuser.data\nuser.empty\n\n" "" "" + "# file: attrs/file\nuser.data\nuser.empty\nuser.more\n\n" "" "" testing "-d" "getfattr -d attrs/file" \ - "# file: attrs/file\nuser.data=\"hello\"\nuser.empty\n\n" "" "" + "# file: attrs/file\nuser.data=\"hello\"\nuser.empty\nuser.more=\"world\"\n\n" "" "" testing "-n" "getfattr -n user.empty attrs/file" \ "# file: attrs/file\nuser.empty\n\n" "" "" testing "-d -n" "getfattr -d -n user.data attrs/file" \ "# file: attrs/file\nuser.data=\"hello\"\n\n" "" "" +testing "--only-values" "getfattr --only-values attrs/file" \ + "helloworld" "" "" +testing "--only-values -n" "getfattr --only-values -n user.data attrs/file" \ + "hello" "" "" rm -rf attrs diff --git a/toys/pending/getfattr.c b/toys/pending/getfattr.c index c58994d6..bf2c04c8 100644 --- a/toys/pending/getfattr.c +++ b/toys/pending/getfattr.c @@ -4,7 +4,7 @@ * * No standard -USE_GETFATTR(NEWTOY(getfattr, "dhn:", TOYFLAG_USR|TOYFLAG_BIN)) +USE_GETFATTR(NEWTOY(getfattr, "(only-values)dhn:", TOYFLAG_USR|TOYFLAG_BIN)) config GETFATTR bool "getfattr" @@ -17,6 +17,7 @@ config GETFATTR -d Show values as well as names -h Do not dereference symbolic links -n Show only attributes with the given name + --only-values Don't show names */ #define FOR_getfattr @@ -36,7 +37,7 @@ static void do_getfattr(char *file) char *keys, *key; int i, key_count; - if (toys.optflags&FLAG_h) { + if (FLAG(h)) { getter = lgetxattr; lister = llistxattr; } @@ -59,14 +60,14 @@ static void do_getfattr(char *file) sorted_keys[i++] = key; qsort(sorted_keys, key_count, sizeof(char *), qstrcmp); - printf("# file: %s\n", file); + if (!FLAG(only_values)) printf("# file: %s\n", file); for (i = 0; i < key_count; i++) { key = sorted_keys[i]; if (TT.n && strcmp(TT.n, key)) continue; - if (toys.optflags&FLAG_d) { + if (FLAG(d) || FLAG(only_values)) { ssize_t value_len; char *value = NULL; @@ -77,13 +78,15 @@ static void do_getfattr(char *file) free(value); } - if (!value) puts(key); + if (FLAG(only_values)) { + if (value) printf("%s", value); + } else if (!value) puts(key); else printf("%s=\"%s\"\n", key, value); free(value); } else puts(key); // Just list names. } - xputc('\n'); + if (!FLAG(only_values)) xputc('\n'); free(sorted_keys); } |