Skip to content

Commit

Permalink
nhc: Fix detached mode result writability test
Browse files Browse the repository at this point in the history
In detached mode, we check to see if we can write to the result file
before actually trying to do so, but `test -w` returns false for
non-existent files, not just unwritable files.  So we need to redo the
logic of that test to account for both cases: (1) file exists and is
writable, or (2) file does not exist but directory does and is
writable.

While I was at it, I also changed where the write is done to account
for a third scenario:  (3) everything looks like it should work but
the write itself fails.

Fixes #59.  Thanks to @hwj0303 for spotting this!
  • Loading branch information
mej committed Nov 8, 2018
1 parent 35b7ad6 commit fa5d035
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions nhc
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ function die() {
fi
fi
if [[ -n "$NHC_DETACHED" ]]; then
if [[ -w "$RESULTFILE" ]]; then
echo "$RET $*" > $RESULTFILE
if [[ -w "$RESULTFILE" || (! -e "$RESULTFILE" && -w "${RESULTFILE%/*}") ]] && echo "$RET $*" > $RESULTFILE ; then
dbg "Wrote results file $RESULTFILE: $RET $*"
else
log "ERROR: $NAME: Unable to write to \"$RESULTFILE\" -- is ${RESULTFILE%/*} read-only?"
syslog "ERROR: $NAME: Unable to write to \"$RESULTFILE\" -- is ${RESULTFILE%/*} read-only?"
log "ERROR: $NAME: Unable to write to \"$RESULTFILE\" -- is ${RESULTFILE%/*} missing/read-only?"
syslog "ERROR: $NAME: Unable to write to \"$RESULTFILE\" -- is ${RESULTFILE%/*} missing/read-only?"
syslog_flush
fi
elif [[ "$NHC_RM" == "sge" ]]; then
Expand Down

0 comments on commit fa5d035

Please sign in to comment.