diff --git a/config/module/folder_storage.go b/config/module/folder_storage.go index dfb79748a..4c47ba294 100644 --- a/config/module/folder_storage.go +++ b/config/module/folder_storage.go @@ -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 diff --git a/config/module/folder_storage_test.go b/config/module/folder_storage_test.go index 4ffaac2bb..7fda6b21a 100644 --- a/config/module/folder_storage_test.go +++ b/config/module/folder_storage_test.go @@ -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) } diff --git a/config/module/storage.go b/config/module/storage.go index dcb0cc57c..9c752f630 100644 --- a/config/module/storage.go +++ b/config/module/storage.go @@ -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) } diff --git a/config/module/tree.go b/config/module/tree.go index 08f73b0e4..d7b3ac966 100644 --- a/config/module/tree.go +++ b/config/module/tree.go @@ -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.