Skip to content

Commit

Permalink
os-helpers: extend filesystem helper with wait4rm
Browse files Browse the repository at this point in the history
This function waits until a file is removed or times out - useful to
implement basic file based mutexes.

Change-type: patch
Signed-off-by: Alex Gonzalez <alexg@balena.io>
  • Loading branch information
alexgg committed May 3, 2024
1 parent 7674716 commit bb77f62
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ wait4file() {
return 0
}

# Wait for a file to be removed with loop count limit.
# Use-case example: wait for udev to create a filesystem symlink.
# Arguments:
# 1 - target path
# 2 - number of loops (each loop sleeps for 100ms)
wait4rm() {
_lpath="$1"
_lloops="$2"

while [ -e "$_lpath" ]; do
if [ "$_lloops" -gt 0 ]; then
sleep 0.1
_lloops=$((_lloops-1))
else
return 1
fi
done
return 0
}

# Output the UUID for the specified block device.
# Arguments:
# 1 - Target block device
Expand Down

0 comments on commit bb77f62

Please sign in to comment.