Fix function delete with uid (#142)
If no uid is provided, all versions of function files and function metadata will be deleted. If a uid is provided, only that specific version is deleted, and the "latest" version of the function moves back to the previous one. Fixes #152
This commit is contained in:
@@ -108,7 +108,26 @@ func (fs *FunctionStore) Delete(m fission.Metadata) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return fs.ResourceStore.delete(typeName, m.Name)
|
||||
|
||||
bufs, err := fs.ResourceStore.getAll("file/" + m.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(bufs) == 0 {
|
||||
return fs.ResourceStore.delete(typeName, m.Name)
|
||||
}
|
||||
|
||||
fnew, err := fs.Get(&fission.Metadata{Name: m.Name})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
latestUid := bufs[len(bufs)-1] // function always tracks the latest version of code
|
||||
if latestUid == fnew.Uid {
|
||||
return nil
|
||||
}
|
||||
fnew.Uid = latestUid
|
||||
return fs.ResourceStore.update(fnew)
|
||||
}
|
||||
|
||||
func (fs *FunctionStore) List() ([]fission.Function, error) {
|
||||
|
||||
Reference in New Issue
Block a user