mirror of
https://github.com/project-zot/zot.git
synced 2026-06-18 05:28:07 +08:00
e2aa088e0d
initial working prototype for sync fix: pre-load chunk readers on manifest fetch feat: make chunkSize configurable fix minimal build fix: linter errors Signed-off-by: Vishwas Rajashekar <dev@vrajashkr.com>
50 lines
1013 B
Go
50 lines
1013 B
Go
package sync
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
|
|
godigest "github.com/opencontainers/go-digest"
|
|
)
|
|
|
|
type StreamTempStore interface {
|
|
BlobPath(digest godigest.Digest) string
|
|
}
|
|
|
|
type LocalTempStore struct {
|
|
rootPath string
|
|
}
|
|
|
|
func NewLocalTempStore(rootDir string) *LocalTempStore {
|
|
_, err := os.Stat(rootDir)
|
|
if err != nil {
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
err := os.MkdirAll(rootDir, 0o755)
|
|
if err != nil {
|
|
fmt.Println("failed to create root dir " + err.Error())
|
|
}
|
|
} else {
|
|
fmt.Println("failed to stat root dir " + err.Error())
|
|
}
|
|
}
|
|
|
|
return &LocalTempStore{
|
|
rootPath: rootDir,
|
|
}
|
|
}
|
|
|
|
func (lts *LocalTempStore) BlobPath(digest godigest.Digest) string {
|
|
parentDir := path.Join(lts.rootPath, digest.Algorithm().String())
|
|
_, err := os.Stat(parentDir)
|
|
if err != nil && errors.Is(err, os.ErrNotExist) {
|
|
err := os.MkdirAll(parentDir, 0o755)
|
|
if err != nil {
|
|
fmt.Println("failed to create directory " + err.Error())
|
|
}
|
|
}
|
|
|
|
return path.Join(parentDir, digest.Encoded())
|
|
}
|