diff --git a/internal/resolution/pm/nuget/cmd_factory.go b/internal/resolution/pm/nuget/cmd_factory.go index 96f67d3f..05a627ad 100644 --- a/internal/resolution/pm/nuget/cmd_factory.go +++ b/internal/resolution/pm/nuget/cmd_factory.go @@ -80,10 +80,10 @@ func (cmdf *CmdFactory) MakeInstallCmd(command string, file string) (*exec.Cmd, fileLockName := "packages.lock.json" if packageConfig.MatchString(file) { file, err = cmdf.convertPackagesConfigToCsproj(file, command) + cmdf.tempoCsproj = file if err != nil { return nil, err } - cmdf.tempoCsproj = file fileLockName = ".packages.config.nuget.debricked.lock" } @@ -152,7 +152,7 @@ func (cmdf *CmdFactory) createCsprojContentWithTemplate(targetFrameworksStr stri "Packages": packages, }) if err != nil { - return "", err + return tpl.String(), err } return tpl.String(), nil diff --git a/internal/resolution/pm/nuget/job.go b/internal/resolution/pm/nuget/job.go index 489cd828..27cdb372 100644 --- a/internal/resolution/pm/nuget/job.go +++ b/internal/resolution/pm/nuget/job.go @@ -39,6 +39,7 @@ func (j *Job) Run() { j.SendStatus("installing dependencies") output, err := j.runInstallCmd() + defer j.cleanupTempoCsproj() if err != nil { j.Errors().Critical(fmt.Errorf("%s\n%s", output, err)) @@ -63,15 +64,17 @@ func (j *Job) runInstallCmd() ([]byte, error) { return installCmdOutput, j.GetExitError(err) } + return installCmdOutput, nil +} + +func (j *Job) cleanupTempoCsproj() { // Cleanup of the temporary .csproj file (packages.config) tempFile := j.cmdFactory.GetTempoCsproj() if tempFile != "" { // remove the packages.config.csproj file - err = osRemoveAll(tempFile) + err := osRemoveAll(tempFile) if err != nil { - return installCmdOutput, j.GetExitError(err) + j.Errors().Critical(fmt.Errorf("failed to remove temporary .csproj file: %s", err)) } } - - return installCmdOutput, nil } diff --git a/internal/resolution/pm/nuget/job_test.go b/internal/resolution/pm/nuget/job_test.go index 21e8c693..d2926b40 100644 --- a/internal/resolution/pm/nuget/job_test.go +++ b/internal/resolution/pm/nuget/job_test.go @@ -46,7 +46,7 @@ func TestRunInstallPackagesConfigRemoveAllErr(t *testing.T) { oldOsRemoveAll := osRemoveAll cmdErr := errors.New("os-remove-all-error") - cmdErrGt := errors.New("\n\nos-remove-all-error") + cmdErrGt := errors.New("failed to remove temporary .csproj file: os-remove-all-error") osRemoveAll = func(path string) error { return cmdErr } @@ -61,8 +61,8 @@ func TestRunInstallPackagesConfigRemoveAllErr(t *testing.T) { go jobTestdata.WaitStatus(j) j.Run() - - assert.Equal(t, j.Errors().GetAll()[0], cmdErrGt) + errors := j.Errors().GetAll() + assert.Equal(t, errors[0], cmdErrGt) }