xattr: use LGet/LSet etc
Support has been merged into the xattr package ( https://github.com/pkg/xattr/pull/29 ), use it.
This commit is contained in:
parent
44caf21deb
commit
ae02ca1ded
@ -36,7 +36,7 @@ func (fs *FS) GetXAttr(path string, attr string, context *fuse.Context) ([]byte,
|
||||
if err != nil {
|
||||
return nil, fuse.ToStatus(err)
|
||||
}
|
||||
encryptedData, err := xattr.Get(cPath, cAttr)
|
||||
encryptedData, err := xattr.LGet(cPath, cAttr)
|
||||
if err != nil {
|
||||
return nil, unpackXattrErr(err)
|
||||
}
|
||||
@ -67,7 +67,7 @@ func (fs *FS) SetXAttr(path string, attr string, data []byte, flags int, context
|
||||
}
|
||||
cAttr := fs.encryptXattrName(attr)
|
||||
cData := fs.encryptXattrValue(data)
|
||||
return unpackXattrErr(xattr.SetWithFlags(cPath, cAttr, cData, flags))
|
||||
return unpackXattrErr(xattr.LSetWithFlags(cPath, cAttr, cData, flags))
|
||||
}
|
||||
|
||||
// RemoveXAttr implements pathfs.Filesystem.
|
||||
@ -83,7 +83,7 @@ func (fs *FS) RemoveXAttr(path string, attr string, context *fuse.Context) fuse.
|
||||
return fuse.ToStatus(err)
|
||||
}
|
||||
cAttr := fs.encryptXattrName(attr)
|
||||
return unpackXattrErr(xattr.Remove(cPath, cAttr))
|
||||
return unpackXattrErr(xattr.LRemove(cPath, cAttr))
|
||||
}
|
||||
|
||||
// ListXAttr implements pathfs.Filesystem.
|
||||
@ -95,7 +95,7 @@ func (fs *FS) ListXAttr(path string, context *fuse.Context) ([]string, fuse.Stat
|
||||
if err != nil {
|
||||
return nil, fuse.ToStatus(err)
|
||||
}
|
||||
cNames, err := xattr.List(cPath)
|
||||
cNames, err := xattr.LList(cPath)
|
||||
if err != nil {
|
||||
return nil, unpackXattrErr(err)
|
||||
}
|
||||
@ -167,7 +167,7 @@ func (fs *FS) decryptXattrValue(cData []byte) (data []byte, err error) {
|
||||
return fs.contentEnc.DecryptBlock([]byte(cData), 0, nil)
|
||||
}
|
||||
|
||||
// unpackXattrErr unpacks an error value that we got from xattr.Get/Set/etc
|
||||
// unpackXattrErr unpacks an error value that we got from xattr.LGet/LSet/etc
|
||||
// and converts it to a fuse status.
|
||||
func unpackXattrErr(err error) fuse.Status {
|
||||
if err == nil {
|
||||
|
@ -53,12 +53,12 @@ func TestXattrSetGetRm(t *testing.T) {
|
||||
}
|
||||
// Set
|
||||
val1 := []byte("123456789")
|
||||
err = xattr.Set(fn, attr, val1)
|
||||
err = xattr.LSet(fn, attr, val1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Read back
|
||||
val2, err := xattr.Get(fn, attr)
|
||||
val2, err := xattr.LGet(fn, attr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -66,12 +66,12 @@ func TestXattrSetGetRm(t *testing.T) {
|
||||
t.Fatalf("wrong readback value: %v != %v", val1, val2)
|
||||
}
|
||||
// Remove
|
||||
err = xattr.Remove(fn, attr)
|
||||
err = xattr.LRemove(fn, attr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Read back
|
||||
val3, err := xattr.Get(fn, attr)
|
||||
val3, err := xattr.LGet(fn, attr)
|
||||
if err == nil {
|
||||
t.Fatalf("attr is still there after deletion!? val3=%v", val3)
|
||||
}
|
||||
@ -85,17 +85,17 @@ func TestXattrSetEmpty(t *testing.T) {
|
||||
t.Fatalf("creating empty file failed: %v", err)
|
||||
}
|
||||
// Make sure it does not exist already
|
||||
_, err = xattr.Get(fn, attr)
|
||||
_, err = xattr.LGet(fn, attr)
|
||||
if err == nil {
|
||||
t.Fatal("we should have got an error here")
|
||||
}
|
||||
// Set empty value
|
||||
err = xattr.Set(fn, attr, nil)
|
||||
err = xattr.LSet(fn, attr, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Read back
|
||||
val, err := xattr.Get(fn, attr)
|
||||
val, err := xattr.LGet(fn, attr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -104,12 +104,12 @@ func TestXattrSetEmpty(t *testing.T) {
|
||||
}
|
||||
// Overwrite empty value with something
|
||||
val1 := []byte("xyz123")
|
||||
err = xattr.Set(fn, attr, val1)
|
||||
err = xattr.LSet(fn, attr, val1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Read back
|
||||
val2, err := xattr.Get(fn, attr)
|
||||
val2, err := xattr.LGet(fn, attr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -117,12 +117,12 @@ func TestXattrSetEmpty(t *testing.T) {
|
||||
t.Fatalf("wrong readback value: %v != %v", val1, val2)
|
||||
}
|
||||
// Overwrite something with empty value
|
||||
err = xattr.Set(fn, attr, nil)
|
||||
err = xattr.LSet(fn, attr, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Read back
|
||||
val, err = xattr.Get(fn, attr)
|
||||
val, err = xattr.LGet(fn, attr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -141,12 +141,12 @@ func TestXattrList(t *testing.T) {
|
||||
num := 20
|
||||
for i := 1; i <= num; i++ {
|
||||
attr := fmt.Sprintf("user.TestXattrList.%02d", i)
|
||||
err = xattr.Set(fn, attr, val)
|
||||
err = xattr.LSet(fn, attr, val)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
names, err := xattr.List(fn)
|
||||
names, err := xattr.LList(fn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -161,7 +161,7 @@ func TestXattrList(t *testing.T) {
|
||||
}
|
||||
|
||||
func xattrSupported(path string) bool {
|
||||
_, err := xattr.Get(path, "user.xattrSupported-dummy-value")
|
||||
_, err := xattr.LGet(path, "user.xattrSupported-dummy-value")
|
||||
if err == nil {
|
||||
return true
|
||||
}
|
||||
@ -191,24 +191,24 @@ func TestBase64XattrRead(t *testing.T) {
|
||||
if _, err2 := os.Stat(encryptedFn); os.IsNotExist(err2) {
|
||||
t.Fatalf("encrypted file does not exist: %v", err2)
|
||||
}
|
||||
xattr.Set(plainFn, attrName, []byte(attrValue))
|
||||
xattr.LSet(plainFn, attrName, []byte(attrValue))
|
||||
|
||||
encryptedAttrValue, err1 := xattr.Get(encryptedFn, encryptedAttrName)
|
||||
encryptedAttrValue, err1 := xattr.LGet(encryptedFn, encryptedAttrName)
|
||||
if err1 != nil {
|
||||
t.Fatal(err1)
|
||||
}
|
||||
|
||||
xattr.Set(encryptedFn, encryptedAttrName2, encryptedAttrValue)
|
||||
plainValue, err := xattr.Get(plainFn, attrName2)
|
||||
xattr.LSet(encryptedFn, encryptedAttrName2, encryptedAttrValue)
|
||||
plainValue, err := xattr.LGet(plainFn, attrName2)
|
||||
|
||||
if err != nil || string(plainValue) != attrValue {
|
||||
t.Fatalf("Attribute binary value decryption error %s != %s %v", string(plainValue), attrValue, err)
|
||||
}
|
||||
|
||||
encryptedAttrValue64 := base64.RawURLEncoding.EncodeToString(encryptedAttrValue)
|
||||
xattr.Set(encryptedFn, encryptedAttrName2, []byte(encryptedAttrValue64))
|
||||
xattr.LSet(encryptedFn, encryptedAttrName2, []byte(encryptedAttrValue64))
|
||||
|
||||
plainValue, err = xattr.Get(plainFn, attrName2)
|
||||
plainValue, err = xattr.LGet(plainFn, attrName2)
|
||||
if err != nil || string(plainValue) != attrValue {
|
||||
t.Fatalf("Attribute base64-encoded value decryption error %s != %s %v", string(plainValue), attrValue, err)
|
||||
}
|
||||
@ -225,8 +225,8 @@ func TestBase64XattrRead(t *testing.T) {
|
||||
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
|
||||
}
|
||||
for _, val := range brokenVals {
|
||||
xattr.Set(encryptedFn, encryptedAttrName2, []byte(val))
|
||||
plainValue, err = xattr.Get(plainFn, attrName2)
|
||||
xattr.LSet(encryptedFn, encryptedAttrName2, []byte(val))
|
||||
plainValue, err = xattr.LGet(plainFn, attrName2)
|
||||
err2, _ := err.(*xattr.Error)
|
||||
if err == nil || err2.Err != syscall.EIO {
|
||||
t.Fatalf("Incorrect handling of broken data %s %v", string(plainValue), err)
|
||||
|
Loading…
Reference in New Issue
Block a user