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:
@@ -56,7 +56,7 @@ type Logic struct {
|
||||
openFileChan chan string
|
||||
retryChan chan string // Added for auto-save retries
|
||||
workerPool *pool.WorkerPool
|
||||
mockFS *mock.FileSystem
|
||||
mockFS pool.FileSystem
|
||||
mu sync.Mutex
|
||||
done chan struct{}
|
||||
saveTimer *time.Timer // Added for auto-save debounce
|
||||
@@ -64,7 +64,7 @@ type Logic struct {
|
||||
}
|
||||
|
||||
// NewLogic creates a new Logic instance, accepting an optional mockFS.
|
||||
func NewLogic(mfs *mock.FileSystem) *Logic {
|
||||
func NewLogic(mfs pool.FileSystem) *Logic {
|
||||
state := NewState()
|
||||
TheState = state
|
||||
|
||||
|
||||
@@ -6,17 +6,23 @@ import (
|
||||
"time"
|
||||
|
||||
"pad/internal/browser"
|
||||
"pad/internal/io/pool"
|
||||
"pad/internal/io/pool/mock"
|
||||
"pad/internal/io/pool/types"
|
||||
)
|
||||
|
||||
// populateMockFileSystem seeds the mock filesystem with sample data for testing.
|
||||
// Creates a realistic directory structure with subdirectories, various file types,
|
||||
// and varied sizes/dates to exercise the browser functionality.
|
||||
func populateMockFileSystem(fs *mock.FileSystem) {
|
||||
func populateMockFileSystem(fs pool.FileSystem) {
|
||||
mfs, ok := fs.(*mock.FileSystem)
|
||||
if !ok {
|
||||
panic("populateMockFileSystem requires a *mock.FileSystem")
|
||||
}
|
||||
baseTime := time.Date(2026, 5, 15, 10, 0, 0, 0, time.UTC)
|
||||
|
||||
// Create root directory - required for ReadDir("/") to succeed
|
||||
fs.AddDir("/", baseTime)
|
||||
mfs.AddDir("/", baseTime)
|
||||
|
||||
// --- Root directories ---
|
||||
dirs := []string{
|
||||
@@ -32,7 +38,7 @@ func populateMockFileSystem(fs *mock.FileSystem) {
|
||||
"/Pictures/Vacation",
|
||||
}
|
||||
for i, d := range dirs {
|
||||
fs.AddDir(d, baseTime.AddDate(0, 0, -i))
|
||||
mfs.AddDir(d, baseTime.AddDate(0, 0, -i))
|
||||
}
|
||||
|
||||
// --- Root files ---
|
||||
@@ -48,7 +54,7 @@ func populateMockFileSystem(fs *mock.FileSystem) {
|
||||
{".gitignore", "*.log\n.pad/\n.git/\n*.tmp\n", -90},
|
||||
}
|
||||
for _, f := range rootFiles {
|
||||
fs.AddFile("/"+f.name, []byte(f.content), baseTime.AddDate(0, 0, f.days))
|
||||
mfs.AddFile("/"+f.name, []byte(f.content), baseTime.AddDate(0, 0, f.days))
|
||||
}
|
||||
|
||||
// --- Documents/Work files ---
|
||||
@@ -64,7 +70,7 @@ func populateMockFileSystem(fs *mock.FileSystem) {
|
||||
{"Presentation.pptx", "Pad Presentation Mock\n\nSlide 1: Title - No Practical Limits\nSlide 2: Virtualization is the key\nSlide 3: Single-Owner thread design\n", -21},
|
||||
}
|
||||
for _, f := range workFiles {
|
||||
fs.AddFile("/Documents/Work/"+f.name, []byte(f.content), baseTime.AddDate(0, 0, f.days))
|
||||
mfs.AddFile("/Documents/Work/"+f.name, []byte(f.content), baseTime.AddDate(0, 0, f.days))
|
||||
}
|
||||
|
||||
// --- Documents/Personal files ---
|
||||
@@ -79,7 +85,7 @@ func populateMockFileSystem(fs *mock.FileSystem) {
|
||||
{"Letter_to_Friend.txt", "Hey friend,\n\nI've been working on a really cool Go text editor called Pad. It uses Gio for rendering and handles massive files without blocking the GUI thread. Talk soon!\n", -5},
|
||||
}
|
||||
for _, f := range personalFiles {
|
||||
fs.AddFile("/Documents/Personal/"+f.name, []byte(f.content), baseTime.AddDate(0, 0, f.days))
|
||||
mfs.AddFile("/Documents/Personal/"+f.name, []byte(f.content), baseTime.AddDate(0, 0, f.days))
|
||||
}
|
||||
|
||||
// --- Projects/pad source files ---
|
||||
@@ -100,7 +106,7 @@ func populateMockFileSystem(fs *mock.FileSystem) {
|
||||
{"go.sum", "gioui.org v0.9.0 h1:...\n", -30},
|
||||
}
|
||||
for _, f := range padFiles {
|
||||
fs.AddFile("/Projects/pad/"+f.name, []byte(f.content), baseTime.AddDate(0, 0, f.days))
|
||||
mfs.AddFile("/Projects/pad/"+f.name, []byte(f.content), baseTime.AddDate(0, 0, f.days))
|
||||
}
|
||||
|
||||
// --- Pictures/Vacation files ---
|
||||
@@ -116,7 +122,7 @@ func populateMockFileSystem(fs *mock.FileSystem) {
|
||||
{"IMG_0005.jpg", "[Binary JPEG Image Data Mock]", -178},
|
||||
}
|
||||
for _, f := range vacationFiles {
|
||||
fs.AddFile("/Pictures/Vacation/"+f.name, []byte(f.content), baseTime.AddDate(0, 0, f.days))
|
||||
mfs.AddFile("/Pictures/Vacation/"+f.name, []byte(f.content), baseTime.AddDate(0, 0, f.days))
|
||||
}
|
||||
|
||||
// --- Downloads files ---
|
||||
@@ -130,7 +136,7 @@ func populateMockFileSystem(fs *mock.FileSystem) {
|
||||
{"patch.diff", "--- a/internal/browser/handlers.go\n+++ b/internal/browser/handlers.go\n@@ -65,3 +65,3 @@\n-bm.NavigateTo(newPath)\n+bm.NavigateTo(entry.Path)\n", -3},
|
||||
}
|
||||
for _, f := range downloads {
|
||||
fs.AddFile("/Downloads/"+f.name, []byte(f.content), baseTime.AddDate(0, 0, f.days))
|
||||
mfs.AddFile("/Downloads/"+f.name, []byte(f.content), baseTime.AddDate(0, 0, f.days))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,9 +161,9 @@ func modeCount() int {
|
||||
return 4
|
||||
}
|
||||
|
||||
// buildBrowserIndex converts mock DirEntry results into a browser.DirectoryIndex
|
||||
// buildBrowserIndex converts types.DirEntry results into a browser.DirectoryIndex
|
||||
// with pre-computed position maps for all sort modes.
|
||||
func buildBrowserIndex(entries []mock.DirEntry) *browser.DirectoryIndex {
|
||||
func buildBrowserIndex(entries []types.DirEntry) *browser.DirectoryIndex {
|
||||
var browserEntries []browser.Entry
|
||||
for _, e := range entries {
|
||||
info, err := e.Info()
|
||||
|
||||
Reference in New Issue
Block a user