Skip to content

Commit

Permalink
Fix is_older_than_x_days: use find instead of stat (#481)
Browse files Browse the repository at this point in the history
Only relevant in case the lock file is present, but still...

This was tested in:

* macOS - 13.5.1
* Ubuntu - 22.04.3

I didn't test on FreeBSD (couldn't find an easy way to run it) but
according to what I read in the `find` manual this solution should
be working
  • Loading branch information
paulo-ferraz-oliveira committed Oct 24, 2023
1 parent d63e4f0 commit 736b8fb
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions kerl
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,8 @@ is_older_than_x_days() {
# $1: file to check
# $2: age in days

eval "$(\stat -s "$1")"
# shellcheck disable=SC2154 # .. is referenced but not assigned.
if [ $(($(date +%s) - st_mtime)) -gt $(($2 * 24 * 3600)) ]; then
old_file=$(find "$1" -type f -mtime "$2")
if [ -n "$old_file" ]; then
return 0
else
return 1
Expand All @@ -630,7 +629,7 @@ lock() {
# $2: folder to act on

if [ -f "$2/$1.lock" ]; then
if is_older_than_x_days "$2/$1.lock" 14; then
if is_older_than_x_days "$2/$1.lock" "+14"; then
unlock "$1" "$2"
else
error "trying to $1 in $2, but lock file ($2/$1.lock) exists!"
Expand Down

0 comments on commit 736b8fb

Please sign in to comment.