From ea56ff4aac96354045e3da4541ea30710351465e Mon Sep 17 00:00:00 2001 From: Tom Wiesing Date: Fri, 30 Sep 2022 18:33:42 +0200 Subject: [PATCH] {backup,snapshot,system_update}: Use better UI --- cmd/backup.go | 20 +++-- cmd/snapshot.go | 8 +- cmd/system_update.go | 16 +--- go.mod | 14 ++-- go.sum | 25 +++--- internal/backup/backup.go | 159 ++++++++++++++++++++---------------- internal/backup/context.go | 2 +- internal/backup/report.go | 2 + internal/wisski/backup.go | 1 - internal/wisski/snapshot.go | 32 +++++++- pkg/opgroup/opgroup.go | 4 +- 11 files changed, 168 insertions(+), 115 deletions(-) delete mode 100644 internal/wisski/backup.go diff --git a/cmd/backup.go b/cmd/backup.go index 2aac230..ab44db4 100644 --- a/cmd/backup.go +++ b/cmd/backup.go @@ -8,15 +8,17 @@ import ( "github.com/FAU-CDI/wisski-distillery/pkg/logging" "github.com/FAU-CDI/wisski-distillery/pkg/targz" "github.com/tkw1536/goprogram/exit" + "github.com/tkw1536/goprogram/status" ) // Backup is the 'backup' command var Backup wisski_distillery.Command = backupC{} type backupC struct { - NoPrune bool `short:"n" long:"no-prune" description:"Do not prune older backup archives"` - StagingOnly bool `short:"s" long:"staging-only" description:"Do not package into a backup archive, but only create a staging directory"` - Positionals struct { + NoPrune bool `short:"n" long:"no-prune" description:"Do not prune older backup archives"` + StagingOnly bool `short:"s" long:"staging-only" description:"Do not package into a backup archive, but only create a staging directory"` + ConcurrentSnapshots int `short:"c" long:"concurrent-snapshots" description:"Maximum number of concurrent snapshots" default:"2"` + Positionals struct { Dest string `positional-arg-name:"DEST" description:"Destination path to write backup archive to. Defaults to the snapshots/archives/ directory"` } `positional-args:"true"` } @@ -81,8 +83,9 @@ func (bk backupC) Run(context wisski_distillery.Context) error { logging.LogOperation(func() error { backup := backup.New(context.IOStream, dis, backup.Description{ - Dest: sPath, - Auto: bk.Positionals.Dest == "", + Dest: sPath, + Auto: bk.Positionals.Dest == "", + ConcurrentSnapshots: bk.ConcurrentSnapshots, }) backup.WriteReport(dis.Core.Environment, context.IOStream) return nil @@ -105,10 +108,13 @@ func (bk backupC) Run(context wisski_distillery.Context) error { if err := logging.LogOperation(func() error { context.IOStream.Println(archivePath) + st := status.NewWithCompat(context.Stdout, 1) + st.Start() + defer st.Stop() + count, err = targz.Package(dis.Core.Environment, archivePath, sPath, func(dst, src string) { - context.Printf("\033[2K\r%s", dst) + st.Set(0, dst) }) - context.Println("") return err }, context.IOStream, "Writing backup archive"); err != nil { return errSnapshotFailed.Wrap(err) diff --git a/cmd/snapshot.go b/cmd/snapshot.go index 3d7f914..2832c38 100644 --- a/cmd/snapshot.go +++ b/cmd/snapshot.go @@ -10,6 +10,7 @@ import ( "github.com/FAU-CDI/wisski-distillery/pkg/logging" "github.com/FAU-CDI/wisski-distillery/pkg/targz" "github.com/tkw1536/goprogram/exit" + "github.com/tkw1536/goprogram/status" ) // Snapshot creates a snapshot of an instance @@ -115,10 +116,13 @@ func (bi snapshot) Run(context wisski_distillery.Context) error { if err := logging.LogOperation(func() error { context.IOStream.Println(archivePath) + st := status.NewWithCompat(context.Stdout, 1) + st.Start() + defer st.Stop() + count, err = targz.Package(dis.Core.Environment, archivePath, sPath, func(dst, src string) { - context.Printf("\033[2K\r%s", dst) + st.Set(0, dst) }) - context.Println("") return err }, context.IOStream, "Writing snapshot archive"); err != nil { return errSnapshotFailed.Wrap(err) diff --git a/cmd/system_update.go b/cmd/system_update.go index 722d234..c0dce85 100644 --- a/cmd/system_update.go +++ b/cmd/system_update.go @@ -11,8 +11,8 @@ import ( "github.com/FAU-CDI/wisski-distillery/pkg/fsx" "github.com/FAU-CDI/wisski-distillery/pkg/logging" "github.com/tkw1536/goprogram/exit" - "github.com/tkw1536/goprogram/lib/status" "github.com/tkw1536/goprogram/parser" + "github.com/tkw1536/goprogram/status" "github.com/tkw1536/goprogram/stream" ) @@ -111,18 +111,12 @@ func (si systemupdate) Run(context wisski_distillery.Context) error { } if err := logging.LogOperation(func() error { - group := &status.Group[component.Installable]{ - Writer: context.Stdout, + return status.RunErrorGroup(context.Stdout, status.Group[component.Installable, error]{ PrefixString: func(item component.Installable, index int) string { return fmt.Sprintf("[install %q]: ", item.Name()) }, PrefixAlign: true, - ErrString: func(item component.Installable, index int, err error) string { - if err == nil { - return "ok" - } - return "failed (" + err.Error() + ")" - }, + Handler: func(item component.Installable, index int, writer io.Writer) error { io := stream.NewIOStream(writer, writer, stream.Null, 0) stack := item.Stack(context.Environment.Environment) @@ -137,9 +131,7 @@ func (si systemupdate) Run(context wisski_distillery.Context) error { return nil }, - } - - return group.Run(dis.Installables()) + }, dis.Installables()) }, context.IOStream, "Performing Stack Updates"); err != nil { return err } diff --git a/go.mod b/go.mod index 25da022..a980bf4 100644 --- a/go.mod +++ b/go.mod @@ -9,17 +9,19 @@ require ( github.com/feiin/sqlstring v0.3.0 github.com/go-sql-driver/mysql v1.6.0 github.com/pkg/errors v0.9.1 - github.com/tkw1536/goprogram v0.0.13 - golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 - golang.org/x/sync v0.0.0-20220907140024-f12130a52804 + github.com/tkw1536/goprogram v0.0.17 + golang.org/x/exp v0.0.0-20220929160808-de9c53c655b9 + golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0 gorm.io/driver/mysql v1.3.6 - gorm.io/gorm v1.23.8 + gorm.io/gorm v1.23.10 ) require ( + github.com/gosuri/uilive v0.0.4 // indirect github.com/jessevdk/go-flags v1.5.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect - golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2 // indirect - golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect + github.com/mattn/go-isatty v0.0.16 // indirect + golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect + golang.org/x/term v0.0.0-20220919170432-7a66f970e087 // indirect ) diff --git a/go.sum b/go.sum index deef222..11ad57b 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/feiin/sqlstring v0.3.0 h1:iyPEFijI2BxpY2M+AuhIvdNManzXa2OwGzuPaEMLUgo github.com/feiin/sqlstring v0.3.0/go.mod h1:xpZTjVUw1nD3hMgF9SMRdPiooKSikLf4PS5j2NTn3RI= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/gosuri/uilive v0.0.4 h1:hUEBpQDj8D8jXgtCdBu7sWsy5sbW/5GhuO8KBwJ2jyY= +github.com/gosuri/uilive v0.0.4/go.mod h1:V/epo5LjjlDE5RJUcqx8dbw+zc93y5Ya3yg8tfZ74VI= github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc= github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= @@ -15,23 +17,26 @@ github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkr github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/tkw1536/goprogram v0.0.12 h1:CJI79IieP750q9j27OmoB1J/PC4povjk8kdckPVJ1YQ= -github.com/tkw1536/goprogram v0.0.12/go.mod h1:rX9MKOpJ9qAu4jHV2+n64SKmm3c2D3Hh1V8zC1H3jB4= -github.com/tkw1536/goprogram v0.0.13 h1:tq36MGZ24T+Xjv8y+bWbMGv2zx5prJ7tmi/bvs3wemA= -github.com/tkw1536/goprogram v0.0.13/go.mod h1:rX9MKOpJ9qAu4jHV2+n64SKmm3c2D3Hh1V8zC1H3jB4= +github.com/tkw1536/goprogram v0.0.17 h1:SAD/rHtxm7CTEdUV1a37LUyE6G0MdcKhLzO8fZ8cFKI= +github.com/tkw1536/goprogram v0.0.17/go.mod h1:Jqs0sTMzhrAGCX3JQrlEwQ0WRWQACCvuQQkaBDp65pE= golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E= golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= -golang.org/x/exp v0.0.0-20220921164117-439092de6870 h1:j8b6j9gzSigH28O5SjSpQSSh9lFd6f5D/q0aHjNTulc= -golang.org/x/exp v0.0.0-20220921164117-439092de6870/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= +golang.org/x/exp v0.0.0-20220929160808-de9c53c655b9 h1:lNtcVz/3bOstm7Vebox+5m3nLh/BYWnhmc3AhXOW6oI= +golang.org/x/exp v0.0.0-20220929160808-de9c53c655b9/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= golang.org/x/sync v0.0.0-20220907140024-f12130a52804 h1:0SH2R3f1b1VmIMG7BXbEZCBUu2dKmHschSmjqGUrW8A= golang.org/x/sync v0.0.0-20220907140024-f12130a52804/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0 h1:cu5kTvlzcw1Q5S9f5ip1/cpiB4nXvw1XYzFPGgzLUOY= +golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2 h1:wM1k/lXfpc5HdkJJyW9GELpd8ERGdnh8sMGL6Gzq3Ho= golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 h1:h+EGohizhe9XlX18rfpa8k8RAc5XyaeamM+0VHRd4lc= -golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI= +golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc= golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220919170432-7a66f970e087 h1:tPwmk4vmvVCMdr98VgL4JH+qZxPL8fqlUOHnyOM8N3w= @@ -40,5 +45,5 @@ gorm.io/driver/mysql v1.3.6 h1:BhX1Y/RyALb+T9bZ3t07wLnPZBukt+IRkMn8UZSNbGM= gorm.io/driver/mysql v1.3.6/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c= gorm.io/gorm v1.23.8 h1:h8sGJ+biDgBA1AD1Ha9gFCx7h8npU7AsLdlkX0n2TpE= gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= -gorm.io/gorm v1.23.9 h1:NSHG021i+MCznokeXR3udGaNyFyBQJW8MbjrJMVCfGw= -gorm.io/gorm v1.23.9/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA= +gorm.io/gorm v1.23.10 h1:4Ne9ZbzID9GUxRkllxN4WjJKpsHx8YbKvekVdgyWh24= +gorm.io/gorm v1.23.10/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA= diff --git a/internal/backup/backup.go b/internal/backup/backup.go index 0d71ca3..509a6bc 100644 --- a/internal/backup/backup.go +++ b/internal/backup/backup.go @@ -2,14 +2,17 @@ package backup import ( + "fmt" + "io" "path/filepath" - "sync" "time" "github.com/FAU-CDI/wisski-distillery/internal/component" + "github.com/FAU-CDI/wisski-distillery/internal/component/instances" "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/tkw1536/goprogram/status" "github.com/tkw1536/goprogram/stream" "golang.org/x/exp/slices" ) @@ -35,59 +38,95 @@ func New(io stream.IOStream, dis *wisski.Distillery, description Description) (b return } -type backupResult struct { - name string - err error -} +func (backup *Backup) run(ios stream.IOStream, dis *wisski.Distillery) { + // + // MANIFEST + // -func (backup *Backup) run(io stream.IOStream, dis *wisski.Distillery) { + manifest := make(chan string) // receive all the entries in the manifest + manifestDone := make(chan struct{}) // to signal that everything is finished + go func() { + defer close(manifestDone) + + for file := range manifest { + // get the relative path to the root of the manifest + // or fallback to the absolute path! + path, err := filepath.Rel(backup.Description.Dest, file) + if err != nil { + path = file + } + + // add the file to the manifest array + backup.Manifest = append(backup.Manifest, path) + } + + // sort the manifest + slices.Sort(backup.Manifest) + }() + + // + // BACKUP COMPONENTS + // + + // create a new status display backups := dis.Backupable() - - files := make(chan string, len(backups)) // channel for files being added into the backups - results := make(chan backupResult, len(backups)) // channel for results to be stored into backup.ComponentErrors = make(map[string]error, len(backups)) - wg := &sync.WaitGroup{} // to wait for the results - wg.Add(len(backups)) // tell the group about all the operations - for _, bc := range backups { - go func(bc component.Backupable, context component.BackupContext) { - defer wg.Done() + // Component backup tasks + logging.LogOperation(func() error { + st := status.NewWithCompat(ios.Stdout, 0) + st.Start() + defer st.Stop() - // make the backup and store the result - results <- backupResult{ - name: bc.Name(), - err: bc.Backup(context), - } - }(bc, &context{ - env: dis.Core.Environment, - io: io, - dst: filepath.Join(backup.Description.Dest, bc.BackupName()), - files: files, - }) - } + return status.UseErrorGroup(st, status.Group[component.Backupable, error]{ + PrefixString: func(item component.Backupable, index int) string { + return fmt.Sprintf("[backup %q]: ", item.Name()) + }, + PrefixAlign: true, + + Handler: func(bc component.Backupable, index int, writer io.Writer) error { + // create a new context for the backup! + context := &context{ + env: dis.Core.Environment, + io: stream.NewIOStream(writer, writer, nil, 0), + dst: filepath.Join(backup.Description.Dest, bc.BackupName()), + files: manifest, + } + + backup.ComponentErrors[bc.Name()] = bc.Backup(context) + return nil + }, + }, backups) + }, ios, "Backing up core components") // backup instances - wg.Add(1) - go func() { - defer wg.Done() + logging.LogOperation(func() error { + st := status.NewWithCompat(ios.Stdout, 0) + st.Start() + defer st.Stop() instancesBackupDir := filepath.Join(backup.Description.Dest, "instances") if err := dis.Core.Environment.Mkdir(instancesBackupDir, environment.DefaultDirPerm); err != nil { backup.InstanceListErr = err - return + return nil } // list all instances - instances, err := dis.Instances().All() + wissKIs, err := dis.Instances().All() if err != nil { backup.InstanceListErr = err - return + return nil } - backup.InstanceSnapshots = make([]wisski.Snapshot, len(instances)) - for i, instance := range instances { - backup.InstanceSnapshots[i] = func() wisski.Snapshot { + // re-use the backup of the snapshots + backup.InstanceSnapshots = status.Group[instances.WissKI, wisski.Snapshot]{ + PrefixString: func(item instances.WissKI, index int) string { + return fmt.Sprintf("[snapshot %s]: ", item.Slug) + }, + PrefixAlign: true, + + Handler: func(instance instances.WissKI, index int, writer io.Writer) wisski.Snapshot { dir := filepath.Join(instancesBackupDir, instance.Slug) if err := dis.Core.Environment.Mkdir(dir, environment.DefaultDirPerm); err != nil { return wisski.Snapshot{ @@ -95,44 +134,24 @@ func (backup *Backup) run(io stream.IOStream, dis *wisski.Distillery) { } } - files <- dir - return dis.Snapshot(instance, io.NonInteractive(), wisski.SnapshotDescription{ + manifest <- dir + + return dis.Snapshot(instance, stream.NewIOStream(writer, writer, nil, 0), wisski.SnapshotDescription{ Dest: dir, }) - }() - } + }, + ResultString: func(res wisski.Snapshot, item instances.WissKI, index int) string { + return "done" + }, + WaitString: status.DefaultWaitString[instances.WissKI], + HandlerLimit: backup.Description.ConcurrentSnapshots, + }.Use(st, wissKIs) + return nil + }, ios, "creating instance snapshots") - }() - - // finish processing all the results as soon as the group is done. - go func() { - defer close(results) - wg.Wait() - }() - - // finish the message processing once results are finished. - go func() { - defer close(files) // no more file processing! - for result := range results { - backup.ComponentErrors[result.name] = result.err - } - }() - - for file := range files { - // get the relative path to the root of the manifest. - // nothing *should* go wrong, but in case it does, use the original path. - path, err := filepath.Rel(backup.Description.Dest, file) - if err != nil { - path = file - } - - // write it to the command line - // and also add it to the manifest - io.Printf("\033[2K\r%s", path) - backup.Manifest = append(backup.Manifest, path) - } - slices.Sort(backup.Manifest) // backup the manifest - io.Println("") + // close the manifest + close(manifest) + <-manifestDone // sort the instances manifest slices.SortFunc(backup.InstanceSnapshots, func(a, b wisski.Snapshot) bool { diff --git a/internal/backup/context.go b/internal/backup/context.go index ec0d700..ace658d 100644 --- a/internal/backup/context.go +++ b/internal/backup/context.go @@ -27,6 +27,7 @@ func (bc *context) sendPath(path string) { return } + bc.io.Println(dst) bc.files <- dst } @@ -93,6 +94,5 @@ func (bc *context) AddFile(path string, op func(file io.Writer) error) error { bc.sendPath(path) // and do whatever they wanted to do - // TODO: Add to the manifest of some sort return op(file) } diff --git a/internal/backup/report.go b/internal/backup/report.go index de4180a..dd3bac2 100644 --- a/internal/backup/report.go +++ b/internal/backup/report.go @@ -19,6 +19,8 @@ import ( type Description struct { Dest string // Destination path Auto bool // Was the path created automatically? + + ConcurrentSnapshots int // maximum number of concurrent snapshots } // Backup describes a backup diff --git a/internal/wisski/backup.go b/internal/wisski/backup.go deleted file mode 100644 index 9a3ff40..0000000 --- a/internal/wisski/backup.go +++ /dev/null @@ -1 +0,0 @@ -package wisski diff --git a/internal/wisski/snapshot.go b/internal/wisski/snapshot.go index 98bec12..c6eab45 100644 --- a/internal/wisski/snapshot.go +++ b/internal/wisski/snapshot.go @@ -16,6 +16,7 @@ import ( "github.com/FAU-CDI/wisski-distillery/pkg/logging" "github.com/FAU-CDI/wisski-distillery/pkg/opgroup" "github.com/FAU-CDI/wisski-distillery/pkg/password" + "github.com/tkw1536/goprogram/status" "github.com/tkw1536/goprogram/stream" "golang.org/x/exp/slices" ) @@ -194,6 +195,10 @@ func (snapshot *Snapshot) makeBlackbox(io stream.IOStream, dis *Distillery, inst og := opgroup.NewOpGroup[string](4) + st := status.NewWithCompat(io.Stdout, 0) + st.Start() + defer st.Stop() + // stop the instance (unless it was explicitly asked to not do so!) if !snapshot.Description.Keepalive { logging.LogMessage(io, "Stopping instance") @@ -207,7 +212,12 @@ func (snapshot *Snapshot) makeBlackbox(io stream.IOStream, dis *Distillery, inst // write bookkeeping information og.GoErr(func(files chan<- string) error { + line := st.OpenLine("[snapshot bookkeeping]: ", "") + defer line.Close() + defer fmt.Fprintln(line, "done") + bkPath := filepath.Join(snapshot.Description.Dest, "bookkeeping.txt") + fmt.Fprintln(line, bkPath) files <- bkPath info, err := dis.Core.Environment.Create(bkPath, environment.DefaultFilePerm) @@ -224,17 +234,29 @@ func (snapshot *Snapshot) makeBlackbox(io stream.IOStream, dis *Distillery, inst // backup the filesystem og.GoErr(func(files chan<- string) error { + line := st.OpenLine("[snapshot filesystem]: ", "") + defer line.Close() + defer fmt.Fprintln(line, "done") + fsPath := filepath.Join(snapshot.Description.Dest, filepath.Base(instance.FilesystemBase)) // copy over whatever is in the base directory + defer fmt.Fprintln(line, "done") return fsx.CopyDirectory(dis.Core.Environment, fsPath, instance.FilesystemBase, func(dst, src string) { + fmt.Fprintln(line, dst) files <- dst }) + }, &snapshot.ErrFilesystem) // backup the graph db repository og.GoErr(func(files chan<- string) error { + line := st.OpenLine("[snapshot triplestore]: ", "") + defer line.Close() + defer fmt.Fprintln(line, "done") + tsPath := filepath.Join(snapshot.Description.Dest, instance.GraphDBRepository+".nq") + fmt.Fprintln(line, tsPath) files <- tsPath nquads, err := dis.Core.Environment.Create(tsPath, environment.DefaultFilePerm) @@ -250,7 +272,12 @@ func (snapshot *Snapshot) makeBlackbox(io stream.IOStream, dis *Distillery, inst // backup the sql database og.GoErr(func(files chan<- string) error { + line := st.OpenLine("[snapshot sql]: ", "") + defer line.Close() + defer fmt.Fprintln(line, "done") + sqlPath := filepath.Join(snapshot.Description.Dest, snapshot.Instance.SqlDatabase+".sql") + fmt.Fprintln(line, sqlPath) files <- sqlPath sql, err := dis.Core.Environment.Create(sqlPath, environment.DefaultFilePerm) @@ -302,12 +329,9 @@ func (snapshot *Snapshot) waitGroup(io stream.IOStream, og *opgroup.OpGroup[stri path = file } - // write it to the command line - // and also add it to the manifest - io.Printf("\033[2K\r%s", path) + // add the manifest snapshot.Manifest = append(snapshot.Manifest, path) } - io.Println("") } // WriteReport writes out the report belonging to this snapshot. diff --git a/pkg/opgroup/opgroup.go b/pkg/opgroup/opgroup.go index a4b0306..5488f06 100644 --- a/pkg/opgroup/opgroup.go +++ b/pkg/opgroup/opgroup.go @@ -4,7 +4,7 @@ package opgroup import "sync" // OpGroup represents an operation group that can send messages to the waiting goroutine. -//The zero value is not ready for use, use [NewOpGroup] instead. +// The zero value is not ready for use, use [NewOpGroup] instead. type OpGroup[M any] struct { wg sync.WaitGroup c chan M @@ -37,7 +37,7 @@ func (op *OpGroup[M]) GoErr(worker func(c chan<- M) error, dest *error) { }) } -// Wait returns a receive-only reference to the message channel.// +// Wait returns a receive-only reference to the message channel. // The message channel will be closed once all operations on this group have completed. // // The Wait function may only be called once.