[llvm-shlib] Fix the version naming style of libLLVM for Windows (#85710)
[llvm-project.git] / bolt / test / runtime / wait_file.sh
blob42d4c5b29e795a729037ceea7c2d95a1be0572bf
1 #!/bin/bash
3 check_file() {
4 local file="$1"
5 if [ -z "$file" ]; then
6 echo "No file passed!"
7 exit 1
8 fi
9 if [ ! -f "$file" ]; then
10 return 1
13 fuser -s "$file"
14 local ret=$?
15 if [ $ret -eq 1 ]; then # noone has file open
16 return 0
18 if [ $ret -eq 0 ]; then # file open by some processes
19 return 1
21 if [ $ret -eq 127 ]; then
22 echo "fuser command not found!"
23 exit 1
26 echo "Unexpected exit code $ret from fuser!"
27 exit 1
30 wait_file() {
31 local file="$1"
32 local max_sleep=10
33 check_file "$file"
34 local ret=$?
35 while [ $ret -ne 0 ] && [ $max_sleep -ne 0 ]; do
36 sleep 1
37 max_sleep=$((max_sleep - 1))
38 check_file $file
39 ret=$?
40 done
41 if [ $max_sleep -eq 0 ]; then
42 echo "The file does not exist or the test hung!"
43 exit 1
47 file="$1"
48 wait_file "$file"