]> Cypherpunks.ru repositories - goredo.git/blobdiff - run.go
Prevent possible race when building target twice
[goredo.git] / run.go
diff --git a/run.go b/run.go
index 2e5dbf5f7ebd5fc8e9c4cfc6e8194333b0456fd9..7ee463714ed229448325014944d91c9fab266d18 100644 (file)
--- a/run.go
+++ b/run.go
@@ -184,7 +184,7 @@ func syncDir(dir string) error {
        return err
 }
 
-func runScript(tgtOrig string, errs chan error, traced bool) error {
+func runScript(tgtOrig string, errs chan error, forced, traced bool) error {
        cwd, tgt := cwdAndTgt(tgtOrig)
        redoDir := path.Join(cwd, RedoDir)
        if err := mkdirs(redoDir); err != nil {
@@ -281,6 +281,19 @@ func runScript(tgtOrig string, errs chan error, traced bool) error {
                return nil
        }
 
+       // 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
+                       }
+               }
+       }
+
        // Check if target is not modified externally
        modified, inodePrev, hshPrev, err := isModified(cwd, redoDir, tgt)
        if err != nil {