added moving of files

This commit is contained in:
Stefan Hoffmann 2023-05-29 22:18:37 +02:00
parent 685f80988e
commit 6a0baa278c
Signed by: stefan
GPG Key ID: 8EFC7042BF8D5CDD

41
main.go
View File

@ -2,17 +2,54 @@ package main
import ( import (
"flag" "flag"
"fmt"
"log" "log"
"os"
_ "github.com/codingsince1985/checksum" _ "github.com/codingsince1985/checksum"
) )
func main() { func main() {
var source_dir = flag.String("source_dir", "./", "Path to image folder (/srv/fwuploads-tmp/)") var source_dir = flag.String("source_dir", "./", "Path to image folder (/srv/fwuploads-tmp/)")
var target_dir = flag.String("target_dir", "./", "Path to image folder in public (/srv/fwuploads/troisdorf)")
var branch = flag.String("branch", "", "Branch to work with")
flag.Parse() flag.Parse()
sdir := *source_dir
err := generate_manifest(*source_dir) tdir := *target_dir
br := *branch
var source_dir_branch string = sdir + br + "/"
var target_dir_branch string = tdir + br + "/"
err := generate_manifest(source_dir_branch)
if err != nil { if err != nil {
log.Println("Error generating Manifest file: ", err) log.Println("Error generating Manifest file: ", err)
} }
release_branch(*branch, source_dir_branch, target_dir_branch)
}
func release_branch(branch string, source_dir string, target_dir string) {
checkOldFolder, _ := os.ReadDir(source_dir)
checkNewFolder, _ := os.ReadDir(target_dir)
var newImages bool = false
if len(checkOldFolder) > 0 {
newImages = true
}
if newImages {
// delete old firmware files in public folder
for _, file := range checkNewFolder {
err := os.Remove(target_dir + file.Name())
if err != nil {
log.Println("error deleting file: ", err)
} else {
log.Println("removed file: ", file.Name())
}
}
//move new files to folder
for _, file := range checkOldFolder {
os.Rename(source_dir+file.Name(), target_dir+file.Name())
fmt.Println("moved file: ", file.Name())
}
}
} }