Merge pull request #1407 from JasonYangShadow/issue/1377

Return non-zero exit code on container copy failure
This commit is contained in:
Jonathon Anderson
2024-09-20 17:28:00 -06:00
committed by GitHub
2 changed files with 5 additions and 10 deletions

View File

@@ -40,6 +40,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Replace slice in templates with sprig substr. #1093
- Fix an invalid format issue for the GitHub nightly build action. #1258
- Return non-zero exit code on overlay build failure #1393
- Return non-zero exit code on container copy failure #1377
## v4.5.8, unreleased

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
}