@@ -152,12 +152,19 @@ func (a *apiProvider) ManifestAdd(ctx context.Context, p *ManifestAddParams) (*M
152152 },
153153 }, nil
154154 }
155+ if p .Deviceid == "" {
156+ return & ManifestAddResponse {
157+ Stat : & Status {
158+ Code : bte .InvalidParameter ,
159+ Msg : "Device ID may not be empty" ,
160+ },
161+ }, nil
162+ }
155163 metadata := make (map [string ]string )
156164 for _ , kv := range p .Metadata {
157165 metadata [kv .Key ] = kv .Value
158166 }
159- dev := & manifest.ManifestDevice {Descriptor : p .Deviceid , Metadata : metadata , Streams : make (map [string ]* manifest.ManifestDeviceStream )}
160- success , err := manifest .UpsertManifestDeviceAtomically (ctx , a .ec , dev )
167+ md , err := manifest .RetrieveManifestDevice (ctx , a .ec , p .Deviceid )
161168 if err != nil {
162169 return & ManifestAddResponse {
163170 Stat : & Status {
@@ -166,15 +173,25 @@ func (a *apiProvider) ManifestAdd(ctx context.Context, p *ManifestAddParams) (*M
166173 },
167174 }, nil
168175 }
169- if ! success {
176+ if md != nil {
170177 return & ManifestAddResponse {
171178 Stat : & Status {
172179 Code : bte .ManifestDeviceDuplicated ,
173180 Msg : err .Error (),
174181 },
175182 }, nil
176183 }
177- return & ManifestAddResponse {}, nil
184+ dev := & manifest.ManifestDevice {Descriptor : p .Deviceid , Metadata : metadata , Streams : make (map [string ]* manifest.ManifestDeviceStream )}
185+ err = manifest .UpsertManifestDevice (ctx , a .ec , dev )
186+ if err != nil {
187+ return & ManifestAddResponse {
188+ Stat : & Status {
189+ Code : bte .ManifestError ,
190+ Msg : err .Error (),
191+ },
192+ }, nil
193+ }
194+ return & ManifestAddResponse {Deviceid : p .Deviceid }, nil
178195}
179196
180197func (a * apiProvider ) ManifestDel (ctx context.Context , p * ManifestDelParams ) (* ManifestDelResponse , error ) {
@@ -187,7 +204,7 @@ func (a *apiProvider) ManifestDel(ctx context.Context, p *ManifestDelParams) (*M
187204 },
188205 }, nil
189206 }
190- err := manifest .DeleteManifestDevice (ctx , a .ec , p .Deviceid )
207+ md , err := manifest .RetrieveManifestDevice (ctx , a .ec , p .Deviceid )
191208 if err != nil {
192209 return & ManifestDelResponse {
193210 Stat : & Status {
@@ -196,7 +213,24 @@ func (a *apiProvider) ManifestDel(ctx context.Context, p *ManifestDelParams) (*M
196213 },
197214 }, nil
198215 }
199- return & ManifestDelResponse {}, nil
216+ if md == nil {
217+ return & ManifestDelResponse {
218+ Stat : & Status {
219+ Code : bte .ManifestDeviceDoesntExist ,
220+ Msg : "No device exists with that deviceid" ,
221+ },
222+ }, nil
223+ }
224+ err = manifest .DeleteManifestDevice (ctx , a .ec , p .Deviceid )
225+ if err != nil {
226+ return & ManifestDelResponse {
227+ Stat : & Status {
228+ Code : bte .ManifestError ,
229+ Msg : err .Error (),
230+ },
231+ }, nil
232+ }
233+ return & ManifestDelResponse {Deviceid : p .Deviceid }, nil
200234}
201235
202236func (a * apiProvider ) ManifestDelPrefix (ctx context.Context , p * ManifestDelPrefixParams ) (* ManifestDelPrefixResponse , error ) {
@@ -218,6 +252,14 @@ func (a *apiProvider) ManifestDelPrefix(ctx context.Context, p *ManifestDelPrefi
218252 },
219253 }, nil
220254 }
255+ if n == 0 {
256+ return & ManifestDelPrefixResponse {
257+ Stat : & Status {
258+ Code : bte .ManifestDeviceDoesntExist ,
259+ Msg : "No devices exist with this device id pattern" ,
260+ },
261+ }, nil
262+ }
221263 return & ManifestDelPrefixResponse {
222264 Numdeleted : uint32 (n ),
223265 }, nil
0 commit comments