summaryrefslogtreecommitdiff
path: root/backupDir.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-27 07:20:47 -0500
committerJeff Carr <[email protected]>2024-10-27 07:20:47 -0500
commiteba6f5c1883014558baffbe97be9e24ee9453c44 (patch)
tree73ae333742812da0ef10df360890f008029449b9 /backupDir.go
parent6b5323da11c5c47162d13784f170f37c2f6f74f1 (diff)
filepath.Walk is overkill here
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'backupDir.go')
-rw-r--r--backupDir.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/backupDir.go b/backupDir.go
new file mode 100644
index 0000000..1c633af
--- /dev/null
+++ b/backupDir.go
@@ -0,0 +1,47 @@
+package virtbuf
+
+// thank chatgpt for this because why. why write this if you can have it
+// kick this out in 30 seconds
+
+import (
+ "log"
+ "os"
+ "path/filepath"
+)
+
+func backupDir(srcDir string, destDir string) error {
+ // Create the destination directory
+ err := os.MkdirAll(destDir, os.ModePerm)
+ if err != nil {
+ log.Println("Failed to create directory: %v", err)
+ return err
+ }
+
+ // Walk through the source directory
+ err = filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ return err
+ }
+
+ // Skip if it's not a .test file or if it's a directory
+ // if filepath.Ext(path) != ".json" || info.IsDir() {
+ if info.IsDir() {
+ return nil
+ }
+
+ // Destination file path
+ destPath := filepath.Join(destDir, info.Name())
+
+ // Copy the file
+ if err := copyFile(path, destPath); err != nil {
+ return err
+ }
+ return nil
+ })
+
+ if err != nil {
+ log.Println("Failed to copy files: %v", err)
+ return err
+ }
+ return nil
+}