Skip to content

Instantly share code, notes, and snippets.

@ezr
Last active November 20, 2020 07:22
Show Gist options
  • Save ezr/6218179038b9ce7b9b2bcabcc83249d1 to your computer and use it in GitHub Desktop.
Save ezr/6218179038b9ce7b9b2bcabcc83249d1 to your computer and use it in GitHub Desktop.
Like "getfattr -d"
package main
import (
"fmt"
"log"
"os"
"github.com/pkg/xattr"
)
func handleError(e error) {
if e != nil {
log.Fatal(e)
}
}
func main() {
if len(os.Args) < 2 {
fmt.Println("error - must provide the path to a file or directory")
os.Exit(1)
}
paths := os.Args[1:]
for _, path := range paths {
list, err := xattr.List(path)
handleError(err)
if len(list) == 0 {
continue
}
fmt.Println(path)
for _, attr := range list {
val, err := xattr.Get(path, attr)
handleError(err)
fmt.Printf(" %s: %s\n", attr, val)
}
fmt.Println()
}
}
@ezr
Copy link
Author

ezr commented Nov 20, 2020

getfattr -d only lists attributes in the user namespace. This will dump all extended attributes for a file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment