X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=run.go;h=f08547008d9f76a04e11b164be62e553bfa5a4c5;hb=8d7b239655f024fa18f22a1d7988d184732000c3;hp=c85543a0f8d7b4897bfc1ee65f69ef3b87200c82;hpb=db81599c97bdc51c5fd1edfabc4840438a26029a;p=goredo.git diff --git a/run.go b/run.go index c85543a..f085470 100644 --- a/run.go +++ b/run.go @@ -1,6 +1,6 @@ /* goredo -- redo implementation on pure Go -Copyright (C) 2020 Sergey Matveev +Copyright (C) 2020-2021 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 @@ -28,6 +28,7 @@ import ( "os" "os/exec" "path" + "path/filepath" "strings" "sync" "syscall" @@ -76,8 +77,6 @@ type RunErr struct { Err error } -func (e RunErr) Unwrap() error { return e.Err } - func (e *RunErr) Name() string { var name string if e.DoFile == "" { @@ -306,13 +305,22 @@ func runScript(tgtOrig string, errs chan error, traced bool) error { } // Temporary file for stdout - fdStdout, err := tempfile(cwd, tgt) + fdStdout, err := tempfile(cwdOrig, tgt) if err != nil { cleanup() return TgtErr{tgtOrig, err} } tmpPath := fdStdout.Name() + ".3" // and for $3 - args = append(args, tgt, basename, path.Base(tmpPath)) + tmpPathRel, err := filepath.Rel(cwd, tmpPath) + if err != nil { + panic(err) + } + args = append( + args, + path.Join(dirPrefix, tgt), + path.Join(dirPrefix, basename), + tmpPathRel, + ) cmd := exec.Command(cmdName, args...) cmd.Dir = cwd @@ -448,14 +456,16 @@ func runScript(tgtOrig string, errs chan error, traced bool) error { } // Was $1 touched? - if fd, err := os.Open(path.Join(cwdOrig, tgt)); err == nil { - ts, err := fileCtime(fd) - fd.Close() - if err == nil && ts != tsPrev { - runErr.Err = errors.New("$1 was explicitly touched") - errs <- runErr + if tsPrev != "" { + if fd, err := os.Open(path.Join(cwdOrig, tgt)); err == nil { + ts, err := fileCtime(fd) fd.Close() - return + if err == nil && ts != tsPrev { + runErr.Err = errors.New("$1 was explicitly touched") + errs <- runErr + fd.Close() + return + } } } @@ -495,6 +505,7 @@ func runScript(tgtOrig string, errs chan error, traced bool) error { // Do we need to ifcreate it, of ifchange with renaming? if fd == nil { + os.Remove(path.Join(cwdOrig, tgt)) err = ifcreate(fdDep, tgt) if err != nil { goto Finish