]> Cypherpunks.ru repositories - goredo.git/commitdiff
Chmod even if not renamed
authorSergey Matveev <stargrave@stargrave.org>
Sat, 7 Oct 2023 14:25:18 +0000 (17:25 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 7 Oct 2023 14:25:18 +0000 (17:25 +0300)
run.go
t/goredo-chmoding.t [new file with mode: 0755]

diff --git a/run.go b/run.go
index 33857bfc5c3fb227d3fa43f17ae0669cc8409cc1..283ebc9b673b07cdc78f1e164842ac8c07055e8d 100644 (file)
--- a/run.go
+++ b/run.go
@@ -702,12 +702,18 @@ 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 {
                                err = ErrLine(err)
                                goto Finish
                        }
+                       if fi, rerr := fd.Stat(); rerr == nil {
+                               chmod = fi.Mode()
+                       } else {
+                               err = rerr
+                       }
                        defer fd.Close()
                } else if fiStdout.Size() > 0 {
                        fd = fdStdout
@@ -740,6 +746,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
diff --git a/t/goredo-chmoding.t b/t/goredo-chmoding.t
new file mode 100755 (executable)
index 0000000..7986697
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+testname=`basename "$0"`
+test_description="Check that non-renamed target copies mode from temporary target"
+. $SHARNESS_TEST_SRCDIR/sharness.sh
+export REDO_TOP_DIR="`pwd`" REDO_NO_PROGRESS=1
+
+echo echo ok > foo.do
+redo foo
+test_expect_success "foo is non executable" '[ ! -x foo ]'
+inode0=`stat -f %i foo`
+
+cat > foo.do <<EOF
+echo ok > \$3
+chmod +x \$3
+EOF
+redo foo
+test_expect_success "foo is executable" '[ -x foo ]'
+inode1=`stat -f %i foo`
+test_expect_success "foo was not renamed" '[ $inode0 = $inode1 ]'
+
+test_done