fix race condition
[distro-setup] / conflink
index aecd0377119a99daf04b7d0e497e65c46f729de0..d72f98c29e775a1aa7b6bbf9c0a7689687864c3c 100755 (executable)
--- a/conflink
+++ b/conflink
@@ -24,14 +24,25 @@ m() {
 s() { sudo "$@"; }
 
 lnf() { /a/exe/lnf "$@"; }
+now=$(date +%s)
+f=~/.local/conflink
+fast=false
+if [[ -e $f ]] && (( $(stat -c %Y $f) > $now - 60*60*24 )); then
+  fast=true
+fi
 if [[ $1 == -f ]]; then # f for fast
-  lnf() { ln -sf "$@"; }
+  fast=true
+  shift
 elif
   [[ $1 ]]; then
   echo "error: unrecognized arguments" >&2
   exit 0
 fi
 
+if $fast; then
+  lnf() { ln -sf "$@"; }
+fi
+
 shopt -s nullglob
 shopt -s extglob
 shopt -s dotglob
@@ -164,4 +175,3 @@ case $user in
     echo "$0: error: unexpected user"; exit 1
     ;;
 esac
-