pkg/environment: Migrate fs functions to fsx

This commit is contained in:
Tom Wiesing 2023-03-02 11:38:30 +01:00
parent 45540ab253
commit 5a43ecfaeb
No known key found for this signature in database
21 changed files with 155 additions and 199 deletions

View file

@ -3,12 +3,14 @@ package cli
import (
"errors"
"io/fs"
"os"
"os/user"
"path/filepath"
"strings"
"github.com/FAU-CDI/wisski-distillery/internal/bootstrap"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
)
// metaConfigFile is the path to a configuration file that contains the path to the last used wdcli executable.
@ -41,7 +43,7 @@ func ReadBaseDirectory(env environment.Environment) (value string, err error) {
}
// read the meta config file!
contents, err := environment.ReadFile(env, path)
contents, err := os.ReadFile(path)
if err != nil {
return "", err
}
@ -67,5 +69,5 @@ func WriteBaseDirectory(env environment.Environment, dir string) error {
}
// just put the directory inside it!
return environment.WriteFile(env, path, []byte(dir), fs.ModePerm)
return fsx.WriteFile(path, []byte(dir), fs.ModePerm)
}

View file

@ -19,11 +19,12 @@ type Params struct {
// ParamsFromEnv creates a new set of parameters from the environment.
// Uses [ReadBaseDirectory] or falls back to [BaseDirectoryDefault].
func ParamsFromEnv() (params Params, err error) {
var native environment.Environment
// try to read the base directory!
value, err := ReadBaseDirectory(new(environment.Native)) // TODO: Are we sure about the native environment here?
value, err := ReadBaseDirectory(native) // TODO: Are we sure about the native environment here?
switch {
case environment.IsNotExist(err):
case os.IsNotExist(err):
params.ConfigPath = bootstrap.BaseDirectoryDefault
case err == nil:
params.ConfigPath = value