Skip to content

Commit

Permalink
api: rest: Write to database first
Browse files Browse the repository at this point in the history
  • Loading branch information
ish-hcc committed Oct 27, 2024
1 parent 5795d85 commit 7207d47
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/api/rest/controller/software.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,17 @@ func RegisterSoftware(c echo.Context) error {
NeededPackages: neededPackages,
}

destDir := filepath.Join(config.CMGrasshopperConfig.CMGrasshopper.Ansible.PlaybookRootPath, sw.ID)
err = writePlaybookFiles(softwareRegisterReq.Name, destDir, softwareRegisterReq.NeededPackages)
dbSW, err := dao.SoftwareCreate(&sw)
if err != nil {
_ = fileutil.DeleteDir(destDir)

return common.ReturnErrorMsg(c, err.Error())
}

dbSW, err := dao.SoftwareCreate(&sw)
destDir := filepath.Join(config.CMGrasshopperConfig.CMGrasshopper.Ansible.PlaybookRootPath, sw.ID)
err = writePlaybookFiles(softwareRegisterReq.Name, destDir, softwareRegisterReq.NeededPackages)
if err != nil {
_ = fileutil.DeleteDir(destDir)
_ = dao.SoftwareDelete(&sw)

return common.ReturnErrorMsg(c, err.Error())
}

Expand Down

0 comments on commit 7207d47

Please sign in to comment.