11 // FolderStorage is an implementation of the Storage interface that manages
12 // modules on the disk.
13 type FolderStorage struct {
14 // StorageDir is the directory where the modules will be stored.
18 // Dir implements Storage.Dir
19 func (s *FolderStorage) Dir(key string) (d string, e bool, err error) {
27 if os.IsNotExist(err) {
28 // Directory doesn't exist
41 // Get implements Storage.Get
42 func (s *FolderStorage) Get(key string, source string, update bool) error {
45 if _, err := os.Stat(dir); err == nil {
46 // If the directory already exists, then we're done since
47 // we're not updating.
49 } else if !os.IsNotExist(err) {
50 // If the error we got wasn't a file-not-exist error, then
51 // something went wrong and we should report it.
52 return fmt.Errorf("Error reading module directory: %s", err)
56 // Get the source. This always forces an update.
57 return Get(dir, source)
60 // dir returns the directory name internally that we'll use to map to
62 func (s *FolderStorage) dir(key string) string {
63 sum := md5.Sum([]byte(key))
64 return filepath.Join(s.StorageDir, hex.EncodeToString(sum[:]))