tstor/src/vfs/dummy.go

121 lines
2.2 KiB
Go
Raw Normal View History

2024-03-28 13:09:42 +00:00
package vfs
import (
"context"
"io/fs"
"os"
"path"
"time"
)
var _ Filesystem = &DummyFs{}
type DummyFs struct {
name string
}
// ModTime implements Filesystem.
func (d *DummyFs) ModTime() time.Time {
return time.Time{}
}
// Mode implements Filesystem.
func (d *DummyFs) Mode() fs.FileMode {
return fs.ModeDir
}
// FsName implements Filesystem.
func (d *DummyFs) FsName() string {
return "dummyfs"
}
// Stat implements Filesystem.
func (*DummyFs) Stat(ctx context.Context, filename string) (fs.FileInfo, error) {
2024-05-19 21:24:09 +00:00
return NewFileInfo(path.Base(filename), 0), nil // TODO
2024-03-28 13:09:42 +00:00
}
func (d *DummyFs) Open(ctx context.Context, filename string) (File, error) {
return &DummyFile{}, nil
}
func (d *DummyFs) Unlink(ctx context.Context, filename string) error {
return ErrNotImplemented
}
func (d *DummyFs) ReadDir(ctx context.Context, path string) ([]fs.DirEntry, error) {
if path == "/dir/here" {
return []fs.DirEntry{
2024-05-19 21:24:09 +00:00
NewFileInfo("file1.txt", 0),
NewFileInfo("file2.txt", 0),
2024-03-28 13:09:42 +00:00
}, nil
}
return nil, os.ErrNotExist
}
// Info implements Filesystem.
func (d *DummyFs) Info() (fs.FileInfo, error) {
2024-06-02 19:53:33 +00:00
return NewDirInfo(d.name), nil
2024-03-28 13:09:42 +00:00
}
// IsDir implements Filesystem.
func (d *DummyFs) IsDir() bool {
return true
}
// Name implements Filesystem.
func (d *DummyFs) Name() string {
return d.name
}
// Type implements Filesystem.
func (d *DummyFs) Type() fs.FileMode {
return fs.ModeDir
}
var _ File = &DummyFile{}
type DummyFile struct {
name string
}
// Seek implements File.
func (d *DummyFile) Seek(offset int64, whence int) (int64, error) {
return 0, nil
}
2024-03-28 13:09:42 +00:00
// Name implements File.
func (d *DummyFile) Name() string {
panic("unimplemented")
}
// Type implements File.
func (d *DummyFile) Type() fs.FileMode {
panic("unimplemented")
}
// Stat implements File.
func (d *DummyFile) Info() (fs.FileInfo, error) {
2024-05-19 21:24:09 +00:00
return NewFileInfo(d.name, 0), nil
2024-03-28 13:09:42 +00:00
}
func (d *DummyFile) Size() int64 {
return 0
}
func (d *DummyFile) IsDir() bool {
return false
}
func (d *DummyFile) Close(ctx context.Context) error {
return nil
}
func (d *DummyFile) Read(ctx context.Context, p []byte) (n int, err error) {
return 0, nil
}
func (d *DummyFile) ReadAt(ctx context.Context, p []byte, off int64) (n int, err error) {
return 0, nil
}