Enhance DiskFS initialization and error handling

- Updated `disk.New` to support asynchronous initialization for large caches, improving responsiveness during startup.
- Introduced an eviction function parameter to `disk.New`, ensuring proper handling of over-capacity scenarios.
- Enhanced error handling in various components, including memory and disk tests, to ensure robustness and clarity.
- Refactored tests to validate new behaviors, including checks for delayed attachment and proper error propagation.
- Removed obsolete error handling code and tests related to the now-deleted errors package, streamlining the codebase.
This commit is contained in:
2026-05-27 13:15:33 -05:00
parent 4861f93e6f
commit feda55e225
18 changed files with 584 additions and 1380 deletions
+4 -3
View File
@@ -3,6 +3,7 @@ package memory
import (
"bytes"
"fmt"
"io"
"s1d3sw1ped/steamcache2/vfs"
"s1d3sw1ped/steamcache2/vfs/locks"
@@ -35,9 +36,9 @@ type MemoryFS struct {
}
// New creates a new MemoryFS
func New(capacity int64) *MemoryFS {
func New(capacity int64) (*MemoryFS, error) {
if capacity <= 0 {
panic("memory capacity must be greater than 0")
return nil, fmt.Errorf("memory capacity must be greater than 0")
}
// Initialize sharded locks
@@ -51,7 +52,7 @@ func New(capacity int64) *MemoryFS {
keyLocks: keyLocks,
LRU: lru.NewLRUList[*types.FileInfo](),
timeUpdater: types.NewBatchedTimeUpdate(100 * time.Millisecond), // Update time every 100ms
}
}, nil
}
// Name returns the name of this VFS