-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
63 lines (56 loc) · 1.41 KB
/
util.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
52
53
54
55
56
57
58
59
60
61
62
63
package fs
import (
"context"
"errors"
"github.com/hanwen/go-fuse/v2/fuse"
"github.com/hown3d/s3-csi/internal/aws/s3"
"hash/fnv"
"k8s.io/klog/v2"
"strings"
"syscall"
)
func keyToFileMode(key string) uint32 {
isDir := keyIsDir(key)
if !isDir {
// signs that obj is a file
return fuse.S_IFREG
}
// signs that obj is a directory
return fuse.S_IFDIR
}
func keyIsDir(key string) bool {
return strings.HasSuffix(key, "/")
}
func uniqueInode(s string) uint64 {
h := fnv.New64a()
h.Write([]byte(s))
return h.Sum64()
}
func rootDirAttrs() *fuse.AttrOut {
return &fuse.AttrOut{
Attr: fuse.Attr{
Mode: fuse.S_IFDIR,
},
}
}
func setFuseAttr(ctx context.Context, obj *s3.Object, out *fuse.Attr) syscall.Errno {
key := obj.Key
objAttrs, err := obj.GetAttrs(ctx)
if err != nil {
var notFoundErr *s3.ErrObjectNotFound
if errors.As(err, ¬FoundErr) {
klog.Infof("%s: %s", "setFuseAttr", notFoundErr)
return syscall.ENOENT
}
printError("setFuseAttr", err)
return syscall.EIO
}
out.Ino = uniqueInode(key)
out.Mode = keyToFileMode(key)
out.Size = objAttrs.Size
out.SetTimes(objAttrs.AccessTime, objAttrs.ModifyTime, objAttrs.ChangeTime)
return 0
}
func printError(method string, err error) {
klog.Errorf("%s: %s", method, err)
}