Skip to content

Commit b4d8bd1

Browse files
committed
improve show-busy-java-threads: check before write file
1 parent b3907ec commit b4d8bd1

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

show-busy-java-threads

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ colorPrint() {
3737
shift
3838

3939
colorEcho "$color" "$@"
40-
# use "{} &> /dev/null" to discard bash error message:
41-
# line 42: xxx.log: Permission denied
42-
{
43-
[ -n "$append_file" ] && echo "$@" >> "$append_file"
44-
[ -n "$store_dir" ] && echo "$@" >> "${store_file_prefix}$PROG"
45-
} &> /dev/null
40+
[ -n "$append_file" -a -w "$append_file" ] && echo "$@" >> "$append_file"
41+
[ -n "$store_dir" -a -w "$store_dir" ] && echo "$@" >> "${store_file_prefix}$PROG"
42+
}
43+
44+
normalPrint() {
45+
echo "$@"
46+
[ -n "$append_file" -a -w "$append_file" ] && echo "$@" >> "$append_file"
47+
[ -n "$store_dir" -a -w "$store_dir" ] && echo "$@" >> "${store_file_prefix}$PROG"
4648
}
4749

4850
redPrint() {
@@ -61,12 +63,6 @@ bluePrint() {
6163
colorPrint 36 "$@"
6264
}
6365

64-
normalPrint() {
65-
echo "$@"
66-
[ -n "$append_file" ] && echo "$@" >> "$append_file"
67-
[ -n "$store_dir" ] && echo "$@" >> "${store_file_prefix}$PROG"
68-
}
69-
7066
die() {
7167
redPrint "Error: $@" 1>&2
7268
exit 1

0 commit comments

Comments
 (0)