X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=run.go;h=2e5dbf5f7ebd5fc8e9c4cfc6e8194333b0456fd9;hb=b4eefdd675c9aef9ff8bd1089d031ee05733195b;hp=8cb6017d7d5ee3547a9bb0fd59d8a180135fa0c8;hpb=a534f625d40042d3269b5c428a6bead8c503a40d;p=goredo.git diff --git a/run.go b/run.go index 8cb6017..2e5dbf5 100644 --- a/run.go +++ b/run.go @@ -1,6 +1,6 @@ /* goredo -- djb's redo implementation on pure Go -Copyright (C) 2020-2022 Sergey Matveev +Copyright (C) 2020-2023 Sergey Matveev 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 @@ -126,7 +126,7 @@ func (e RunError) Error() string { } func mkdirs(pth string) error { - if _, err := os.Stat(pth); err == nil { + if FileExists(pth) { return nil } return os.MkdirAll(pth, os.FileMode(0777)) @@ -156,18 +156,13 @@ func isModified(cwd, redoDir, tgt string) (bool, *Inode, string, error) { if m["Type"] != DepTypeIfchange || m["Target"] != tgt { continue } - fd, err := os.Open(path.Join(cwd, tgt)) + ourInode, err = inodeFromFileByPath(path.Join(cwd, tgt)) if err != nil { if os.IsNotExist(err) { return false, nil, "", nil } return false, nil, "", err } - ourInode, err = inodeFromFile(fd) - fd.Close() - if err != nil { - return false, nil, "", err - } theirInode, err := inodeFromRec(m) if err != nil { return false, nil, "", err @@ -222,7 +217,7 @@ func runScript(tgtOrig string, errs chan error, traced bool) error { tracef(CLock, "LOCK_UN: %s", fdLock.Name()) flock.Type = unix.F_UNLCK if err := unix.FcntlFlock(fdLock.Fd(), unix.F_SETLK, &flock); err != nil { - log.Fatalln(err) + log.Fatalln(err, fdLock.Name()) } fdLock.Close() } @@ -236,7 +231,7 @@ func runScript(tgtOrig string, errs chan error, traced bool) error { } Jobs.Add(1) if err = unix.FcntlFlock(fdLock.Fd(), unix.F_GETLK, &flock); err != nil { - log.Fatalln(err) + log.Fatalln(err, fdLock.Name()) } tracef(CDebug, "waiting: %s (pid=%d)", tgtOrig, flock.Pid) if FdStatus != nil { @@ -247,8 +242,11 @@ func runScript(tgtOrig string, errs chan error, traced bool) error { go func() { defer Jobs.Done() tracef(CLock, "LOCK_EX: %s", fdLock.Name()) + LockAgain: if err := unix.FcntlFlock(fdLock.Fd(), unix.F_SETLKW, &flock); err != nil { - log.Fatalln(err) + log.Println(err, fdLock.Name()) + time.Sleep(10 * time.Millisecond) + goto LockAgain } lockRelease() tracef(CDebug, "waiting done: %s", tgtOrig) @@ -582,7 +580,6 @@ func runScript(tgtOrig string, errs chan error, traced bool) error { os.Remove(fdDep.Name()) os.Remove(fdStdout.Name()) os.Remove(tmpPath) - os.Remove(fdLock.Name()) if FdStatus != nil { if _, err = FdStatus.Write([]byte{StatusDone}); err != nil { log.Fatalln(err) @@ -655,15 +652,12 @@ func runScript(tgtOrig string, errs chan error, traced bool) error { } // Was $1 touched? - if fd, err := os.Open(path.Join(cwdOrig, tgt)); err == nil { + if inode, err := inodeFromFileByPath(path.Join(cwdOrig, tgt)); err == nil { if inodePrev == nil { - fd.Close() runErr.Err = Err1WasTouched errs <- runErr return } - inode, err := inodeFromFile(fd) - fd.Close() if err != nil { runErr.Err = err errs <- runErr @@ -677,10 +671,8 @@ func runScript(tgtOrig string, errs chan error, traced bool) error { } if inodePrev != nil { - if fd, err := os.Open(path.Join(cwdOrig, tgt)); err == nil { - inode, err := inodeFromFile(fd) - fd.Close() - if err == nil && !inode.Equals(inodePrev) { + if inode, err := inodeFromFileByPath(path.Join(cwdOrig, tgt)); err == nil { + if !inode.Equals(inodePrev) { runErr.Err = Err1WasTouched errs <- runErr return