Skip to content

Commit

Permalink
Reload local blueprints from storage
Browse files Browse the repository at this point in the history
  • Loading branch information
td5r committed Nov 15, 2022
1 parent 3c2c130 commit 394bf0a
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions pkg/storage/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func cleanPath(p string) string {

func NewWritableFileSystem(root string) *WritableFileSystem {
p := cleanPath(root)
return &WritableFileSystem{FileSystem: FileSystem{p, make(map[uuid.UUID]*core.Blueprint), nil}}
return &WritableFileSystem{FileSystem: FileSystem{p, nil, nil}}
}

func NewReadOnlyFileSystem(root string) *FileSystem {
Expand Down Expand Up @@ -123,7 +123,7 @@ func (fs *WritableFileSystem) Save(blueprint core.Blueprint) (uuid.UUID, error)
}

delete(fs.cache, opId)
fs.uuids = nil
fs.uuids = append(fs.uuids, opId)

blueprintYaml, err := yaml.Marshal(&blueprint)

Expand All @@ -139,6 +139,23 @@ func (fs *WritableFileSystem) Save(blueprint core.Blueprint) (uuid.UUID, error)
return opId, nil
}

func (fs *WritableFileSystem) List() ([]uuid.UUID, error) {
// force to reload writable/local blueprints
fs.clearCache()
return fs.FileSystem.List()
}

func (fs *WritableFileSystem) Load(opId uuid.UUID) (*core.Blueprint, error) {
// force to reload writable/local blueprints
delete(fs.cache, opId)
return fs.FileSystem.Load(opId)
}

func (fs *WritableFileSystem) clearCache() {
fs.cache = make(map[uuid.UUID]*core.Blueprint)
fs.uuids = nil
}

func (fs *FileSystem) hasSupportedSuffix(filePath string) bool {
return utils.IsJSON(filePath) || utils.IsYAML(filePath)
}
Expand Down

0 comments on commit 394bf0a

Please sign in to comment.