diff options
author | Elliott Hughes <enh@google.com> | 2019-02-20 15:57:30 -0800 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-02-21 12:12:01 -0600 |
commit | 4cc20c7554685df53228c4cf6d551b07837f8bf1 (patch) | |
tree | 947c469dbf22a74c594c8f480e5e984a19943f4f | |
parent | 01503a37c9ae3bc608e7ba9fb476ab7aca3fdd46 (diff) | |
download | toybox-4cc20c7554685df53228c4cf6d551b07837f8bf1.tar.gz |
getfattr: add --only-values.
Needed to improve cp(1) testing.
-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); } |