teach localstorage how to init its dirs

This commit is contained in:
risk danger olson 2015-11-24 13:18:26 -07:00
parent 8517888577
commit 50a398052b
3 changed files with 26 additions and 16 deletions

@ -92,27 +92,28 @@ func ResolveDirs() {
LocalWorkingDir, LocalGitDir, err = resolveGitDir() LocalWorkingDir, LocalGitDir, err = resolveGitDir()
if err == nil { if err == nil {
LocalGitStorageDir = resolveGitStorageDir(LocalGitDir) LocalGitStorageDir = resolveGitStorageDir(LocalGitDir)
LocalMediaDir = filepath.Join(LocalGitStorageDir, "lfs", "objects")
LocalStorage = localstorage.New(LocalMediaDir)
LocalLogDir = filepath.Join(LocalMediaDir, "logs")
TempDir = filepath.Join(LocalGitDir, "lfs", "tmp") // temp files per worktree TempDir = filepath.Join(LocalGitDir, "lfs", "tmp") // temp files per worktree
if err := os.MkdirAll(LocalMediaDir, localMediaDirPerms); err != nil {
panic(fmt.Errorf("Error trying to create objects directory in '%s': %s", LocalMediaDir, err)) ls, err := localstorage.New(
filepath.Join(LocalGitStorageDir, "lfs", "objects"),
filepath.Join(TempDir, "objects"),
)
if err != nil {
panic(fmt.Sprintf("Error trying to init LocalStorage: %s", err))
} }
LocalStorage = ls
LocalMediaDir = ls.RootDir
LocalObjectTempDir = ls.TempDir
LocalLogDir = filepath.Join(ls.RootDir, "logs")
if err := os.MkdirAll(LocalLogDir, localLogDirPerms); err != nil { if err := os.MkdirAll(LocalLogDir, localLogDirPerms); err != nil {
panic(fmt.Errorf("Error trying to create log directory in '%s': %s", LocalLogDir, err)) panic(fmt.Errorf("Error trying to create log directory in '%s': %s", LocalLogDir, err))
} }
LocalObjectTempDir = filepath.Join(TempDir, "objects")
if err := os.MkdirAll(LocalObjectTempDir, tempDirPerms); err != nil {
panic(fmt.Errorf("Error trying to create temp directory in '%s': %s", TempDir, err))
}
} }
} }
func init() { func init() {
tracerx.DefaultKey = "GIT" tracerx.DefaultKey = "GIT"
tracerx.Prefix = "trace git-lfs: " tracerx.Prefix = "trace git-lfs: "

@ -18,7 +18,8 @@ var (
// LocalStorage manages the locally stored LFS objects for a repository. // LocalStorage manages the locally stored LFS objects for a repository.
type LocalStorage struct { type LocalStorage struct {
Root string RootDir string
TempDir string
} }
// Object represents a locally stored LFS object. // Object represents a locally stored LFS object.
@ -27,8 +28,16 @@ type Object struct {
Size int64 Size int64
} }
func New(dir string) *LocalStorage { func New(storageDir, tempDir string) (*LocalStorage, error) {
return &LocalStorage{dir} if err := os.MkdirAll(storageDir, dirPerms); err != nil {
return nil, err
}
if err := os.MkdirAll(tempDir, dirPerms); err != nil {
return nil, err
}
return &LocalStorage{storageDir, tempDir}, nil
} }
func (s *LocalStorage) ObjectPath(oid string) string { func (s *LocalStorage) ObjectPath(oid string) string {
@ -45,5 +54,5 @@ func (s *LocalStorage) BuildObjectPath(oid string) (string, error) {
} }
func localObjectDir(s *LocalStorage, oid string) string { func localObjectDir(s *LocalStorage, oid string) string {
return filepath.Join(s.Root, oid[0:2], oid[2:4]) return filepath.Join(s.RootDir, oid[0:2], oid[2:4])
} }

@ -27,7 +27,7 @@ func (s *LocalStorage) ScanObjectsChan() <-chan Object {
go func() { go func() {
defer close(ch) defer close(ch)
scanObjects(s.Root, ch) scanObjects(s.RootDir, ch)
}() }()
return ch return ch