@@ -204,34 +204,33 @@ func DeleteModelFromSystem(basePath string, name string, additionalFiles []strin
204
204
log .Error ().Err (err ).Msgf ("failed to read gallery file %s" , configFile )
205
205
}
206
206
207
+ var filesToRemove []string
208
+
207
209
// Remove additional files
208
210
if galleryconfig != nil {
209
211
for _ , f := range galleryconfig .Files {
210
212
fullPath := filepath .Join (basePath , f .Filename )
211
- log .Debug ().Msgf ("Removing file %s" , fullPath )
212
- if e := os .Remove (fullPath ); e != nil {
213
- err = errors .Join (err , fmt .Errorf ("failed to remove file %s: %w" , f .Filename , e ))
214
- }
213
+ filesToRemove = append (filesToRemove , fullPath )
215
214
}
216
215
}
217
216
218
217
for _ , f := range additionalFiles {
219
218
fullPath := filepath .Join (filepath .Join (basePath , f ))
220
- log .Debug ().Msgf ("Removing additional file %s" , fullPath )
221
- if e := os .Remove (fullPath ); e != nil {
222
- err = errors .Join (err , fmt .Errorf ("failed to remove file %s: %w" , f , e ))
223
- }
219
+ filesToRemove = append (filesToRemove , fullPath )
224
220
}
225
221
226
- log .Debug ().Msgf ("Removing model config file %s" , configFile )
222
+ filesToRemove = append (filesToRemove , configFile )
223
+ filesToRemove = append (filesToRemove , galleryFile )
227
224
228
- // Delete the model config file
229
- if e := os .Remove (configFile ); e != nil {
230
- err = errors .Join (err , fmt .Errorf ("failed to remove file %s: %w" , configFile , e ))
231
- }
225
+ // skip duplicates
226
+ filesToRemove = utils .Unique (filesToRemove )
232
227
233
- // Delete gallery config file
234
- os .Remove (galleryFile )
228
+ // Removing files
229
+ for _ , f := range filesToRemove {
230
+ if e := os .Remove (f ); e != nil {
231
+ err = errors .Join (err , fmt .Errorf ("failed to remove file %s: %w" , f , e ))
232
+ }
233
+ }
235
234
236
235
return err
237
236
}
0 commit comments