snapshot: Explicitly export Pathbuilders

This commit updates the 'wdcli snapshot' command to also export
pathbuilders from the system.
This commit is contained in:
Tom Wiesing 2022-09-09 10:12:18 +02:00
parent 477152814a
commit c4de1f2a06
No known key found for this signature in database
5 changed files with 125 additions and 6 deletions

38
env/instances.go vendored
View file

@ -1,6 +1,8 @@
package env
import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/fs"
@ -16,6 +18,8 @@ import (
"github.com/pkg/errors"
"github.com/tkw1536/goprogram/exit"
"github.com/tkw1536/goprogram/stream"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
@ -366,3 +370,37 @@ func (instance *Instance) PrefixConfig() (config string, err error) {
// and done!
return builder.String(), nil
}
var errPathbuildersExecFailed = errors.New("ExportPathbuilders: Failed to call export_pathbuilder")
// ExportPathbuilders writes pathbuilders into the directory dest
func (instance *Instance) ExportPathbuilders(dest string) error {
// export all the pathbuilders into the buffer
var buffer bytes.Buffer
wu := stream.NewIOStream(&buffer, nil, nil, 0)
code, err := instance.Stack().Exec(wu, "barrel", "/bin/bash", "/user_shell.sh", "-c", "drush php:script /wisskiutils/export_pathbuilder.php")
if err != nil || code != 0 {
return errPathbuildersExecFailed
}
// decode them as a json array
var pathbuilders map[string]string
if err := json.NewDecoder(&buffer).Decode(&pathbuilders); err != nil {
return err
}
// sort the names of the pathbuilders
names := maps.Keys(pathbuilders)
slices.Sort(names)
// write each into a file!
for _, name := range names {
pbxml := []byte(pathbuilders[name])
name := filepath.Join(dest, fmt.Sprintf("%s.xml", name))
if err := os.WriteFile(name, pbxml, fs.ModePerm); err != nil {
return err
}
}
return nil
}

19
env/snapshot.go vendored
View file

@ -86,6 +86,7 @@ type Snapshot struct {
ErrStop error
ErrBookkeep error
ErrPathbuilder error
ErrFilesystem error
ErrTriplestore error
ErrSSQL error
@ -145,6 +146,24 @@ func (snapshot *Snapshot) create(io stream.IOStream, instance Instance) {
_, snapshot.ErrBookkeep = fmt.Fprintf(info, "%#v\n", instance.Instance)
}()
// write pathbuilders
wg.Add(1)
go func() {
defer wg.Done()
pbPath := filepath.Join(snapshot.Description.Dest, "pathbuilders")
messages <- pbPath
// create the directory!
if err := os.Mkdir(pbPath, fs.ModeDir); err != nil {
snapshot.ErrPathbuilder = err
return
}
// put in all the pathbuilders
snapshot.ErrPathbuilder = instance.ExportPathbuilders(pbPath)
}()
// backup the filesystem
wg.Add(1)
go func() {