-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanifest.go
42 lines (34 loc) · 1023 Bytes
/
manifest.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
package main
import (
"os"
"encoding/json"
"path/filepath"
"fmt"
)
type linkMetadata struct {
Project string `json:"project"`
Asset string `json:"asset"`
Version string `json:"version"`
Path string `json:"path"`
Ancestor *linkMetadata `json:"ancestor,omitempty"`
}
type manifestEntry struct {
Size int64 `json:"size"`
Md5sum string `json:"md5sum"`
Link *linkMetadata `json:"link,omitempty"`
}
const manifestFileName = "..manifest"
const linksFileName = "..links"
func readManifest(path string) (map[string]manifestEntry, error) {
manifest_path := filepath.Join(path, manifestFileName)
manifest_raw, err := os.ReadFile(manifest_path)
if err != nil {
return nil, fmt.Errorf("cannot read '" + manifest_path + "'; %w", err)
}
var info map[string]manifestEntry
err = json.Unmarshal(manifest_raw, &info)
if err != nil {
return nil, fmt.Errorf("cannot parse JSON in '" + manifest_path + "'; %w", err)
}
return info, nil
}