feat: loader logic

This commit is contained in:
Ilia Denisov
2026-03-15 21:57:42 +02:00
parent 6179dadb5e
commit cc7ecf6667
5 changed files with 117 additions and 96 deletions
+11 -4
View File
@@ -163,10 +163,10 @@ func (s *fsStorage) SaveOrderAsync(id client.GameID, turn uint, o order.Order, c
}()
}
func (s *fsStorage) FileExists(path string) (bool, error) {
func (s *fsStorage) FileExists(path string) (bool, string, error) {
absPath, err := s.resolvePath(path)
if err != nil {
return false, err
return false, "", err
}
var exists bool
@@ -175,7 +175,13 @@ func (s *fsStorage) FileExists(path string) (bool, error) {
exists, opErr = s.fileExistsUnlocked(absPath)
return opErr
})
return exists, err
if err != nil {
return false, "", err
}
if !exists {
return false, "", nil
}
return true, absPath, nil
}
func (s *fsStorage) ReadFile(path string) ([]byte, error) {
@@ -254,7 +260,8 @@ func (s *fsStorage) ListFiles() ([]string, error) {
}
func (s *fsStorage) StateExists() (bool, error) {
return s.FileExists(stateFileName)
exists, _, err := s.FileExists(stateFileName)
return exists, err
}
func (s *fsStorage) LoadState() (client.State, error) {
+16 -1
View File
@@ -172,13 +172,28 @@ func TestRawFileCRUDAndList(t *testing.T) {
t.Fatalf("write beta: %v", err)
}
alphaExists, err := s.FileExists("nested/alpha.txt")
alphaExists, alphaPath, err := s.FileExists("nested/alpha.txt")
if err != nil {
t.Fatalf("file exists: %v", err)
}
if !alphaExists {
t.Fatal("nested/alpha.txt should exist")
}
wantAlphaPath := filepath.Join(s.storageRoot, "nested", "alpha.txt")
if alphaPath != wantAlphaPath {
t.Fatalf("file path = %q, want %q", alphaPath, wantAlphaPath)
}
missingExists, missingPath, err := s.FileExists("missing.txt")
if err != nil {
t.Fatalf("missing file exists: %v", err)
}
if missingExists {
t.Fatal("missing.txt should not exist")
}
if missingPath != "" {
t.Fatalf("missing file path = %q, want empty string", missingPath)
}
alphaData, err := s.ReadFile("nested/alpha.txt")
if err != nil {
+1 -1
View File
@@ -8,7 +8,7 @@ import (
type Storage interface {
UIStorage
FileExists(string) (bool, error)
FileExists(string) (bool, string, error)
ReadFile(string) ([]byte, error)
WriteFile(string, []byte) error
DeleteFile(string) error