fsx: Remove environment references

This commit removes the reference to the environment from the fsx
package.
This commit is contained in:
Tom Wiesing 2023-03-02 11:47:11 +01:00
parent 5a43ecfaeb
commit 3263920d6b
No known key found for this signature in database
25 changed files with 167 additions and 183 deletions

View file

@ -24,7 +24,7 @@ type Parser[T any] func(env environment.Environment, s string) (T, error)
// ParseAbspath checks that s is an absolute path and returns it as-is
func ParseAbspath(env environment.Environment, s string) (string, error) {
if !fsx.IsDirectory(env, s) {
if !fsx.IsDirectory(s) {
return "", errors.Errorf("%q does not exist or is not a directory", s)
}
return s, nil
@ -32,7 +32,7 @@ func ParseAbspath(env environment.Environment, s string) (string, error) {
// ParseFile checks that s is a valid file and returns it as-is
func ParseFile(env environment.Environment, s string) (string, error) {
if !fsx.IsFile(env, s) {
if !fsx.IsFile(s) {
return "", errors.Errorf("%q does not exist or is not a regular file", s)
}
return s, nil

View file

@ -39,14 +39,14 @@ func (pcfg PathsConfig) UsingDistilleryExecutable(env environment.Environment) b
if err != nil {
return false
}
return fsx.SameFile(env, exe, pcfg.ExecutablePath())
return fsx.SameFile(exe, pcfg.ExecutablePath())
}
// CurrentExecutable returns the path to the current executable being used.
// When it does not exist, falls back to the default executable.
func (pcfg PathsConfig) CurrentExecutable(env environment.Environment) string {
exe, err := os.Executable()
if err != nil || !fsx.IsFile(env, exe) {
if err != nil || !fsx.IsFile(exe) {
return pcfg.ExecutablePath()
}
return exe

View file

@ -10,7 +10,7 @@ func ValidateFile(env environment.Environment, path *string, dflt string) error
if *path == "" {
*path = dflt
}
if !fsx.IsFile(env, *path) {
if !fsx.IsFile(*path) {
return errors.Errorf("%q does not exist or is not a file", *path)
}
return nil
@ -20,7 +20,7 @@ func ValidateDirectory(env environment.Environment, path *string, dflt string) e
if *path == "" {
*path = dflt
}
if !fsx.IsDirectory(env, *path) {
if !fsx.IsDirectory(*path) {
return errors.Errorf("%q does not exist or is not a directory", *path)
}
return nil

View file

@ -147,7 +147,7 @@ func (sc *stagingContext) CopyFile(dst, src string) error {
return err
}
sc.sendPath(dst)
return fsx.CopyFile(sc.ctx, sc.env, dstPath, src)
return fsx.CopyFile(sc.ctx, dstPath, src)
}
func (sc *stagingContext) CopyDirectory(dst, src string) error {
@ -160,7 +160,7 @@ func (sc *stagingContext) CopyDirectory(dst, src string) error {
return err
}
return fsx.CopyDirectory(sc.ctx, sc.env, dstPath, src, func(dst, src string) {
return fsx.CopyDirectory(sc.ctx, dstPath, src, func(dst, src string) {
sc.sendPath(dst)
})
}

View file

@ -10,7 +10,7 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
"github.com/tkw1536/goprogram/status"
"golang.org/x/exp/slices"
@ -119,7 +119,7 @@ func (backup *Backup) run(ctx context.Context, progress io.Writer, exporter *Exp
defer st.Stop()
instancesBackupDir := filepath.Join(backup.Description.Dest, "instances")
if err := exporter.Environment.Mkdir(instancesBackupDir, environment.DefaultDirPerm); err != nil {
if err := fsx.Mkdir(instancesBackupDir, fsx.DefaultDirPerm); err != nil {
backup.InstanceListErr = err
return nil
}
@ -140,7 +140,7 @@ func (backup *Backup) run(ctx context.Context, progress io.Writer, exporter *Exp
Handler: func(instance *wisski.WissKI, index int, writer io.Writer) Snapshot {
dir := filepath.Join(instancesBackupDir, instance.Slug)
if err := exporter.Environment.Mkdir(dir, environment.DefaultDirPerm); err != nil {
if err := fsx.Mkdir(dir, fsx.DefaultDirPerm); err != nil {
return Snapshot{
ErrPanic: err,
}

View file

@ -12,7 +12,6 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/sql"
"github.com/FAU-CDI/wisski-distillery/internal/passwordx"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/tkw1536/pkglib/password"
)
@ -51,7 +50,7 @@ func (dis *Exporter) ArchivePath() string {
// The path is guaranteed to not exist.
func (dis *Exporter) NewArchivePath(prefix string) (path string) {
// TODO: Consider moving these into a subdirectory with the provided prefix.
for path == "" || fsx.Exists(dis.Environment, path) {
for path == "" || fsx.Exists(path) {
name := dis.newSnapshotName(prefix) + ".tar.gz"
path = filepath.Join(dis.ArchivePath(), name)
}
@ -75,7 +74,7 @@ func (*Exporter) newSnapshotName(prefix string) string {
func (dis *Exporter) NewStagingDir(prefix string) (path string, err error) {
for path == "" || os.IsExist(err) {
path = filepath.Join(dis.StagingPath(), dis.newSnapshotName(prefix))
err = dis.Still.Environment.Mkdir(path, environment.DefaultFilePerm)
err = fsx.Mkdir(path, fsx.DefaultFilePerm)
}
if err != nil {
path = ""

View file

@ -8,7 +8,7 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
"github.com/FAU-CDI/wisski-distillery/pkg/targz"
"github.com/tkw1536/goprogram/status"
@ -74,7 +74,7 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
// create the staging directory
logging.LogMessage(progress, ctx, "Creating staging directory")
err = exporter.Environment.Mkdir(stagingDir, environment.DefaultDirPerm)
err = fsx.Mkdir(stagingDir, fsx.DefaultDirPerm)
if !os.IsExist(err) && err != nil {
return err
}
@ -112,7 +112,7 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
logging.ProgressF(progress, ctx, reportPath)
// create the path
report, err := exporter.Environment.Create(reportPath, environment.DefaultFilePerm)
report, err := fsx.Create(reportPath, fsx.DefaultFilePerm)
if err != nil {
return err
}

View file

@ -43,7 +43,7 @@ func (pv *Provision) Provision(progress io.Writer, ctx context.Context, flags Pr
// check that the base directory does not exist
logging.LogMessage(progress, ctx, "Checking that base directory %s does not exist", instance.FilesystemBase)
if fsx.IsDirectory(pv.Environment, instance.FilesystemBase) {
if fsx.IsDirectory(instance.FilesystemBase) {
return nil, ErrInstanceAlreadyExists
}

View file

@ -7,6 +7,7 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/tkw1536/pkglib/lazy"
)
@ -53,7 +54,7 @@ func (sql *SQL) Stack(env environment.Environment) component.StackWithResources
"HTTPS_ENABLED": sql.Config.HTTP.HTTPSEnabledEnv(),
},
MakeDirsPerm: environment.DefaultDirPerm,
MakeDirsPerm: fsx.DefaultDirPerm,
MakeDirs: []string{
"data",
"imports",

View file

@ -10,7 +10,7 @@ import (
"io"
"os"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
"github.com/gliderlabs/ssh"
@ -119,7 +119,7 @@ func (ssh2 *SSH2) makeHostKey(progress io.Writer, ctx context.Context, key HostK
}
// generate and write private key as PEM
privateKeyFile, err := ssh2.Environment.Create(path, environment.DefaultFilePerm)
privateKeyFile, err := fsx.Create(path, fsx.DefaultFilePerm)
if err != nil {
return err
}

View file

@ -268,7 +268,7 @@ func (is StackWithResources) Install(ctx context.Context, progress io.Writer, co
// copy over file from context
logging.ProgressF(progress, ctx, "[copy] %s (from %s)\n", dst, src)
if err := fsx.CopyFile(ctx, env, dst, src); err != nil {
if err := fsx.CopyFile(ctx, dst, src); err != nil {
return errors.Wrapf(err, "Unable to copy file %s", src)
}
}

View file

@ -5,8 +5,6 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/cli"
"github.com/FAU-CDI/wisski-distillery/internal/config"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/tkw1536/goprogram/exit"
)
@ -23,9 +21,6 @@ var errOpenConfig = exit.Error{
// NewDistillery creates a new distillery from the provided flags
func NewDistillery(params cli.Params, flags cli.Flags, req cli.Requirements) (dis *Distillery, err error) {
dis = &Distillery{
Still: component.Still{
Environment: new(environment.Native),
},
Upstream: Upstream{
SQL: "127.0.0.1:3306",
Triplestore: "127.0.0.1:7200",

View file

@ -34,7 +34,7 @@ var (
// NoPrefix checks if this WissKI instance is excluded from generating prefixes.
// TODO: Move this to the database!
func (prefixes *Prefixes) NoPrefix() bool {
return fsx.IsFile(prefixes.Malt.Environment, filepath.Join(prefixes.FilesystemBase, "prefixes.skip"))
return fsx.IsFile(filepath.Join(prefixes.FilesystemBase, "prefixes.skip"))
}
//go:embed prefixes.php
@ -120,7 +120,7 @@ func hasAnyPrefix(candidate string, prefixes []string) bool {
func (wisski *Prefixes) filePrefixes() (prefixes []string, err error) {
path := filepath.Join(wisski.FilesystemBase, "prefixes")
if !fsx.IsFile(wisski.Malt.Environment, path) {
if !fsx.IsFile(path) {
return nil, nil
}