2023-05-29 20:27:28 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2023-05-30 17:57:42 +00:00
|
|
|
func release_branch(branch string, source_dir string, target_dir string, dryrun bool) {
|
2023-05-29 20:27:28 +00:00
|
|
|
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 {
|
2023-05-30 17:57:42 +00:00
|
|
|
if !(dryrun) {
|
|
|
|
err := os.RemoveAll(target_dir + file.Name())
|
|
|
|
if err != nil {
|
|
|
|
log.Println("error deleting file: ", err)
|
|
|
|
} else {
|
|
|
|
log.Println("removed file: ", file.Name())
|
|
|
|
}
|
2023-05-29 20:27:28 +00:00
|
|
|
} else {
|
2023-05-30 17:57:42 +00:00
|
|
|
log.Println("DRYRUN: delete folder :", file.Name())
|
2023-05-29 20:27:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//move new files to folder
|
|
|
|
for _, file := range checkOldFolder {
|
2023-05-30 17:57:42 +00:00
|
|
|
if !(dryrun) {
|
|
|
|
os.Rename(source_dir+file.Name(), target_dir+file.Name())
|
|
|
|
log.Println("moved file: ", file.Name())
|
|
|
|
} else {
|
|
|
|
log.Println("DRYRUN: move folder: ", file.Name())
|
|
|
|
}
|
2023-05-29 20:27:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|