]> Cypherpunks.ru repositories - goredo.git/commitdiff
Less excess file remove calls
authorSergey Matveev <stargrave@stargrave.org>
Wed, 4 Oct 2023 12:12:32 +0000 (15:12 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 4 Oct 2023 12:12:51 +0000 (15:12 +0300)
run.go

diff --git a/run.go b/run.go
index bea836661746b36060927e9c604d5c61c02b1e94..903a063c283b53136eb5475ac15f5d05c9a6388e 100644 (file)
--- a/run.go
+++ b/run.go
@@ -304,13 +304,15 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error {
                return TgtError{tgt, ErrLine(err)}
        }
        fdDepOpened := true
-       fdDepPath := fdDep.Name()
+       fdDepExists := true
        cleanup := func() {
                lockRelease()
                if fdDepOpened {
                        fdDep.Close()
                }
-               os.Remove(fdDep.Name())
+               if fdDepExists {
+                       os.Remove(fdDep.Name())
+               }
        }
        if _, err = recfile.NewWriter(fdDep).WriteFields(
                recfile.Field{Name: "Build", Value: BuildUUID},
@@ -383,9 +385,8 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error {
                cleanup()
                return TgtError{tgt, ErrLine(err)}
        }
-       stdoutPath := fdStdout.Name()
        fdStdout.Close()
-       tmpPath := stdoutPath + ".3" // and for $3
+       tmpPath := fdStdout.Name() + ".3" // and for $3
        tmpPathRel := mustRel(cwd, tmpPath)
        args = append(
                args,
@@ -475,7 +476,7 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error {
                var exitErr *exec.ExitError
                started := time.Now()
                runErr.Started = &started
-               fdStdout, err = os.OpenFile(stdoutPath, os.O_RDWR, os.FileMode(0666))
+               fdStdout, err = os.OpenFile(fdStdout.Name(), os.O_RDWR, os.FileMode(0666))
                if err != nil {
                        if fdStderr != nil {
                                fdStderr.Close()
@@ -485,7 +486,7 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error {
                        return
                }
                cmd.Stdout = fdStdout
-               fdDep, err = os.OpenFile(fdDepPath, os.O_WRONLY|os.O_APPEND, os.FileMode(0666))
+               fdDep, err = os.OpenFile(fdDep.Name(), os.O_WRONLY|os.O_APPEND, os.FileMode(0666))
                if err != nil {
                        if fdStderr != nil {
                                fdStderr.Close()
@@ -582,7 +583,9 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error {
                                }
                        }
                        lockRelease()
-                       os.Remove(fdDep.Name())
+                       if fdDepExists {
+                               os.Remove(fdDep.Name())
+                       }
                        os.Remove(fdStdout.Name())
                        os.Remove(tmpPath)
                        if FdStatus != nil {
@@ -788,6 +791,7 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error {
                if err != nil {
                        goto Finish
                }
+               fdDepExists = false
                if !NoSync {
                        err = ErrLine(syncDir(redoDir))
                        if err != nil {