summaryrefslogtreecommitdiff
path: root/backup.go
blob: de87880a2e630216d8ade7afe761a8055ca982d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
		}

		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
}
*/