tstor/src/host/vfs/dir.go

60 lines
991 B
Go
Raw Normal View History

2023-10-16 09:18:40 +00:00
package vfs
2023-12-21 23:15:39 +00:00
import (
2024-03-20 21:47:51 +00:00
"context"
2023-12-21 23:15:39 +00:00
"io/fs"
"path"
)
2024-03-28 13:09:42 +00:00
var _ File = &dirFile{}
2023-12-21 23:15:39 +00:00
2024-03-28 13:09:42 +00:00
func newDirFile(name string) File {
return &dirFile{
2023-12-21 23:15:39 +00:00
name: path.Base(name),
}
}
2024-03-28 13:09:42 +00:00
type dirFile struct {
2023-12-21 23:15:39 +00:00
name string
}
2024-03-28 13:09:42 +00:00
// Close implements File.
func (d *dirFile) Close(ctx context.Context) error {
return nil
}
2023-12-21 23:15:39 +00:00
// Info implements File.
2024-03-28 13:09:42 +00:00
func (d *dirFile) Info() (fs.FileInfo, error) {
2023-12-21 23:15:39 +00:00
return newDirInfo(d.name), nil
}
2024-03-28 13:09:42 +00:00
// IsDir implements File.
func (d *dirFile) IsDir() bool {
return true
}
2024-03-28 13:09:42 +00:00
// Name implements File.
func (d *dirFile) Name() string {
return d.name
}
2024-03-28 13:09:42 +00:00
// Read implements File.
func (d *dirFile) Read(ctx context.Context, p []byte) (n int, err error) {
return 0, fs.ErrInvalid
}
2024-03-28 13:09:42 +00:00
// ReadAt implements File.
func (d *dirFile) ReadAt(ctx context.Context, p []byte, off int64) (n int, err error) {
return 0, fs.ErrInvalid
}
// Size implements File.
func (d *dirFile) Size() int64 {
return 0
}
2024-03-28 13:09:42 +00:00
// Type implements File.
func (d *dirFile) Type() fs.FileMode {
return roMode | fs.ModeDir
}