-
Notifications
You must be signed in to change notification settings - Fork 85
/
version.go
43 lines (37 loc) · 1012 Bytes
/
version.go
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
package repo
import (
"encoding/json"
"os"
"path/filepath"
"github.com/bacalhau-project/bacalhau/pkg/storage/util"
)
const (
// RepoVersion2 is the current repo versioning.
RepoVersion2 = 2
// RepoVersion1 is the current repo versioning for v1-v1.1.4
RepoVersion1 = 1
// RepoVersionFile is the name of the repo file containing the repo version.
RepoVersionFile = "repo.version"
)
type RepoVersion struct {
Version int
}
func (fsr *FsRepo) writeVersion(version int) error {
repoVersion := RepoVersion{Version: version}
versionJSON, err := json.Marshal(repoVersion)
if err != nil {
return err
}
return os.WriteFile(filepath.Join(fsr.path, RepoVersionFile), versionJSON, util.OS_USER_RW)
}
func (fsr *FsRepo) readVersion() (int, error) {
versionBytes, err := os.ReadFile(filepath.Join(fsr.path, RepoVersionFile))
if err != nil {
return -1, err
}
var version RepoVersion
if err := json.Unmarshal(versionBytes, &version); err != nil {
return -1, err
}
return version.Version, nil
}