Show More
@@ -1,39 +1,39 | |||
|
1 | 1 | #!/bin/sh |
|
2 | 2 | # |
|
3 | 3 | # wait up to TIMEOUT seconds until a WAIT_ON_FILE is created. |
|
4 | 4 | # |
|
5 | 5 | # In addition, this script can create CREATE_FILE once it is ready to wait. |
|
6 | 6 | |
|
7 | 7 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
|
8 | 8 | echo $# |
|
9 | 9 | echo "USAGE: $0 TIMEOUT WAIT_ON_FILE [CREATE_FILE]" |
|
10 | 10 | fi |
|
11 | 11 | |
|
12 | 12 | timer="$1" |
|
13 | 13 | |
|
14 | 14 | # Scale the timeout to match the sleep steps below, i.e. 1/0.02. |
|
15 | 15 | timer=$(( 50 * $timer )) |
|
16 | 16 | # If the test timeout have been extended, also scale the timer relative |
|
17 | 17 | # to the normal timing. |
|
18 | 18 | if [ "$HGTEST_TIMEOUT_DEFAULT" -lt "$HGTEST_TIMEOUT" ]; then |
|
19 | 19 | timer=$(( ( $timer * $HGTEST_TIMEOUT) / $HGTEST_TIMEOUT_DEFAULT )) |
|
20 | 20 | fi |
|
21 | 21 | |
|
22 | 22 | wait_on="$2" |
|
23 | 23 | create="" |
|
24 | 24 | if [ $# -eq 3 ]; then |
|
25 | 25 | create="$3" |
|
26 | 26 | fi |
|
27 | 27 | |
|
28 | 28 | if [ -n "$create" ]; then |
|
29 | 29 | touch "$create" |
|
30 | 30 | create="" |
|
31 | 31 | fi |
|
32 |
while [ "$timer" -gt 0 ] && |
|
|
32 | while [ "$timer" -gt 0 ] && !([ -e "$wait_on" ] || [ -L "$wait_on" ]) ; do | |
|
33 | 33 | timer=$(( $timer - 1)) |
|
34 | 34 | sleep 0.02 |
|
35 | 35 | done |
|
36 | 36 | if [ "$timer" -le 0 ]; then |
|
37 | 37 | echo "file not created after $1 seconds: $wait_on" >&2 |
|
38 | 38 | exit 1 |
|
39 | 39 | fi |
General Comments 0
You need to be logged in to leave comments.
Login now