Add 'environment' package

This commit adds a new environment package that manages all calls to the
underlying operating system.
This commit is contained in:
Tom Wiesing 2022-09-18 14:24:22 +02:00
parent 822c70cd69
commit f19619ef9f
No known key found for this signature in database
60 changed files with 539 additions and 308 deletions

View file

@ -2,11 +2,11 @@ package cmd
import (
"io/fs"
"os"
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/internal/core"
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
"github.com/FAU-CDI/wisski-distillery/pkg/targz"
"github.com/tkw1536/goprogram/exit"
@ -60,7 +60,7 @@ func (bi snapshot) Run(context wisski_distillery.Context) error {
}
defer func() {
logging.LogMessage(context.IOStream, "Removing snapshot staging directory")
os.RemoveAll(sPath)
dis.Core.Environment.RemoveAll(sPath)
}()
} else {
// staging mode: use dest as a destination
@ -74,8 +74,8 @@ func (bi snapshot) Run(context wisski_distillery.Context) error {
// create the directory (if it doesn't already exist)
logging.LogMessage(context.IOStream, "Creating staging directory")
err = os.Mkdir(sPath, fs.ModePerm)
if !os.IsExist(err) && err != nil {
err = dis.Core.Environment.Mkdir(sPath, fs.ModePerm)
if !environment.IsExist(err) && err != nil {
return errSnapshotFailed.WithMessageF(err)
}
err = nil
@ -92,7 +92,7 @@ func (bi snapshot) Run(context wisski_distillery.Context) error {
})
// write out the report, ignoring any errors!
sreport.WriteReport(context.IOStream)
sreport.WriteReport(dis.Core.Environment, context.IOStream)
return nil
}, context.IOStream, "Generating Snapshot")
@ -115,7 +115,7 @@ func (bi snapshot) Run(context wisski_distillery.Context) error {
if err := logging.LogOperation(func() error {
context.IOStream.Println(archivePath)
count, err = targz.Package(archivePath, sPath, func(dst, src string) {
count, err = targz.Package(dis.Core.Environment, archivePath, sPath, func(dst, src string) {
context.Printf("\033[2K\r%s", dst)
})
context.Println("")