Use fsx package and friends from pkglib
This commit is contained in:
parent
1f8c55da7c
commit
0f6803f890
35 changed files with 91 additions and 493 deletions
|
|
@ -10,8 +10,8 @@ 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/fsx"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
"github.com/tkw1536/pkglib/fsx/umaskfree"
|
||||
"github.com/tkw1536/pkglib/status"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
|
@ -118,7 +118,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 := fsx.Mkdir(instancesBackupDir, fsx.DefaultDirPerm); err != nil {
|
||||
if err := umaskfree.Mkdir(instancesBackupDir, umaskfree.DefaultDirPerm); err != nil {
|
||||
backup.InstanceListErr = err
|
||||
return nil
|
||||
}
|
||||
|
|
@ -139,7 +139,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 := fsx.Mkdir(dir, fsx.DefaultDirPerm); err != nil {
|
||||
if err := umaskfree.Mkdir(dir, umaskfree.DefaultDirPerm); err != nil {
|
||||
return Snapshot{
|
||||
ErrPanic: err,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ 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/fsx"
|
||||
"github.com/tkw1536/pkglib/fsx"
|
||||
"github.com/tkw1536/pkglib/fsx/umaskfree"
|
||||
"github.com/tkw1536/pkglib/password"
|
||||
)
|
||||
|
||||
|
|
@ -75,7 +76,7 @@ func (*Exporter) newSnapshotName(prefix string) string {
|
|||
func (dis *Exporter) NewStagingDir(prefix string) (path string, err error) {
|
||||
for path == "" || errors.Is(err, fs.ErrExist) {
|
||||
path = filepath.Join(dis.StagingPath(), dis.newSnapshotName(prefix))
|
||||
err = fsx.Mkdir(path, fsx.DefaultFilePerm)
|
||||
err = umaskfree.Mkdir(path, umaskfree.DefaultFilePerm)
|
||||
}
|
||||
if err != nil {
|
||||
path = ""
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@ import (
|
|||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
|
||||
"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/pkglib/collection"
|
||||
"github.com/tkw1536/pkglib/fsx/umaskfree"
|
||||
"github.com/tkw1536/pkglib/status"
|
||||
)
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
|
|||
|
||||
// create the staging directory
|
||||
logging.LogMessage(progress, "Creating staging directory")
|
||||
err = fsx.Mkdir(stagingDir, fsx.DefaultDirPerm)
|
||||
err = umaskfree.Mkdir(stagingDir, umaskfree.DefaultDirPerm)
|
||||
if !errors.Is(err, fs.ErrExist) && err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -136,7 +136,7 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
|
|||
reportPath := filepath.Join(stagingDir, ReportMachinePath)
|
||||
fmt.Fprintln(progress, reportPath)
|
||||
|
||||
report, err := fsx.Create(reportPath, fsx.DefaultFilePerm)
|
||||
report, err := umaskfree.Create(reportPath, umaskfree.DefaultFilePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -151,7 +151,7 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
|
|||
reportPath := filepath.Join(stagingDir, ReportPlainPath)
|
||||
fmt.Fprintln(progress, reportPath)
|
||||
|
||||
report, err := fsx.Create(reportPath, fsx.DefaultFilePerm)
|
||||
report, err := umaskfree.Create(reportPath, umaskfree.DefaultFilePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,16 +4,15 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/tkw1536/pkglib/pools"
|
||||
"github.com/tkw1536/pkglib/sequence"
|
||||
)
|
||||
|
||||
func (snapshot Snapshot) String() string {
|
||||
builder := pools.GetBuilder()
|
||||
defer pools.ReleaseBuilder(builder)
|
||||
var builder strings.Builder
|
||||
|
||||
snapshot.ReportPlain(builder)
|
||||
snapshot.ReportPlain(&builder)
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
|
|
@ -68,10 +67,8 @@ func (snapshot Snapshot) ReportPlain(w io.Writer) error {
|
|||
|
||||
// Strings turns this backup into a string for the BackupReport.
|
||||
func (backup Backup) String() string {
|
||||
builder := pools.GetBuilder()
|
||||
defer pools.ReleaseBuilder(builder)
|
||||
|
||||
backup.ReportPlain(builder)
|
||||
var builder strings.Builder
|
||||
backup.ReportPlain(&builder)
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue