/
store.go
43 lines (34 loc) · 1.02 KB
/
store.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 blobstore
import (
"fmt"
"os"
"path/filepath"
"sync"
)
type localStore struct {
sync.Mutex
root string
}
// NewLocalStore creates a new local blob store in the given root directory.
func NewLocalStore(root string) (Store, error) {
return newLocalStore(root)
}
func (ls *localStore) blobDirname(digest string) string {
return filepath.Join(ls.root, "blobs", digest)
}
func (ls *localStore) blobFilename(digest string) string {
return filepath.Join(ls.blobDirname(digest), "blob")
}
func (ls *localStore) blobInfoFilename(digest string) string {
return filepath.Join(ls.blobDirname(digest), "info.json")
}
// newLocalStore is the unexported version of NewLocalStore which returns
// the unexported type.
func newLocalStore(root string) (*localStore, error) {
ls := &localStore{root: root}
blobsDirname := ls.blobDirname("")
if err := os.MkdirAll(blobsDirname, os.FileMode(0755)); err != nil {
return nil, fmt.Errorf("unable to create local blob store directory %q: %s", blobsDirname, err)
}
return ls, nil
}