Fix 'decomposedfs meta set' value handling

Don't strip off the first two characters of the target
value to set unconditionally. Also print an error if
decoding hex/base64 values fails (falling back to treating
the values as strings).
This commit is contained in:
Ralf Haferkamp
2023-06-13 12:02:12 +02:00
committed by Ralf Haferkamp
parent e0ec2c1ccd
commit 046ff50f52

View File

@@ -135,15 +135,19 @@ func setCmd(cfg *config.Config) *cli.Command {
b64, err := base64.StdEncoding.DecodeString(v[2:])
if err == nil {
v = string(b64)
} else {
fmt.Printf("Error decoding base64 string: '%s'. Using as raw string.\n", err)
}
} else if strings.HasPrefix(v, "0x") {
h, err := hex.DecodeString(v)
h, err := hex.DecodeString(v[2:])
if err == nil {
v = string(h)
} else {
fmt.Printf("Error decoding base64 string: '%s'. Using as raw string.\n", err)
}
}
err = backend.Set(path, c.String("attribute"), []byte(v[2:]))
err = backend.Set(path, c.String("attribute"), []byte(v))
if err != nil {
fmt.Println("Error setting attribute")
return err