]> Cypherpunks.ru repositories - goredo.git/blobdiff - run.go
EDEADLK is regular non-warning error
[goredo.git] / run.go
diff --git a/run.go b/run.go
index 1bdbfe861c3b132f859ab0b5d0cf2413d98dba4f..0bc3155661143249eef83b592e69d0506c980090 100644 (file)
--- a/run.go
+++ b/run.go
@@ -1,6 +1,6 @@
 /*
 goredo -- djb's redo implementation on pure Go
-Copyright (C) 2020-2022 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2020-2023 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -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 {
@@ -244,9 +244,11 @@ func runScript(tgtOrig string, errs chan error, traced bool) error {
                        tracef(CLock, "LOCK_EX: %s", fdLock.Name())
                LockAgain:
                        if err := unix.FcntlFlock(fdLock.Fd(), unix.F_SETLKW, &flock); err != nil {
-                               log.Println(err, fdLock.Name())
-                               time.Sleep(10 * time.Millisecond)
-                               goto LockAgain
+                               if errors.Is(err, unix.EDEADLK) {
+                                       time.Sleep(10 * time.Millisecond)
+                                       goto LockAgain
+                               }
+                               log.Fatalln(err, fdLock.Name())
                        }
                        lockRelease()
                        tracef(CDebug, "waiting done: %s", tgtOrig)
@@ -281,6 +283,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 {