Add version to job archive

This commit is contained in:
2023-03-27 13:24:06 +02:00
parent ff8f013b56
commit 8447d011ad
3 changed files with 37 additions and 7 deletions

View File

@@ -7,6 +7,7 @@ package main
import (
"bufio"
"encoding/json"
"errors"
"flag"
"fmt"
"log"
@@ -17,6 +18,8 @@ import (
"github.com/ClusterCockpit/cc-backend/pkg/units"
)
const Version = 1
var ar FsArchive
func loadJobData(filename string) (*JobData, error) {
@@ -169,6 +172,10 @@ func main() {
flag.StringVar(&srcPath, "s", "./var/job-archive", "Specify the source job archive path. Default is ./var/job-archive")
flag.StringVar(&dstPath, "d", "./var/job-archive-new", "Specify the destination job archive path. Default is ./var/job-archive-new")
if _, err := os.Stat(fmt.Sprintf("%s/version.txt", srcPath)); !errors.Is(err, os.ErrNotExist) {
log.Fatal("Archive version exists!")
}
srcConfig := fmt.Sprintf("{\"path\": \"%s\"}", srcPath)
err := ar.Init(json.RawMessage(srcConfig))
if err != nil {
@@ -248,4 +255,6 @@ func main() {
}
}()
}
os.WriteFile(fmt.Sprintf("%s/version.txt", dstPath), []byte(fmt.Sprintf("%d", Version)), 0644)
}