critical fixes

This commit is contained in:
AustrianToast 2024-09-12 19:01:16 +02:00
parent 66ca74441d
commit 3645f7f30c
Signed by: AustrianToast
GPG Key ID: 174D780E041684FF

View File

@ -95,6 +95,55 @@ func zipIt(pathToZip string, pathToFiles string) error {
return nil
}
func _CopyDir(source string, destination string) error {
srcDir, err := os.Stat(source)
if err != nil {
return err
}
if !srcDir.IsDir() {
return fmt.Errorf("source is not a directory")
}
dstDir, err := os.Stat(destination)
if err != nil {
return err
}
if !dstDir.IsDir() {
return fmt.Errorf("destination is not a directory")
}
return nil
}
func _CopyFile(source string, destination string) error {
srcFile, err := os.Open(source)
dstFile, err := os.Create(destination)
_, err = io.Copy(dstFile, srcFile)
if err != nil {
return err
}
err = dstFile.Sync()
if err != nil {
return err
}
err = srcFile.Close()
if err != nil {
return err
}
err = dstFile.Close()
if err != nil {
return err
}
return nil
}
func backup(when string) error {
var err error
tmpPath := fmt.Sprint("/tmp/update/", when, "_backup")
@ -116,12 +165,12 @@ func backup(when string) error {
return err
}
err = os.WriteFile(fmt.Sprint(tmpPath, fmt.Sprint(when, "_pacman.txt")), output, 0644)
err = os.WriteFile(fmt.Sprint(tmpPath, "/", when, "_pacman.txt"), output, 0666)
if err != nil {
return err
}
if when != "post" {
if strings.Compare(when, "post") != 0 {
err = CopyDir(pacmanDb, fmt.Sprint(tmpPath, "/", pacmanDb))
if err != nil {
return err
@ -136,7 +185,7 @@ func backup(when string) error {
}
for _, backup_location := range backup_locations {
err = CopyFile(pathToZip, fmt.Sprint(backup_location, "/", when, "_backup_", current_time, ".zip"))
err = _CopyFile(pathToZip, fmt.Sprint(backup_location, "/", when, "_backup_", current_time, ".zip"))
if err != nil {
return err
}