From f9cb700a6045d8f2c5d3adb87fb6256125576e36 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 26 Sep 2025 20:02:33 -0500 Subject: add a simple config proto file --- Makefile | 5 ++++- backup.go | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ config.proto | 20 +++++++++++++++++ configBackup.go | 67 --------------------------------------------------------- 4 files changed, 91 insertions(+), 68 deletions(-) create mode 100644 backup.go create mode 100644 config.proto delete mode 100644 configBackup.go diff --git a/Makefile b/Makefile index 72f0e65..bdcc4b0 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: goimports vet +all: config.pb.go goimports vet vet: @GO111MODULE=off go vet @@ -12,3 +12,6 @@ clean: rm -f *.pb.go *.patch -rm -f go.* -go-mod-clean purge + +config.pb.go: config.proto + autogenpb --proto config.proto diff --git a/backup.go b/backup.go new file mode 100644 index 0000000..8d149c9 --- /dev/null +++ b/backup.go @@ -0,0 +1,67 @@ +package config + +// thank chatgpt for this because why. why write this if you can have it +// kick this out in 30 seconds + +/* +func (f *Forge) backupConfig() error { + // make a new dir to backup the files + srcDir := filepath.Join(f.configDir) + destDir := filepath.Join(f.configDir, "backup") + return backupFiles(srcDir, destDir) +} + +func backupFiles(srcDir string, destDir string) error { + // Create the destination directory + err := os.MkdirAll(destDir, os.ModePerm) + if err != nil { + return errors.New(fmt.Sprintf("Failed to create directory: %v", err)) + } + + // Read the contents of the source directory + entries, err := os.ReadDir(srcDir) + if err != nil { + return errors.New(fmt.Sprintf("Failed to read directory: %v", err)) + } + + // 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() { + continue + } + + // log.Println("backing up file", entry.Name()) + srcPath := filepath.Join(srcDir, entry.Name()) + destPath := filepath.Join(destDir, entry.Name()) + + // Copy the file + if err := copyFile(srcPath, destPath); err != nil { + return errors.New(fmt.Sprintf("Failed to copy file %s: %v", entry.Name(), err)) + } + } + return nil +} + +// copyFile copies a file from src to dest +func copyFile(src, dest string) error { + srcFile, err := os.Open(src) + if err != nil { + return err + } + defer srcFile.Close() + + now := time.Now() + timestamp := now.Format("2006.01.02.150405") // bummer. other date doesn't work? + dest = dest + timestamp + destFile, err := os.Create(dest) + if err != nil { + return err + } + defer destFile.Close() + + // Copy the content + _, err = io.Copy(destFile, srcFile) + return err +} +*/ diff --git a/config.proto b/config.proto new file mode 100644 index 0000000..b86de8f --- /dev/null +++ b/config.proto @@ -0,0 +1,20 @@ +// Copyright 2025 WIT.COM Inc Licensed GPL 3.0 + +syntax = "proto3"; + +package config; + +import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp + +message Config { // + string name = 1; // a map for what thing? + map vals = 2; // a simple map + google.protobuf.Timestamp ctime = 3; // create time of the patch +} + +message Configs { // `autogenpb:marshal` `autogenpb:nomutex` + string uuid = 1; // `autogenpb:uuid:3135d0f9-82a9-40b6-8aa1-b683ebe7bedd` + string version = 2; // `autogenpb:version:v0.0.1 go.wit.com/lib/config` + repeated Config configs = 3; + string filename = 4; // can store where the filename is so that saves can be automated +} diff --git a/configBackup.go b/configBackup.go deleted file mode 100644 index 8d149c9..0000000 --- a/configBackup.go +++ /dev/null @@ -1,67 +0,0 @@ -package config - -// thank chatgpt for this because why. why write this if you can have it -// kick this out in 30 seconds - -/* -func (f *Forge) backupConfig() error { - // make a new dir to backup the files - srcDir := filepath.Join(f.configDir) - destDir := filepath.Join(f.configDir, "backup") - return backupFiles(srcDir, destDir) -} - -func backupFiles(srcDir string, destDir string) error { - // Create the destination directory - err := os.MkdirAll(destDir, os.ModePerm) - if err != nil { - return errors.New(fmt.Sprintf("Failed to create directory: %v", err)) - } - - // Read the contents of the source directory - entries, err := os.ReadDir(srcDir) - if err != nil { - return errors.New(fmt.Sprintf("Failed to read directory: %v", err)) - } - - // 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() { - continue - } - - // log.Println("backing up file", entry.Name()) - srcPath := filepath.Join(srcDir, entry.Name()) - destPath := filepath.Join(destDir, entry.Name()) - - // Copy the file - if err := copyFile(srcPath, destPath); err != nil { - return errors.New(fmt.Sprintf("Failed to copy file %s: %v", entry.Name(), err)) - } - } - return nil -} - -// copyFile copies a file from src to dest -func copyFile(src, dest string) error { - srcFile, err := os.Open(src) - if err != nil { - return err - } - defer srcFile.Close() - - now := time.Now() - timestamp := now.Format("2006.01.02.150405") // bummer. other date doesn't work? - dest = dest + timestamp - destFile, err := os.Create(dest) - if err != nil { - return err - } - defer destFile.Close() - - // Copy the content - _, err = io.Copy(destFile, srcFile) - return err -} -*/ -- cgit v1.2.3