-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstat.go
More file actions
32 lines (28 loc) · 784 Bytes
/
Copy pathstat.go
File metadata and controls
32 lines (28 loc) · 784 Bytes
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
package fs
import (
"context"
"errors"
)
// A StatFS is a file system with the Stat method.
type StatFS interface {
FS
// Stat returns file metadata for the named file.
Stat(ctx context.Context, name string) (FileInfo, error)
}
// Stat returns file metadata for the named file.
// Analogous to: [io/fs.Stat], [os.Stat], stat, ls -l, 9P Tstat,
// S3 HeadObject.
//
// Requires: [StatFS]
func Stat(ctx context.Context, fsys FS, name string) (FileInfo, error) {
name, err := localizePath(ctx, fsys, name)
if err != nil {
return nil, err
}
if sfs, ok := fsys.(StatFS); ok {
if info, err := sfs.Stat(ctx, name); !errors.Is(err, ErrUnsupported) {
return info, newPathError("stat", name, err)
}
}
return nil, &PathError{Op: "stat", Path: name, Err: ErrUnsupported}
}