]> gitweb.fluxo.info Git - hydra.git/commitdiff
Fix: hydractl: sync-media:improved lock file handling
authorSilvio Rhatto <rhatto@riseup.net>
Sat, 27 Sep 2025 19:31:51 +0000 (16:31 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sat, 27 Sep 2025 19:31:51 +0000 (16:31 -0300)
docs/changelog.md
share/hydractl/sync-media

index 4cf0afbd490288e2cde351af85b44439c2a6097f..011c3bb5357b9011bc519ab79309d78d04ce5d10 100644 (file)
@@ -24,5 +24,5 @@
         files and manage them through Git, instead of keeping them as unlocked
         files.
   * [x] Added support for `.m3u8` files.
-  * [x] Sync lock, respected by other applications such as `docshower`
-        from [utils-doc][https://git.fluxo.info/utils-doc].
+  * [x] Sync lock for git-annex repositories, respected by other applications
+        such as `docshower` from [utils-doc][https://git.fluxo.info/utils-doc].
index 08d62809f8dd43c5c6237928f74d0d4b12df8e9e..11bbd4f9dfca633c39ca60bf9405292a8e38f63a 100755 (executable)
@@ -50,6 +50,7 @@ function sync_media_set_lockfile {
 # Adapted from borger
 function sync_media_unset_lockfile {
   if [ ! -z "$LOCKFILE" ]; then
+    git annex unannex $LOCK
     rm -f $LOCKFILE || echo "Could not remove lockfile $LOCKFILE"
   fi
 }
@@ -59,13 +60,12 @@ function sync_media_unset_lockfile {
 function sync_media_check_lockfile {
   local pid process
 
+  git ignore $LOCK
+
   if [ ! -z "$LOCKFILE" ] && [ -f "$LOCKFILE" ]; then
     pid="`cat $LOCKFILE`"
     process="`ps --no-headers -o comm $pid`"
 
-    git annex unannex $LOCK
-    git ignore $LOCK
-
     if [ "$?" == "0" ] && [ "`ps --no-headers -o comm $$`" == "$process" ]; then
       fatal "Another program is running for $LOCKFILE, skipping run"
     else
@@ -369,6 +369,7 @@ if [ ! -z "$DRIVE" ] && [ -d "$VOLUME/$MEDIA" ]; then
 
   # Iterate over existing repositories in the removable media
   for folder in $REPOSITORIES; do
+    LOCKFILE="$VOLUME/$MEDIA/$folder/$LOCK"
 
     # Sync each local repository in the removable media
     if [ -d "$VOLUME/$MEDIA/$folder/.git/annex" ]; then
@@ -380,6 +381,10 @@ if [ ! -z "$DRIVE" ] && [ -d "$VOLUME/$MEDIA" ]; then
       cd $VOLUME/$MEDIA/$folder
       echo "Syncing $VOLUME/$MEDIA/$folder..."
 
+      # Lockfile handling
+      sync_media_check_lockfile
+      sync_media_set_lockfile
+
       sync_media_playlist_perms
       sync_media_ensure_remote $HOST $CACHE/$folder
       sync_media_identity
@@ -396,6 +401,9 @@ if [ ! -z "$DRIVE" ] && [ -d "$VOLUME/$MEDIA" ]; then
       git gc
       git prune
       #git annex drop --auto --numcopies=2
+
+      # Unset the lockfile
+      sync_media_unset_lockfile
       )
     elif [ -d "$CACHE/$folder" ] && [ ! -d "$CACHE/$folder/.git" ]; then
       # Avoid those configured to be skipped