mirror of
https://github.com/mudler/LocalAI.git
synced 2025-04-27 06:20:12 +00:00
fix(gallery): do not attempt to delete duplicate files (#3031)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
610e1c00c6
commit
2a839e1432
@ -204,35 +204,34 @@ func DeleteModelFromSystem(basePath string, name string, additionalFiles []strin
|
|||||||
log.Error().Err(err).Msgf("failed to read gallery file %s", configFile)
|
log.Error().Err(err).Msgf("failed to read gallery file %s", configFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var filesToRemove []string
|
||||||
|
|
||||||
// Remove additional files
|
// Remove additional files
|
||||||
if galleryconfig != nil {
|
if galleryconfig != nil {
|
||||||
for _, f := range galleryconfig.Files {
|
for _, f := range galleryconfig.Files {
|
||||||
fullPath := filepath.Join(basePath, f.Filename)
|
fullPath := filepath.Join(basePath, f.Filename)
|
||||||
log.Debug().Msgf("Removing file %s", fullPath)
|
filesToRemove = append(filesToRemove, fullPath)
|
||||||
if e := os.Remove(fullPath); e != nil {
|
|
||||||
err = errors.Join(err, fmt.Errorf("failed to remove file %s: %w", f.Filename, e))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range additionalFiles {
|
for _, f := range additionalFiles {
|
||||||
fullPath := filepath.Join(filepath.Join(basePath, f))
|
fullPath := filepath.Join(filepath.Join(basePath, f))
|
||||||
log.Debug().Msgf("Removing additional file %s", fullPath)
|
filesToRemove = append(filesToRemove, fullPath)
|
||||||
if e := os.Remove(fullPath); e != nil {
|
}
|
||||||
|
|
||||||
|
filesToRemove = append(filesToRemove, configFile)
|
||||||
|
filesToRemove = append(filesToRemove, galleryFile)
|
||||||
|
|
||||||
|
// skip duplicates
|
||||||
|
filesToRemove = utils.Unique(filesToRemove)
|
||||||
|
|
||||||
|
// Removing files
|
||||||
|
for _, f := range filesToRemove {
|
||||||
|
if e := os.Remove(f); e != nil {
|
||||||
err = errors.Join(err, fmt.Errorf("failed to remove file %s: %w", f, e))
|
err = errors.Join(err, fmt.Errorf("failed to remove file %s: %w", f, e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug().Msgf("Removing model config file %s", configFile)
|
|
||||||
|
|
||||||
// Delete the model config file
|
|
||||||
if e := os.Remove(configFile); e != nil {
|
|
||||||
err = errors.Join(err, fmt.Errorf("failed to remove file %s: %w", configFile, e))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete gallery config file
|
|
||||||
os.Remove(galleryFile)
|
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,3 +18,15 @@ func RandString(n int) string {
|
|||||||
}
|
}
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Unique(arr []string) []string {
|
||||||
|
unique := make(map[string]bool)
|
||||||
|
var result []string
|
||||||
|
for _, item := range arr {
|
||||||
|
if _, ok := unique[item]; !ok {
|
||||||
|
unique[item] = true
|
||||||
|
result = append(result, item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user