Skip to content

Commit aead6a8

Browse files
committed
Make a new cleanup() function to remove temporary dir and exit
Also conditioned the pushd call so if it errors (no such file, file not a directory), it’ll now remove the reflac temporary directory too.
1 parent 0c012d9 commit aead6a8

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

reflac

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ eval set -- "$OPTS"
2121

2222
trap "exit 1" INT
2323

24+
cleanup()
25+
{
26+
rmdir "$TMPDIR"
27+
exit "$1"
28+
}
29+
2430
usage()
2531
{
2632
cat <<EOF
@@ -48,8 +54,7 @@ DIRECTORY should point ‘reflac’ to somewhere that contains *.flac
4854
files. Optionally terminate the argument list with -- so that any
4955
possible directory names don’t get misinterpreted as arguments.
5056
EOF
51-
rmdir "$TMPDIR"
52-
exit 0
57+
cleanup 0
5358
}
5459

5560
recompress()
@@ -130,10 +135,9 @@ while true ; do
130135
shift ;;
131136
-V|--version)
132137
echo "reflac version $VERSION"
133-
rmdir "$TMPDIR"
134-
exit 0 ;;
138+
cleanup 0 ;;
135139
--) shift; break ;;
136-
*) echo "$0: This should never happen!" >&2; exit 1 ;;
140+
*) echo "$0: This should never happen!" >&2; cleanup 1 ;;
137141
esac
138142
done
139143

@@ -142,8 +146,7 @@ if [ -z "$*" ]; then
142146
fi
143147

144148
if [ $VERBOSE -eq 0 ] && [ $NOACTION -eq 1 ]; then
145-
rmdir "$TMPDIR"
146-
exit 0
149+
cleanup 0
147150
fi
148151

149152
for dir; do
@@ -170,7 +173,7 @@ for dir; do
170173
-execdir "$SELF" -"$REFLAC_OPTS" {} \;
171174
fi
172175
else
173-
pushd -- "$dir" >/dev/null
176+
pushd -- "$dir" >/dev/null || cleanup $?
174177
if [ $VERBOSE -gt 0 ]; then readlink -f .; fi
175178
if [ ! -z "$(ls -- *.flac 2>/dev/null)" ]; then
176179
recompress

0 commit comments

Comments
 (0)