-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.go
52 lines (44 loc) · 1.29 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package iDB
import (
"os"
"syscall"
"xattr"
)
func ListXattr(aFile string) ([]string, error) {
keys, err := xattr.Listxattr(aFile)
var result []string
if err == nil {
for _, key := range keys {
if len(key)> len(XattrPrefix) && key[0:len(XattrPrefix)] == XattrPrefix {
result = append(result, key[len(XattrPrefix):])
}
}
}
return result, err
}
func GetXattr(aFile, aKey string) (string, error) {
value, err := xattr.Getxattr(aFile, XattrPrefix+aKey)
return string(value), err
}
func IsXattrExists(aFile, aKey string) bool {
return xattr.IsXattrExists(aFile, XattrPrefix+aKey)
}
func SetXattr(aFile, aKey, aValue string) error {
return xattr.Setxattr(aFile, XattrPrefix+aKey, []byte(aValue))
}
func DeleteXattr(aFile, aKey string) error {
return xattr.Removexattr(aFile, XattrPrefix+aKey)
}
//check File or Dir is exists
func FileIsExists(aFile string) (bool, error) {
_, err := os.Stat(aFile)
result := err == nil
if !result {
e, ok := err.(*os.PathError)
// Check if error is "no such file or directory"
if ok && e.Err == syscall.ENOENT {
err = nil
}
}
return result, err
}