-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileinfo.go
49 lines (40 loc) · 1.13 KB
/
fileinfo.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 file
import (
"errors"
"os"
)
// A FileInfo describes a file and is returned by Stat and Lstat.
type FileInfo interface {
os.FileInfo
UID() (int, error) // UID of the file owner. Returns an error on non-POSIX file systems.
GID() (int, error) // GID of the file owner. Returns an error on non-POSIX file systems.
}
// Stat returns a FileInfo describing the named file.
// If there is an error, it will be of type *PathError.
func Stat(name string) (FileInfo, error) {
return stat(name, os.Stat)
}
// Lstat returns a FileInfo describing the named file.
// If the file is a symbolic link, the returned FileInfo
// describes the symbolic link. Lstat makes no attempt to follow the link.
// If there is an error, it will be of type *PathError.
func Lstat(name string) (FileInfo, error) {
return stat(name, os.Lstat)
}
type fileInfo struct {
os.FileInfo
uid *int
gid *int
}
func (f fileInfo) UID() (int, error) {
if f.uid == nil {
return -1, errors.New("uid not implemented")
}
return *f.uid, nil
}
func (f fileInfo) GID() (int, error) {
if f.gid == nil {
return -1, errors.New("gid not implemented")
}
return *f.gid, nil
}