]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
Skip placeholder creation when source-config has no snapshots 1132/head
authorAsish Kumar <officialasishkumar@gmail.com>
Thu, 14 May 2026 03:52:20 +0000 (09:22 +0530)
committerAsish Kumar <officialasishkumar@gmail.com>
Mon, 18 May 2026 12:28:28 +0000 (17:58 +0530)
scripts/snapper-sync derives the highest snapshot number for each source-config from snbk list and then creates a placeholder named after that number under <subvolume>/.snapshots/. When no snapshots match, jq prints the literal string "null" for the existing max_by query, which previously led to a .snapshots/null directory.

Keep the original jq query unchanged and skip placeholder creation when max_num is "null". Also quote "$outputs" on the line that feeds the JSON list into jq, preserving the existing shellcheck SC2086 fix.

Fixes #1131

scripts/snapper-sync

index b49d07bebe4b34da82d383443322be5d3917641e..526139184509916a3c83dbeaf0572478f981a0db 100755 (executable)
@@ -25,7 +25,7 @@ config_mapping=$(
 
 if outputs=$(snbk --machine-readable json list); then
   snapshots=$(
-    echo $outputs |
+    echo "$outputs" |
     jq --argjson config_mapping "$config_mapping" '
       .snapshots | . |= map(. + {config: $config_mapping[.name]})
     '
@@ -47,6 +47,14 @@ echo "$config_mapping" | jq -r 'keys[]' | while read -r backup_config; do
     jq -r "[.[] | select(.config == \"$source_config\")] | max_by(.number) | .number"
   )
 
+  # Nothing to synchronize for this source-config (e.g. no snapshots have been transferred
+  # and the source has none either). Skip to avoid creating a literal '.snapshots/null'
+  # placeholder directory.
+  if [ "$max_num" = "null" ]; then
+    echo "No snapshots found for source-config '$source_config'; skipping."
+    continue
+  fi
+
   # Query the source subvolume path
   subvol_path=$(
     snapper --machine-readable json -c "$source_config" get-config | jq -r '.SUBVOLUME'