try to actually make real files

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-27 07:49:03 -05:00
parent eba6f5c188
commit 099363089b
3 changed files with 20 additions and 18 deletions

View File

@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
"log"
"os"
"path/filepath"
)
@ -27,10 +28,11 @@ func backupFiles(srcDir string, destDir string) error {
// Iterate over the entries in the source directory
for _, entry := range entries {
// Skip directories and files that do not have the .test extension
if entry.IsDir() || filepath.Ext(entry.Name()) != ".test" {
if entry.IsDir() {
continue
}
log.Println("backing up file", entry.Name())
srcPath := filepath.Join(srcDir, entry.Name())
destPath := filepath.Join(destDir, entry.Name())

View File

@ -9,6 +9,7 @@ import (
"path/filepath"
)
// IsDir() check seems to still enter directories for some reason
func backupDir(srcDir string, destDir string) error {
// Create the destination directory
err := os.MkdirAll(destDir, os.ModePerm)

View File

@ -18,20 +18,19 @@ import (
// writes out the cluster information it seperate files
// to make it humanly possible to hand edit things as needed
func (c *Cluster) ConfigSave() error {
var d *Droplets
d = new(Droplets)
// try to backup the current cluster config files
if err := backupConfigFiles(); err != nil {
return err
}
var d *Droplets
d = new(Droplets)
d.Droplets = c.Droplets
if err := ConfigWriteJSON(d, "newdroplets.json"); err != nil {
if err := ConfigWriteJSON(d, "droplets.json"); err != nil {
fmt.Println("droplets.json write failed")
return err
}
if err := ConfigWriteTEXT(d, "newdroplets.text"); err != nil {
if err := ConfigWriteTEXT(d, "droplets.text"); err != nil {
fmt.Println("droplets.json write failed")
return err
}
@ -39,11 +38,11 @@ func (c *Cluster) ConfigSave() error {
var h *Hypervisors
h = new(Hypervisors)
h.Hypervisors = c.Hypervisors
if err := ConfigWriteJSON(h, "newhypervisors.json"); err != nil {
if err := ConfigWriteJSON(h, "hypervisors.json"); err != nil {
fmt.Println("hypervisors.json write failed")
return err
}
if err := ConfigWriteTEXT(h, "newhypervisors.text"); err != nil {
if err := ConfigWriteTEXT(h, "hypervisors.text"); err != nil {
fmt.Println("hypervisors.json write failed")
return err
}
@ -51,17 +50,17 @@ func (c *Cluster) ConfigSave() error {
var e *Events
e = new(Events)
e.Events = c.Events
if err := ConfigWriteJSON(e, "newEvents.json"); err != nil {
fmt.Println("newEvents.json write failed")
if err := ConfigWriteJSON(e, "events.json"); err != nil {
fmt.Println("events.json write failed")
return err
}
if err := ConfigWriteTEXT(e, "newEvents.text"); err != nil {
fmt.Println("newEvents.json write failed")
if err := ConfigWriteTEXT(e, "events.text"); err != nil {
fmt.Println("events.json write failed")
return err
}
if err := ConfigWriteTEXT(c, "newCluster.text"); err != nil {
fmt.Println("newCluster.json write failed")
if err := ConfigWriteTEXT(c, "cluster.full.text"); err != nil {
fmt.Println("Cluster.json write failed")
return err
}
@ -70,8 +69,8 @@ func (c *Cluster) ConfigSave() error {
newc.Droplets = nil
newc.Hypervisors = nil
newc.Events = nil
if err := ConfigWriteTEXT(&newc, "newSmallCluster.text"); err != nil {
fmt.Println("newSmallCluster.json write failed")
if err := ConfigWriteTEXT(&newc, "cluster.text"); err != nil {
fmt.Println("cluster.json write failed")
return err
}
@ -81,14 +80,14 @@ func (c *Cluster) ConfigSave() error {
func backupConfigFiles() error {
// make a new dir to backup the files
now := time.Now()
timestamp := now.Format("2006.01.02.150405")
timestamp := now.Format("2022.07.18.190545") // 50yr shout out to K&R
srcDir := filepath.Join(os.Getenv("VIRTIGO_HOME"))
destDir := filepath.Join(os.Getenv("VIRTIGO_HOME"), timestamp)
return backupFiles(srcDir, destDir)
}
func (c *Cluster) ConfigLoadOld() error {
func (c *Cluster) ConfigLoadOld2() error {
if c == nil {
return errors.New("It's not safe to run ConfigLoad() on a nil cluster")
}