use distinct db for update checks

Tue, 16 May 2023 20:35:01 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Tue, 16 May 2023 20:35:01 -0500
changeset 1115
15ca9da8cd59
parent 1114
fd7f92c949fb
child 1116
2d8f07b212e9

use distinct db for update checks

.lib/sh/stubexec.sh file | annotate | diff | comparison | revisions
.vimrc file | annotate | diff | comparison | revisions
bin/kv file | annotate | diff | comparison | revisions
--- a/.lib/sh/stubexec.sh
+++ b/.lib/sh/stubexec.sh
@@ -1,3 +1,29 @@
+cache="${XDG_CACHE_HOME:-$HOME/.cache}/stubexec"
+
+stubexec() {
+  local real_bin="$(realbin "$0")"
+  if [ ! -x "$real_bin" ] || age_check $0; then
+    try_nix "$@" ||
+      try_install_callback
+    touch_checktime "$0"
+    stubexec "$@"
+  fi
+  exec "$real_bin" "$@"
+}
+
+db() {
+  mkdir -p "$cache"
+  kv "$cache/db" "$@"
+}
+
+touch_checktime() {
+  db touch "$(basename $1)"
+}
+
+age_check() {
+  db age_days_gt "$(basename $1)" "${age_limit:-90}"
+}
+
 realpath() {
   local dir="$(dirname -- "$1")"
   local file="$(basename -- "$1")"
@@ -19,12 +45,6 @@ shim_filter() {
   done
 }
 
-age_check() {
-  local subject=''
-  read subject
-  find "$subject" -mtime -${age_limit:-90} -print
-}
-
 realbin() {
   local bn="$(basename $1)"
   which -a "$bn" |
@@ -33,22 +53,13 @@ realbin() {
     head -n 1
 }
 
-stubexec() {
-  local real_bin="$(realbin "$0" | age_check)"
-  if [ -x "$real_bin" ]; then
-    exec "$real_bin" "$@"
-  fi
-  try_nix "$@"
-  try_install_callback
-  stubexec "$@"
-}
-
 has() {
   type "$1" >/dev/null 2>&1
 }
 
 try_nix() {
   [ "${nix_ref:-}" ] && has nix || return 1
+
   local installed_slot="$(
     nix profile list | perl -anE 'BEGIN { $m = shift =~ s/#/#.+/r } say $F[0] if $F[1] =~ $m' "$nix_ref"
   )"
@@ -57,15 +68,10 @@ try_nix() {
   else
     nix profile install "$nix_ref"
   fi
-  # skip age check
-  exec "$(realbin "$0")" "$@"
-  # FIXME: so right now, this works but will check for upgrades every run past
-  # the age check
 }
 
 try_install_callback() {
   install_it
-  touch "$(realbin "$0")"  # In case of no updates
 }
 
 bina_install() {
--- a/.vimrc
+++ b/.vimrc
@@ -345,7 +345,7 @@ let g:vimwiki_list = [
     \ 'auto_tags': 1, 'auto_toc': 1, 'automatic_nested_syntaxes': 1
   \ },
   \ {
-    \ 'path': '~/Documents/SpiderOak Hive/vimwiki',
+    \ 'path': '~/SynologyDrive/vimwiki',
     \ 'auto_tags': 1, 'auto_toc': 1, 'automatic_nested_syntaxes': 1
   \ }
 \ ]
new file mode 100755
--- /dev/null
+++ b/bin/kv
@@ -0,0 +1,25 @@
+#!/usr/bin/env perl
+use v5.32;
+use Fcntl;
+use AnyDBM_File;
+
+my ($filename, $method, @args) = @ARGV;
+
+tie my %h, 'AnyDBM_File', $filename, O_RDWR|O_CREAT, 0660
+  or die "tie $filename: $!";
+
+$, = "\n";
+
+say main->can($method)->(@args);
+
+sub get { $h{+shift} }
+sub set { $h{$_[0]} = $_[1] and exit }
+sub del { delete $h{+shift} }
+
+sub touch { $h{+shift} = time and exit }
+sub age { time - $h{+shift} }
+sub age_days { int(age(shift) / 86_400) }
+sub age_days_gt { exit 0+!(age_days(shift) > shift) }
+
+sub keys { keys %h }
+sub dump { map { "$_ = $h{$_}" } keys %h }

mercurial