config/module: determine storage folder by path
This commit is contained in:
parent
f084d8d932
commit
2378160803
|
@ -39,8 +39,8 @@ func (s *FolderStorage) Dir(source string) (d string, e bool, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get implements Storage.Get
|
// Get implements Storage.Get
|
||||||
func (s *FolderStorage) Get(source string, update bool) error {
|
func (s *FolderStorage) Get(key string, source string, update bool) error {
|
||||||
dir := s.dir(source)
|
dir := s.dir(key)
|
||||||
if !update {
|
if !update {
|
||||||
if _, err := os.Stat(dir); err == nil {
|
if _, err := os.Stat(dir); err == nil {
|
||||||
// If the directory already exists, then we're done since
|
// If the directory already exists, then we're done since
|
||||||
|
|
|
@ -24,14 +24,16 @@ func TestFolderStorage(t *testing.T) {
|
||||||
t.Fatal("should not exist")
|
t.Fatal("should not exist")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
key := "foo"
|
||||||
|
|
||||||
// We can get it
|
// We can get it
|
||||||
err = s.Get(module, false)
|
err = s.Get(key, module, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now the module exists
|
// Now the module exists
|
||||||
dir, ok, err := s.Dir(module)
|
dir, ok, err := s.Dir(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,17 +9,17 @@ type Storage interface {
|
||||||
Dir(string) (string, bool, error)
|
Dir(string) (string, bool, error)
|
||||||
|
|
||||||
// Get will download and optionally update the given module.
|
// 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.
|
// Get the module with the level specified if we were told to.
|
||||||
if mode > GetModeNone {
|
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
|
return "", false, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the directory where the module is.
|
// Get the directory where the module is.
|
||||||
return s.Dir(src)
|
return s.Dir(key)
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,6 +153,11 @@ func (t *Tree) Load(s Storage, mode GetMode) error {
|
||||||
"module %s: duplicated. module names must be unique", m.Name)
|
"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
|
// Split out the subdir if we have one
|
||||||
source, subDir := getDirSubdir(m.Source)
|
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
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -190,9 +197,7 @@ func (t *Tree) Load(s Storage, mode GetMode) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the path of this child
|
// Set the path of this child
|
||||||
path := make([]string, len(t.path), len(t.path)+1)
|
children[m.Name].path = path
|
||||||
copy(path, t.path)
|
|
||||||
children[m.Name].path = append(path, m.Name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go through all the children and load them.
|
// Go through all the children and load them.
|
||||||
|
|
Loading…
Reference in New Issue