X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=run.go;h=8ea91d1eb9ca10d5789cd5cd9159c6c9aeb715f4;hb=refs%2Fheads%2Fmaster;hp=33857bfc5c3fb227d3fa43f17ae0669cc8409cc1;hpb=6dce71355599d4caf8267f6f02520037480f7ba3;p=goredo.git diff --git a/run.go b/run.go index 33857bf..8ea91d1 100644 --- a/run.go +++ b/run.go @@ -1,19 +1,17 @@ -/* -goredo -- djb's redo implementation on pure Go -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 -the Free Software Foundation, version 3 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ +// goredo -- djb's redo implementation on pure Go +// Copyright (C) 2020-2024 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 +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . // Targets runner @@ -133,7 +131,7 @@ func mkdirs(pth string) error { } func isModified(dep *Dep, tgt *Tgt) ( - modified bool, ourInode Inode, hshPrev Hash, err error, + modified bool, ourInode *Inode, hshPrev Hash, err error, ) { if dep == nil { return @@ -289,9 +287,11 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error { if StopIfMod { return fmt.Errorf("%s externally modified", tgt) } + Jobs.Add(1) tracef(CWarn, "%s externally modified: not redoing", tgt) go func() { errs <- nil + Jobs.Done() }() return nil } @@ -371,7 +371,7 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error { var cmdName string var args []string if err = unix.Access(doFile.rel, unix.X_OK); err == nil { - cmdName = doFileT + cmdName = doFile.a args = make([]string, 0, 3) } else { cmdName = "/bin/sh" @@ -557,7 +557,7 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error { } w := bufio.NewWriter(fdStderr) - { + if !fdDepExists { var ifchanges []string ifchanges, err = depReadOnlyIfchanges(tgt.dep) if err != nil { @@ -628,22 +628,27 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error { line = scanner.Text() if strings.HasPrefix(line, childStderrPrefix) { line = line[len(childStderrPrefix):] - os.Stderr.WriteString(StderrPrefix + line + "\n") + if StderrPrefix == "" { + withPrependedTgt(line) + } else { + stderrWrite(StderrPrefix + line + "\n") + } continue } if fdStderr != nil { ts.FromTime(time.Now()) - LogMutex.Lock() fmt.Fprintln(fdStderr, tai64n.Encode(ts[:]), line) - LogMutex.Unlock() } if StderrSilent { continue } - if MyPid == 0 { - tracef(CNone, "%s", line) + if MyPID != 0 { + line = pid + " " + line + } + if StderrPrefix == "" { + withPrependedTgt("[" + tgt.rel + "]" + line) } else { - tracef(CNone, "%s %s", pid, line) + stderrWrite(StderrPrefix + "[" + tgt.rel + "]" + line + "\n") } } close(stderrTerm) @@ -666,7 +671,7 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error { // Was $1 touched? if inode, err := inodeFromFileByPath(tgt.a); err == nil { - if inodePrev == "" { + if inodePrev == nil { runErr.Err = Err1WasTouched errs <- runErr return @@ -702,6 +707,7 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error { // Determine what file we must process at last var fd *os.File + var chmod fs.FileMode if tmpExists { fd, err = os.Open(tmpPath) if err != nil { @@ -709,6 +715,12 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error { goto Finish } defer fd.Close() + if fi, rerr := fd.Stat(); rerr == nil { + chmod = fi.Mode() + } else { + err = ErrLine(rerr) + goto Finish + } } else if fiStdout.Size() > 0 { fd = fdStdout } @@ -740,6 +752,12 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error { if err != nil { goto Finish } + if chmod != 0 { + err = ErrLine(os.Chmod(tgt.a, chmod)) + if err != nil { + goto Finish + } + } err = ErrLine(os.Chtimes(tgt.a, finished, finished)) if err != nil { goto Finish