diff --git a/client/storage/storage.go b/client/storage/storage.go index 87e4f37..c52bd10 100644 --- a/client/storage/storage.go +++ b/client/storage/storage.go @@ -1,9 +1,7 @@ package storage import ( - "errors" "fmt" - "galaxy/util" "path/filepath" ) @@ -15,26 +13,6 @@ const ( gameDataFileSuffix = ".dat" ) -type storage struct { - root string -} - -// NewStorage returns implementation of the "galaxy/client.Storage" interface -// or nil with a non-nil error when filesystem storage initialisation failed. -func NewStorage(rootPath string) (*storage, error) { - ok, err := util.Writable(rootPath) - if err != nil { - return nil, err - } - if !ok { - return nil, errors.New("user does not have write permissions to the storage root") - } - s := &storage{ - root: rootPath, - } - return s, nil -} - // StateFilePath returns client's state file path relative to the root, // file name and extension are pre-defined constant. func StateFilePath(root string) string { diff --git a/pkg/storage/fs/fs.go b/pkg/storage/fs/fs.go new file mode 100644 index 0000000..72870a4 --- /dev/null +++ b/pkg/storage/fs/fs.go @@ -0,0 +1,27 @@ +// fs implements Storage on filesystem +package fs + +import ( + "errors" + "galaxy/util" +) + +type fs struct { + rootPath string +} + +// NewStorage returns on-filesystem implementation of the "galaxy/storage.Storage" with root located at rootPath. +// rootPath must me a directory and has write access to the current user. If initial checks failed, return nil and non-nil error. +func NewFS(rootPath string) (*fs, error) { + ok, err := util.Writable(rootPath) + if err != nil { + return nil, err + } + if !ok { + return nil, errors.New("user does not have write permissions to the storage root") + } + s := &fs{ + rootPath: rootPath, + } + return s, nil +} diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index d5227c5..07dec59 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -11,9 +11,11 @@ import ( type Storage interface { UIStorage - Exists(string) (bool, error) + FileExists(string) (bool, error) ReadFile(string) ([]byte, error) WriteFile(string, []byte) error + DeleteFile(string) error + ListFiles() ([]string, error) } // UIStorage manages Client's data local storing and retrieval.