aboutsummaryrefslogtreecommitdiff
path: root/cap/text.go
diff options
context:
space:
mode:
authorAndrew G. Morgan <morgan@kernel.org>2020-07-21 22:58:05 -0700
committerAndrew G. Morgan <morgan@kernel.org>2020-07-23 08:06:00 -0700
commit177cd418031b1acfcf73fe3b1af9f3279828681c (patch)
tree5f8760995cf298a224d988ab24f2dd0b7bdd702a /cap/text.go
parentc7b5f2941a045df8cce3d59952817b8bdf0e1173 (diff)
downloadlibcap-177cd418031b1acfcf73fe3b1af9f3279828681c.tar.gz
A more compact form for the text representation of capabilities.
While this does not change anything about the supported range of equivalent text specifications for capabilities, as accepted by cap_from_text(), this does alter the preferred output format of cap_to_text() to be two characters shorter in most cases. That is, what used to be summarized as: "= cap_foo+..." is now converted to the equivalent text: "cap_foo=..." which is also more intuitive. Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
Diffstat (limited to 'cap/text.go')
-rw-r--r--cap/text.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/cap/text.go b/cap/text.go
index cbfe0f4..df037c3 100644
--- a/cap/text.go
+++ b/cap/text.go
@@ -107,7 +107,14 @@ func (c *Set) String() string {
x := strings.Join(list, ",")
var y, z string
if cf := i & ^m; cf != 0 {
- y = "+" + combos[cf]
+ op := "+"
+ if len(vs) == 1 && vs[0] == "=" {
+ // Special case "= foo+..." == "foo=...".
+ // Prefer because it
+ vs = nil
+ op = "="
+ }
+ y = op + combos[cf]
}
if cf := m & ^i; cf != 0 {
z = "-" + combos[cf]
@@ -158,7 +165,11 @@ func FromText(text string) (*Set, error) {
}
var vs []Value
sep := t[i]
- if vals := t[:i]; vals != "all" && vals != "" {
+ if vals := t[:i]; vals == "all" {
+ for v := Value(0); v < Value(maxValues); v++ {
+ vs = append(vs, v)
+ }
+ } else if vals != "" {
for _, name := range strings.Split(vals, ",") {
v, err := FromName(name)
if err != nil {