config/module: determine storage folder by path

This commit is contained in:
Mitchell Hashimoto 2015-04-07 16:44:24 -07:00
parent f084d8d932
commit 2378160803
4 changed files with 19 additions and 12 deletions

View File

@ -39,8 +39,8 @@ func (s *FolderStorage) Dir(source string) (d string, e bool, err error) {
}
// Get implements Storage.Get
func (s *FolderStorage) Get(source string, update bool) error {
dir := s.dir(source)
func (s *FolderStorage) Get(key string, source string, update bool) error {
dir := s.dir(key)
if !update {
if _, err := os.Stat(dir); err == nil {
// If the directory already exists, then we're done since

View File

@ -24,14 +24,16 @@ func TestFolderStorage(t *testing.T) {
t.Fatal("should not exist")
}
key := "foo"
// We can get it
err = s.Get(module, false)
err = s.Get(key, module, false)
if err != nil {
t.Fatalf("err: %s", err)
}
// Now the module exists
dir, ok, err := s.Dir(module)
dir, ok, err := s.Dir(key)
if err != nil {
t.Fatalf("err: %s", err)
}

View File

@ -9,17 +9,17 @@ type Storage interface {
Dir(string) (string, bool, error)
// Get will download and optionally update the given module.
Get(string, bool) error
Get(string, string, bool) error
}
func getStorage(s Storage, src string, mode GetMode) (string, bool, error) {
func getStorage(s Storage, key string, src string, mode GetMode) (string, bool, error) {
// Get the module with the level specified if we were told to.
if mode > GetModeNone {
if err := s.Get(src, mode == GetModeUpdate); err != nil {
if err := s.Get(key, src, mode == GetModeUpdate); err != nil {
return "", false, err
}
}
// Get the directory where the module is.
return s.Dir(src)
return s.Dir(key)
}

View File

@ -153,6 +153,11 @@ func (t *Tree) Load(s Storage, mode GetMode) error {
"module %s: duplicated. module names must be unique", m.Name)
}
// Determine the path to this child
path := make([]string, len(t.path), len(t.path)+1)
copy(path, t.path)
path = append(path, m.Name)
// Split out the subdir if we have one
source, subDir := getDirSubdir(m.Source)
@ -168,7 +173,9 @@ func (t *Tree) Load(s Storage, mode GetMode) error {
}
// Get the directory where this module is so we can load it
dir, ok, err := getStorage(s, source, mode)
key := strings.Join(path, ".")
key = "root." + key
dir, ok, err := getStorage(s, key, source, mode)
if err != nil {
return err
}
@ -190,9 +197,7 @@ func (t *Tree) Load(s Storage, mode GetMode) error {
}
// Set the path of this child
path := make([]string, len(t.path), len(t.path)+1)
copy(path, t.path)
children[m.Name].path = append(path, m.Name)
children[m.Name].path = path
}
// Go through all the children and load them.