-
Notifications
You must be signed in to change notification settings - Fork 0
/
const.go
59 lines (51 loc) · 1.61 KB
/
const.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package shelf
import (
"fmt"
"os"
"path/filepath"
)
const (
SHELF_DIR = ".miner"
)
// ObjectDir returns the directory path to store all object type of records
// - type 1: marks
// - Record of each mine execution, in the format of
// TIMESTAMP
// PARENT MARK HASH
// ACCORDING MAP HASH 1
// ACCORDING MAP HASH 2
// ...
//
// - type 2: maps
// - A list of stuff records, each module will have it own stuff record, in the format of
// ACCORDING STUFF HASH 1 <SPACE> STUFF IDENTIFIER
// ACCORDING STUFF HASH 2 <SPACE> STUFF IDENTIFIER
// ...
//
// - type 3: stuff
// - Record of fetched stuff information,
// in json format of struct shared.MinerResource
func ObjectDir(group, prefixBytes string) (string, error) {
execPath, err := os.Executable()
if err != nil {
return "", fmt.Errorf("object dir: get executable: %w", err)
}
return filepath.Join(filepath.Dir(execPath), SHELF_DIR, group, "objects", prefixBytes), nil
}
// ObjectFile returns the file path to store the object record with the given file name
func ObjectFile(group, objectHash string) (string, error) {
dir, err := ObjectDir(group, objectHash[:2])
if err != nil {
return "", fmt.Errorf("object file: %w", err)
}
return filepath.Join(dir, objectHash[2:]), nil
}
// RefFile returns the file path to store the reference to the latest record mark
// with the given file name
func RefFile(group, name string) (string, error) {
execPath, err := os.Executable()
if err != nil {
return "", fmt.Errorf("ref dir: get executable: %w", err)
}
return filepath.Join(filepath.Dir(execPath), SHELF_DIR, group, "refs", name), nil
}