]> Cypherpunks.ru repositories - goredo.git/blobdiff - run.go
Optimise redo-sources
[goredo.git] / run.go
diff --git a/run.go b/run.go
index 90eb7e6ec1669c996efb04dd7a2c837b46cb2203..6bd7029752d8fac0d13c6bb1a26e95c67c208953 100644 (file)
--- a/run.go
+++ b/run.go
@@ -31,7 +31,6 @@ import (
        "os"
        "os/exec"
        "path"
-       "path/filepath"
        "strconv"
        "strings"
        "sync"
@@ -257,20 +256,14 @@ func runScript(tgtOrig string, errs chan error, forced, traced bool) error {
                                        log.Fatal(err)
                                }
                        }
-                       var depInfo *DepInfo
-                       fdDep, err := os.Open(path.Join(redoDir, tgt+DepSuffix))
+                       build, err := depReadBuild(path.Join(redoDir, tgt+DepSuffix))
                        if err != nil {
-                               if os.IsNotExist(err) {
+                               if errors.Is(err, fs.ErrNotExist) {
                                        err = errors.New("was not built: no .rec")
                                }
                                goto Finish
                        }
-                       defer fdDep.Close()
-                       depInfo, err = depRead(fdDep)
-                       if err != nil {
-                               goto Finish
-                       }
-                       if depInfo.build != BuildUUID {
+                       if build != BuildUUID {
                                err = errors.New("was not built: build differs")
                        }
                Finish:
@@ -285,14 +278,10 @@ func runScript(tgtOrig string, errs chan error, forced, traced bool) error {
 
        // Check if it was already built in parallel
        if !forced {
-               if fdDep, err := os.Open(path.Join(redoDir, tgt+DepSuffix)); err == nil {
-                       depInfo, err := depRead(fdDep)
-                       fdDep.Close()
-                       if err == nil && depInfo.build == BuildUUID {
-                               lockRelease()
-                               errs <- nil
-                               return nil
-                       }
+               if build, err := depReadBuild(path.Join(redoDir, tgt+DepSuffix)); err == nil && build == BuildUUID {
+                       lockRelease()
+                       errs <- nil
+                       return nil
                }
        }
 
@@ -395,10 +384,7 @@ func runScript(tgtOrig string, errs chan error, forced, traced bool) error {
        stdoutPath := fdStdout.Name()
        fdStdout.Close()
        tmpPath := stdoutPath + ".3" // and for $3
-       tmpPathRel, err := filepath.Rel(cwd, tmpPath)
-       if err != nil {
-               panic(err)
-       }
+       tmpPathRel := mustRel(cwd, tmpPath)
        args = append(
                args,
                path.Join(dirPrefix, tgt),
@@ -714,7 +700,7 @@ func runScript(tgtOrig string, errs chan error, forced, traced bool) error {
                                return
                        }
                        tmpExists = true
-               } else if !os.IsNotExist(err) {
+               } else if !errors.Is(err, fs.ErrNotExist) {
                        runErr.Err = ErrLine(err)
                        errs <- runErr
                        return