-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
59 lines (49 loc) · 1.23 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
52
53
54
55
56
57
58
59
package main
import (
"os"
"syscall"
"time"
"github.com/keybase/kbfs/dokan"
)
func has(val, flag uint32) bool {
return val&flag != 0
}
func hasAttribute(val, flag dokan.FileAttribute) bool {
return val&flag != 0
}
func fileInfoToStat(fi os.FileInfo) dokan.Stat {
fstat := fi.Sys().(*syscall.Win32FileAttributeData)
lastAccess := time.Unix(0, fstat.LastAccessTime.Nanoseconds())
lastWrite := time.Unix(0, fstat.LastWriteTime.Nanoseconds())
createdTime := time.Unix(0, fstat.CreationTime.Nanoseconds())
c := dokan.Stat{
Creation: createdTime,
FileSize: fi.Size(),
LastAccess: lastAccess,
LastWrite: lastWrite,
VolumeSerialNumber: 0x1337,
FileAttributes: dokan.FileAttribute(fstat.FileAttributes),
}
if fi.IsDir() {
c.FileAttributes |= dokan.FileAttributeDirectory
}
return c
}
func osErrToDokanErr(err error, dir bool) (error, bool) {
if os.IsExist(err) {
if dir {
return dokan.ErrObjectNameCollision, true
}
return dokan.ErrFileAlreadyExists, true
}
if os.IsNotExist(err) {
if dir {
return dokan.ErrObjectPathNotFound, true
}
return dokan.ErrObjectNameNotFound, true
}
if os.IsPermission(err) {
return dokan.ErrAccessDenied, true
}
return err, false
}