Integrate real filesystem with interface abstraction

- Define pool.FileSystem interface in internal/io/pool/filesystem.go
- Move DirEntry interface to internal/io/pool/types/types.go to break
  the pool <-> mock import cycle
- Implement real.FileSystem with atomic writes (temp file + os.Rename)
- Update mock.FileSystem to satisfy pool.FileSystem interface
- Update worker pool tasks to accept pool.FileSystem interface
- Update main.go to use RealFileSystem by default, with -root flag
- Update all browser/editor/test references to types.DirEntry
This commit is contained in:
gmp
2026-06-04 16:19:38 -04:00
parent 672dcbe6b3
commit d73cb0be2c
16 changed files with 217 additions and 78 deletions
+17 -15
View File
@@ -9,17 +9,9 @@ import (
"path/filepath"
"sync"
"time"
)
// File represents a file or directory in the mock filesystem.
type File struct {
Path string
Name string
Content []byte
ModTime time.Time
Size int64
IsDir bool
}
"pad/internal/io/pool/types"
)
// DirEntry mimics fs.DirEntry behavior for the mock.
type DirEntry struct {
@@ -29,12 +21,22 @@ type DirEntry struct {
size int64
}
func (d DirEntry) Name() string { return d.name }
func (d DirEntry) IsDir() bool { return d.isDir }
func (d DirEntry) Name() string { return d.name }
func (d DirEntry) IsDir() bool { return d.isDir }
func (d DirEntry) Info() (os.FileInfo, error) {
return &mockFileInfo{name: d.name, isDir: d.isDir, modTime: d.modTime, size: d.size}, nil
}
// File represents a file or directory in the mock filesystem.
type File struct {
Path string
Name string
Content []byte
ModTime time.Time
Size int64
IsDir bool
}
// mockFileInfo implements os.FileInfo for the mock.
type mockFileInfo struct {
name string
@@ -273,7 +275,7 @@ func (fs *FileSystem) CreateDir(path string) error {
}
// ReadDir returns a list of entries in the given directory.
func (fs *FileSystem) ReadDir(path string) ([]DirEntry, error) {
func (fs *FileSystem) ReadDir(path string) ([]types.DirEntry, error) {
fs.mu.Lock()
if fs.delay > 0 {
@@ -288,7 +290,7 @@ func (fs *FileSystem) ReadDir(path string) ([]DirEntry, error) {
return nil, fmt.Errorf("directory not found: %s", path)
}
var entries []DirEntry
var entries []types.DirEntry
for _, f := range fs.files {
if f.Path == dirPath {
@@ -308,7 +310,7 @@ func (fs *FileSystem) ReadDir(path string) ([]DirEntry, error) {
// Sort by name
for i := 0; i < len(entries); i++ {
for j := i + 1; j < len(entries); j++ {
if entries[i].name > entries[j].name {
if entries[i].Name() > entries[j].Name() {
entries[i], entries[j] = entries[j], entries[i]
}
}