Skip to content

Commit

Permalink
Always return valid Config and check for directory. Fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepeterson committed Jul 12, 2022
1 parent 3170604 commit a23cfee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewDefaultConfigRetreiver(next ConfigRetriever) *DefaultConfigRetreiver {
// it. If the config is empty a default config is returned.
func (c *DefaultConfigRetreiver) RetrieveConfig(ctx context.Context, name string) (*Config, error) {
config, err := c.next.RetrieveConfig(ctx, name)
if err == nil && (config == nil || config.BaseURL == "") {
if config == nil || config.BaseURL == "" {
config = &Config{BaseURL: DefaultBaseURL}
}
return config, err
Expand Down
14 changes: 12 additions & 2 deletions storage/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,18 @@ type FileStorage struct {
// New creates a new FileStorage backend.
func New(path string) (*FileStorage, error) {
err := os.Mkdir(path, 0755)
if err != nil && !errors.Is(err, os.ErrExist) {
return nil, err
if err != nil {
if errors.Is(err, os.ErrExist) {
f, err := os.Stat(path)
if err != nil {
return nil, err
}
if !f.IsDir() {
return nil, errors.New("path is not a directory")
}
} else {
return nil, err
}
}
return &FileStorage{path: path}, nil
}
Expand Down

0 comments on commit a23cfee

Please sign in to comment.