extract localstorage path building
This commit is contained in:
parent
6a0351111e
commit
8517888577
20
lfs/lfs.go
20
lfs/lfs.go
@ -51,24 +51,12 @@ func ResetTempDir() error {
|
||||
return os.RemoveAll(TempDir)
|
||||
}
|
||||
|
||||
func localMediaDirNoCreate(sha string) string {
|
||||
return filepath.Join(LocalMediaDir, sha[0:2], sha[2:4])
|
||||
}
|
||||
func localMediaPathNoCreate(sha string) string {
|
||||
return filepath.Join(localMediaDirNoCreate(sha), sha)
|
||||
func LocalMediaPath(oid string) (string, error) {
|
||||
return LocalStorage.BuildObjectPath(oid)
|
||||
}
|
||||
|
||||
func LocalMediaPath(sha string) (string, error) {
|
||||
path := localMediaDirNoCreate(sha)
|
||||
if err := os.MkdirAll(path, localMediaDirPerms); err != nil {
|
||||
return "", fmt.Errorf("Error trying to create local media directory in '%s': %s", path, err)
|
||||
}
|
||||
|
||||
return filepath.Join(path, sha), nil
|
||||
}
|
||||
|
||||
func ObjectExistsOfSize(sha string, size int64) bool {
|
||||
path := localMediaPathNoCreate(sha)
|
||||
func ObjectExistsOfSize(oid string, size int64) bool {
|
||||
path := LocalStorage.ObjectPath(oid)
|
||||
return FileExistsOfSize(path, size)
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ func shouldDeleteTempObject(path string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
if FileExists(localMediaPathNoCreate(oid)) {
|
||||
if FileExists(LocalStorage.ObjectPath(oid)) {
|
||||
tracerx.Printf("Removing existing tmp object file: %s", path)
|
||||
return true
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package localstorage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
@ -9,7 +12,8 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
oidRE = regexp.MustCompile(`\A[[:alnum:]]{64}`)
|
||||
oidRE = regexp.MustCompile(`\A[[:alnum:]]{64}`)
|
||||
dirPerms os.FileMode = 0755
|
||||
)
|
||||
|
||||
// LocalStorage manages the locally stored LFS objects for a repository.
|
||||
@ -26,3 +30,20 @@ type Object struct {
|
||||
func New(dir string) *LocalStorage {
|
||||
return &LocalStorage{dir}
|
||||
}
|
||||
|
||||
func (s *LocalStorage) ObjectPath(oid string) string {
|
||||
return filepath.Join(localObjectDir(s, oid), oid)
|
||||
}
|
||||
|
||||
func (s *LocalStorage) BuildObjectPath(oid string) (string, error) {
|
||||
dir := localObjectDir(s, oid)
|
||||
if err := os.MkdirAll(dir, dirPerms); err != nil {
|
||||
return "", fmt.Errorf("Error trying to create local storage directory in %q: %s", dir, err)
|
||||
}
|
||||
|
||||
return filepath.Join(dir, oid), nil
|
||||
}
|
||||
|
||||
func localObjectDir(s *LocalStorage, oid string) string {
|
||||
return filepath.Join(s.Root, oid[0:2], oid[2:4])
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user