diff --git a/pkg/storage/fs/fs.go b/pkg/storage/fs/fs.go index 72870a4..eb16fbc 100644 --- a/pkg/storage/fs/fs.go +++ b/pkg/storage/fs/fs.go @@ -1,27 +1,30 @@ -// fs implements Storage on filesystem +// fs implements galaxy/storage.Storage with filesystem package fs import ( - "errors" + "fmt" "galaxy/util" ) -type fs struct { - rootPath string +type fsStorage struct { + path string } -// NewStorage returns on-filesystem implementation of the "galaxy/storage.Storage" with root located at rootPath. +// NewFS 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 +func NewStorage(path string) (*fsStorage, error) { + if ok, err := util.PathExists(path, true); err != nil { + return nil, fmt.Errorf("new storage: check path %q exists: %w", path, err) + } else if !ok { + return nil, fmt.Errorf("new storage: path %q does not exists", path) } - if !ok { - return nil, errors.New("user does not have write permissions to the storage root") + if ok, err := util.Writable(path); err != nil { + return nil, fmt.Errorf("new storage: check path %q writable: %w", path, err) + } else if !ok { + return nil, fmt.Errorf("new storage: path %q is not writable", path) } - s := &fs{ - rootPath: rootPath, + s := &fsStorage{ + path: path, } return s, nil } diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index 07dec59..ddf85a1 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -1,12 +1,9 @@ package storage import ( - "fmt" - "galaxy/model/client" "galaxy/model/order" "galaxy/model/report" - "galaxy/util" ) type Storage interface { @@ -53,24 +50,3 @@ type UIStorage interface { // I/O or encoding error may occur, it that case callback func will be called with non-nil error. PutOrder(client.GameID, uint, order.Order, func(error)) } - -type storage struct { - path string -} - -func NewStorage(path string) (*storage, error) { - if ok, err := util.PathExists(path, true); err != nil { - return nil, fmt.Errorf("new storage: check path %q exists: %w", path, err) - } else if !ok { - return nil, fmt.Errorf("new storage: path %q does not exists", path) - } - if ok, err := util.Writable(path); err != nil { - return nil, fmt.Errorf("new storage: check path %q writable: %w", path, err) - } else if !ok { - return nil, fmt.Errorf("new storage: path %q is not writable", path) - } - s := &storage{ - path: path, - } - return s, nil -}