-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdir_plan9.go
49 lines (43 loc) · 901 Bytes
/
dir_plan9.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
package p9
import (
"errors"
"os"
"syscall"
"time"
)
func infoToEntry(fi os.FileInfo) DirEntry {
sys, _ := fi.Sys().(*syscall.Dir)
if sys == nil {
return DirEntry{
FileMode: ModeFromOS(fi.Mode()),
MTime: fi.ModTime(),
Length: uint64(fi.Size()),
EntryName: fi.Name(),
}
}
return DirEntry{
FileMode: ModeFromOS(fi.Mode()),
ATime: time.Unix(int64(sys.Atime), 0),
MTime: fi.ModTime(),
Length: uint64(fi.Size()),
EntryName: fi.Name(),
UID: sys.Uid,
GID: sys.Gid,
MUID: sys.Muid,
}
}
func (d Dir) GetQID(p string) (QID, error) {
fi, err := os.Stat(d.path(p))
if err != nil {
return QID{}, err
}
sys, _ := fi.Sys().(*syscall.Dir)
if sys == nil {
return QID{}, errors.New("failed to get QID: FileInfo was not Dir")
}
return QID{
Type: sys.Qid.Type,
Version: sys.Qid.Vers,
Path: sys.Qid.Path,
}, nil
}