-
Notifications
You must be signed in to change notification settings - Fork 0
/
stddirentry.go
45 lines (38 loc) · 1.43 KB
/
stddirentry.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
package fs
import iofs "io/fs"
var (
_ iofs.DirEntry = StdDirEntry{File("")}
)
// StdDirEntry implements the io/fs.DirEntry interface
// from the standard library for a File.
type StdDirEntry struct {
File File
}
// Name returns the name of the file (or subdirectory) described by the entry.
// This name is only the final element of the path (the base name), not the entire path.
// For example, Name would return "hello.go" not "/home/gopher/hello.go".
func (de StdDirEntry) Name() string {
return de.File.Name()
}
// IsDir reports whether the entry describes a directory.
func (de StdDirEntry) IsDir() bool {
return de.File.IsDir()
}
// Type returns the type bits for the entry.
// The type bits are a subset of the usual FileMode bits, those returned by the FileMode.Type method.
func (de StdDirEntry) Type() iofs.FileMode {
stat, err := de.File.Stat()
if err != nil {
return 0
}
return stat.Mode().Type()
}
// Info returns the FileInfo for the file or subdirectory described by the entry.
// The returned FileInfo may be from the time of the original directory read
// or from the time of the call to Info. If the file has been removed or renamed
// since the directory read, Info may return an error satisfying errors.Is(err, ErrNotExist).
// If the entry denotes a symbolic link, Info reports the information about the link itself,
// not the link's target.
func (de StdDirEntry) Info() (iofs.FileInfo, error) {
return de.File.Stat()
}