Return non-zero exit code on container copy failure

Signed-off-by: xu yang <xyang@ciq.com>
This commit is contained in:
xu yang
2024-09-19 23:58:32 +00:00
parent cd39a766d8
commit aa35ce93e5
2 changed files with 5 additions and 10 deletions

View File

@@ -21,28 +21,22 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
}
if !container.DoesSourceExist(cdp.ContainerSource) {
wwlog.Error("Container's source doesn't exists: %s", cdp.ContainerSource)
return
return fmt.Errorf("container's source doesn't exists: %s", cdp.ContainerSource)
}
if !container.ValidName(cdp.ContainerDestination) {
wwlog.Error("Container name contains illegal characters : %s", cdp.ContainerDestination)
return
return fmt.Errorf("container name contains illegal characters : %s", cdp.ContainerDestination)
}
if container.DoesSourceExist(cdp.ContainerDestination) {
wwlog.Error("An other container with name: %s already exists in sources.", cdp.ContainerDestination)
return
return fmt.Errorf("an other container with name: %s already exists in sources", cdp.ContainerDestination)
}
err = container.Duplicate(cdp.ContainerSource, cdp.ContainerDestination)
if err != nil {
err = fmt.Errorf("could not duplicate image: %s", err.Error())
wwlog.Error(err.Error())
return
return fmt.Errorf("could not duplicate image: %s", err.Error())
}
wwlog.Info("Container %s successfully duplicated as %s", cdp.ContainerSource, cdp.ContainerDestination)
return
}