client io architecture

This commit is contained in:
Ilia Denisov
2026-03-12 18:45:46 +02:00
committed by GitHub
parent 2dafa69b93
commit 079b9facb0
36 changed files with 1810 additions and 460 deletions
+9 -8
View File
@@ -4,6 +4,7 @@ import (
"encoding"
"errors"
"fmt"
"galaxy/util"
"math/big"
"os"
"path/filepath"
@@ -28,13 +29,13 @@ func NewFileStorage(path string) (*fs, error) {
if err != nil {
return nil, fmt.Errorf("path %s invalid: %s", path, err)
}
if ok, err := dirExists(absPath); err != nil {
if ok, err := util.DirExists(absPath); err != nil {
return nil, fmt.Errorf("check dir exist: %s", err)
} else if !ok {
return nil, errors.New("directory does not exist: " + absPath)
}
if ok, err := writable(absPath); err != nil {
if ok, err := util.Writable(absPath); err != nil {
return nil, fmt.Errorf("check dir access: %s", err)
} else if !ok {
return nil, errors.New("directory should have read-write access: " + absPath)
@@ -48,7 +49,7 @@ func NewFileStorage(path string) (*fs, error) {
func (f *fs) Lock() (func() error, error) {
lockPath := f.lockFilePath()
exists, err := fileExists(lockPath)
exists, err := util.FileExists(lockPath)
if err != nil {
return nil, fmt.Errorf("check lock file exists: %s", err)
}
@@ -77,7 +78,7 @@ func (f *fs) Lock() (func() error, error) {
}
func (f *fs) Exists(path string) (bool, error) {
return fileExists(filepath.Join(f.root, path))
return util.FileExists(filepath.Join(f.root, path))
}
func (f *fs) WriteSafe(path string, v encoding.BinaryMarshaler) error {
@@ -97,7 +98,7 @@ func (f *fs) WriteSafe(path string, v encoding.BinaryMarshaler) error {
targetDir := filepath.Dir(targetFilePath)
if targetDir != f.root {
ok, err := dirExists(targetDir)
ok, err := util.DirExists(targetDir)
if err != nil {
return fmt.Errorf("check target dir exists: %s", err)
}
@@ -110,12 +111,12 @@ func (f *fs) WriteSafe(path string, v encoding.BinaryMarshaler) error {
}
oldFilePath := targetFilePath + oldFileSuffix
targetExists, err := fileExists(targetFilePath)
targetExists, err := util.FileExists(targetFilePath)
if err != nil {
return fmt.Errorf("check target file exists: %s", err)
}
if targetExists {
oldFileExists, err := fileExists(oldFilePath)
oldFileExists, err := util.FileExists(oldFilePath)
if err != nil {
return fmt.Errorf("check old file exists: %s", err)
}
@@ -125,7 +126,7 @@ func (f *fs) WriteSafe(path string, v encoding.BinaryMarshaler) error {
}
newFilePath := targetFilePath + newFileSuffix
newFileExists, err := fileExists(newFilePath)
newFileExists, err := util.FileExists(newFilePath)
if err != nil {
return fmt.Errorf("check new file exists: %s", err)
}