fix a bug when replacing existing containers
Signed-off-by: jason yang <jasonyangshadow@gmail.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package imprt
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
@@ -19,6 +22,11 @@ Imported containers are used to create bootable VNFS images.`,
|
||||
Example: "wwctl container import docker://ghcr.io/hpcng/warewulf-rockylinux:8 rockylinux-8",
|
||||
RunE: CobraRunE,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
if SetForce && SetUpdate {
|
||||
wwlog.Warn("Both --force and --update flags are set, will ignore --update flag")
|
||||
}
|
||||
},
|
||||
}
|
||||
SetForce bool
|
||||
SetUpdate bool
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user