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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user