brintos

brintos / llvm-project-archived public Read only

0
0
Text · 931 B · 7346476 Raw
49 lines · bash
1#!/bin/bash2 3check_file() {4    local file="$1"5    if [ -z "$file" ]; then6        echo "No file passed!"7        exit 18    fi9    if [ ! -f "$file" ]; then10        return 111    fi12 13    fuser -s "$file"14    local ret=$?15    if [ $ret -eq 1 ]; then # no one has file open16        return 017    fi18    if [ $ret -eq 0 ]; then # file open by some processes19        return 120    fi21    if [ $ret -eq 127 ]; then22        echo "fuser command not found!"23        exit 124    fi25 26    echo "Unexpected exit code $ret from fuser!"27    exit 128}29 30wait_file() {31    local file="$1"32    local max_sleep=1033    check_file "$file"34    local ret=$?35    while [ $ret -ne 0 ] && [ $max_sleep -ne 0 ]; do36        sleep 137        max_sleep=$((max_sleep - 1))38        check_file $file39        ret=$?40    done41    if [ $max_sleep -eq 0 ]; then42        echo "The file does not exist or the test hung!"43        exit 144    fi45 46}47file="$1"48wait_file "$file"49