]> Cypherpunks.ru repositories - goredo.git/commitdiff
Relative paths to targets in outside directories
authorSergey Matveev <stargrave@stargrave.org>
Tue, 15 Dec 2020 12:16:35 +0000 (15:16 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 15 Dec 2020 12:31:54 +0000 (15:31 +0300)
README
run.go

diff --git a/README b/README
index 0cdf3ca40f20142a981a3fafb3897115cd458dcd..0cb969af6141cd4b16bbae27017ec7f558562df9 100644 (file)
--- a/README
+++ b/README
@@ -41,7 +41,7 @@ NOTES                                                     *goredo-notes*
 * "all" target is default
 * stdout is always captured, but no target is created if it was empty
 * empty targets are considered always out of date
-* .do's $3 is relative path to the file in same directory
+* .do's $3 is relative path to the file in target directory
 * .do search goes up to / by default, but can be limited with either
   $REDO_TOP_DIR environment variable, or by having .redo/top file in it
 * target's completion messages are written after they finish
diff --git a/run.go b/run.go
index c85543a0f8d7b4897bfc1ee65f69ef3b87200c82..589889e3db6edbf62f51f626e5f9ed04394323fd 100644 (file)
--- a/run.go
+++ b/run.go
@@ -28,6 +28,7 @@ import (
        "os"
        "os/exec"
        "path"
+       "path/filepath"
        "strings"
        "sync"
        "syscall"
@@ -306,13 +307,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