pkg/environment: Migrate fs functions to fsx
This commit is contained in:
parent
45540ab253
commit
5a43ecfaeb
21 changed files with 155 additions and 199 deletions
|
|
@ -126,7 +126,7 @@ func (sc *stagingContext) AddDirectory(path string, op func(context.Context) err
|
|||
}
|
||||
|
||||
// run the make directory
|
||||
if err := sc.env.Mkdir(dst, environment.DefaultDirPerm); err != nil {
|
||||
if err := fsx.Mkdir(dst, fsx.DefaultDirPerm); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -178,7 +178,7 @@ func (sc *stagingContext) AddFile(path string, op func(ctx context.Context, file
|
|||
}
|
||||
|
||||
// create the file
|
||||
file, err := sc.env.Create(dst, environment.DefaultFilePerm)
|
||||
file, err := fsx.Create(dst, fsx.DefaultFilePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package exporter
|
|||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
|
|
@ -72,7 +73,7 @@ func (*Exporter) newSnapshotName(prefix string) string {
|
|||
// NewStagingDir returns the path to a new snapshot directory.
|
||||
// The directory is guaranteed to have been freshly created.
|
||||
func (dis *Exporter) NewStagingDir(prefix string) (path string, err error) {
|
||||
for path == "" || environment.IsExist(err) {
|
||||
for path == "" || os.IsExist(err) {
|
||||
path = filepath.Join(dis.StagingPath(), dis.newSnapshotName(prefix))
|
||||
err = dis.Still.Environment.Mkdir(path, environment.DefaultFilePerm)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,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)
|
||||
if !environment.IsExist(err) && err != nil {
|
||||
if !os.IsExist(err) && err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/sql"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/status"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
"github.com/tkw1536/pkglib/collection"
|
||||
"github.com/tkw1536/pkglib/reflectx"
|
||||
)
|
||||
|
|
@ -64,7 +63,7 @@ func (log *Logger) Log(ctx context.Context) ([]models.Export, error) {
|
|||
// partition out the exports that have been deleted!
|
||||
parts := collection.Partition(exports, func(s models.Export) bool {
|
||||
_, err := os.Stat(s.Path)
|
||||
return !environment.IsNotExist(err)
|
||||
return !os.IsNotExist(err)
|
||||
})
|
||||
|
||||
// go and delete them!
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ package templating
|
|||
import (
|
||||
_ "embed"
|
||||
"html/template"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
"os"
|
||||
)
|
||||
|
||||
//go:embed "src/footer.html"
|
||||
|
|
@ -16,7 +15,7 @@ func (tpl *Templating) GetCustomizable(dflt *template.Template) *template.Templa
|
|||
name := dflt.Name()
|
||||
|
||||
custom, err := (func() (*template.Template, error) {
|
||||
data, err := environment.ReadFile(tpl.Environment, tpl.CustomAssetPath(name))
|
||||
data, err := os.ReadFile(tpl.CustomAssetPath(name))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ func (ssh2 *SSH2) UseOrMakeHostKey(progress io.Writer, ctx context.Context, serv
|
|||
func (ssh2 *SSH2) ReadOrMakeHostKey(progress io.Writer, ctx context.Context, privateKeyPath string, algorithm HostKeyAlgorithm) (key gossh.Signer, err error) {
|
||||
hostKey := NewHostKey(algorithm)
|
||||
|
||||
if _, e := os.Lstat(privateKeyPath); environment.IsNotExist(e) { // path doesn't exist => generate a new key there!
|
||||
if _, e := os.Lstat(privateKeyPath); os.IsNotExist(e) { // path doesn't exist => generate a new key there!
|
||||
err = ssh2.makeHostKey(progress, ctx, hostKey, privateKeyPath)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "Unable to generate new host key")
|
||||
|
|
@ -84,7 +84,7 @@ func (ssh2 *SSH2) loadHostKey(progress io.Writer, ctx context.Context, key HostK
|
|||
logging.ProgressF(progress, ctx, "Loading hostkey (algorithm %s) from %q", key.Algorithm(), path)
|
||||
|
||||
// read all the bytes from the file
|
||||
privateKeyBytes, err := environment.ReadFile(ssh2.Environment, path)
|
||||
privateKeyBytes, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "Unable to read private key bytes")
|
||||
return
|
||||
|
|
|
|||
|
|
@ -248,9 +248,9 @@ func (is StackWithResources) Install(ctx context.Context, progress io.Writer, co
|
|||
|
||||
logging.ProgressF(progress, ctx, "[make] %s\n", dst)
|
||||
if is.MakeDirsPerm == fs.FileMode(0) {
|
||||
is.MakeDirsPerm = environment.DefaultDirPerm
|
||||
is.MakeDirsPerm = fsx.DefaultDirPerm
|
||||
}
|
||||
if err := env.MkdirAll(dst, is.MakeDirsPerm); err != nil {
|
||||
if err := fsx.MkdirAll(dst, is.MakeDirsPerm); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -279,7 +279,7 @@ func (is StackWithResources) Install(ctx context.Context, progress io.Writer, co
|
|||
dst := filepath.Join(is.Dir, name)
|
||||
|
||||
logging.ProgressF(progress, ctx, "[touch] %s\n", dst)
|
||||
if err := fsx.Touch(env, dst, is.TouchFilesPerm); err != nil {
|
||||
if err := fsx.Touch(dst, is.TouchFilesPerm); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue