fix a bug when replacing existing containers

Signed-off-by: jason yang <jasonyangshadow@gmail.com>
This commit is contained in:
jason yang
2023-12-12 17:06:28 -07:00
parent 9c698d7a13
commit 231987ecfc
3 changed files with 23 additions and 11 deletions

View File

@@ -175,21 +175,23 @@ func ContainerImport(cip *wwapiv1.ContainerImportParameter) (containerName strin
containerName = cip.Name
fullPath := container.SourceDir(cip.Name)
// container already exists and should be removed first
if util.IsDir(fullPath) && cip.Force {
wwlog.Info("Overwriting existing VNFS")
err = os.RemoveAll(fullPath)
if err != nil {
wwlog.ErrorExc(err, "")
return
}
}
if util.IsDir(fullPath) {
if cip.Force {
wwlog.Info("Overwriting existing VNFS")
err = os.RemoveAll(fullPath)
if err != nil {
wwlog.ErrorExc(err, "")
return
}
} else if cip.Update {
wwlog.Info("Updating existing VNFS")
} else {
if !cip.Update {
err = fmt.Errorf("VNFS Name exists, specify --force, --update, or choose a different name: %s", cip.Name)
wwlog.Error(err.Error())
return
}
wwlog.Info("Updating existing VNFS")
} else if strings.HasPrefix(cip.Source, "docker://") || strings.HasPrefix(cip.Source, "docker-daemon://") ||
strings.HasPrefix(cip.Source, "file://") || util.IsFile(cip.Source) {
var sCtx *types.SystemContext