Wait in get till no processes are using the output filepath

This commit is contained in:
Shivam Mathur 2024-11-11 14:32:06 +05:30
parent 449afbcaec
commit 80075aeba5
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A

View File

@ -89,6 +89,12 @@ get() {
echo "Another process is downloading a file at $file_path, waiting"
sleep 1
done
if [ "$execute" = "-e" ]; then
until [ -z "$(fuser "$file_path" 2>/dev/null)" ]; do
echo "Waiting for other processes to stop using $file_path..."
sleep 1
done
fi
trap 'sudo rm -rf "$lock_path"' EXIT SIGINT SIGTERM
for link in "${links[@]}"; do
status_code=$(sudo curl -w "%{http_code}" -o "$file_path" "${curl_opts[@]}" "$link")