From 44a1f0561eb67b042295231ec1ea4eb738c45a0b Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sat, 7 Oct 2023 17:25:18 +0300 Subject: [PATCH] Chmod even if not renamed --- run.go | 12 ++++++++++++ t/goredo-chmoding.t | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100755 t/goredo-chmoding.t diff --git a/run.go b/run.go index 33857bf..283ebc9 100644 --- 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 index 0000000..7986697 --- /dev/null +++ b/t/goredo-chmoding.t @@ -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 < \$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 -- 2.44.0