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

index 11bbd4f9dfca633c39ca60bf9405292a8e38f63a..b7840e5f6990712f7d89f313db5dfcd55f782e19 100755 (executable)
@@ -60,18 +60,23 @@ function sync_media_unset_lockfile {
 function sync_media_check_lockfile {
   local pid process
 
-  git ignore $LOCK
+  if [ ! -e ".gitignore" ] || ! grep -q "$LOCK" .gitignore; then
+    git ignore $LOCK
+  fi
 
   if [ ! -z "$LOCKFILE" ] && [ -f "$LOCKFILE" ]; then
     pid="`cat $LOCKFILE`"
     process="`ps --no-headers -o comm $pid`"
 
     if [ "$?" == "0" ] && [ "`ps --no-headers -o comm $$`" == "$process" ]; then
-      fatal "Another program is running for $LOCKFILE, skipping run"
+      echo "Another program is running for $LOCKFILE, skipping"
+      return 1
     else
       echo "Found old lockfile $LOCKFILE, removing it"
       sync_media_unset_lockfile
     fi
+
+    return 0
   fi
 }
 
@@ -118,6 +123,12 @@ function sync_media_add_metadata {
   #metadata_state="unlock"
   metadata_state="unannex"
 
+  # Gitignore
+  if [ -e ".gitignore" ]; then
+    git annex $metadata_state .gitignore
+    git add .gitignore
+  fi
+
   # Playlist files in the playlist folder
   if [ -d "playlists" ]; then
     find playlists -name '*.m3u'  -type l -exec git annex $metadata_state {} \;
@@ -287,8 +298,11 @@ for folder in $REPOSITORIES; do
     echo "Syncing $CACHE/$folder..."
 
     # Lockfile handling
-    sync_media_check_lockfile
-    sync_media_set_lockfile
+    if ! sync_media_check_lockfile; then
+      continue
+    else
+      sync_media_set_lockfile
+    fi
 
     # Ensure the removable volume is in the list of remotes
     sync_media_ensure_remote $REMOTE $VOLUME/$MEDIA/$folder
@@ -382,8 +396,11 @@ if [ ! -z "$DRIVE" ] && [ -d "$VOLUME/$MEDIA" ]; then
       echo "Syncing $VOLUME/$MEDIA/$folder..."
 
       # Lockfile handling
-      sync_media_check_lockfile
-      sync_media_set_lockfile
+      if ! sync_media_check_lockfile; then
+        continue
+      else
+        sync_media_set_lockfile
+      fi
 
       sync_media_playlist_perms
       sync_media_ensure_remote $HOST $CACHE/$folder