refactor: ssr-*.cfg files are user-owned after creation

ssr mackup scan now only suggests NEW files — it never overwrites an
existing ssr-*.cfg. Once created, the file belongs to the user who
edits it directly in ~/.mackup/ to customise which paths are backed up.

- _ssr_mackup_write_cfg: returns early if file already exists
- scan: drops UPD logic; only shows NEW suggestions
- _ssr_mackup_resolve_paths: removed SSR_MACKUP_SELECTIVE_PATHS support
  (ssr.conf config variable removed — edit the cfg files instead)
- Scan output: hints to edit files directly after creation

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-12 15:06:43 +02:00
parent be9b37010e
commit 61091aa6bf
3 changed files with 25 additions and 57 deletions
+13 -29
View File
@@ -76,62 +76,46 @@ _ssr_mackup_cfg_name() {
printf 'ssr-%s' "$name"
}
# Resolve the list of [configuration_files] entries for an item.
# If a selective override exists for the item, expand sub-paths that are
# present on disk. Falls back to the item itself (whole directory).
# Resolve the initial [configuration_files] entries for a NEW item.
# Uses _SSR_MACKUP_SELECTIVE defaults; once a cfg file exists the user owns
# it and this function is never called for that item again.
#
# Outputs one path per line.
_ssr_mackup_resolve_paths() {
local item="$1"
local -a all_selective=("${_SSR_MACKUP_SELECTIVE[@]}")
# Merge user-defined selectives from ssr.conf.
local entry
for entry in ${SSR_MACKUP_SELECTIVE_PATHS:-}; do
all_selective+=("$entry")
done
for entry in "${all_selective[@]}"; do
for entry in "${_SSR_MACKUP_SELECTIVE[@]}"; do
local key="${entry%%=*}"
local val="${entry#*=}"
if [[ "$key" == "$item" ]]; then
# Split comma-separated sub-paths; only include those that exist.
local sub
local IFS=','
for sub in $val; do
IFS=' '
local full="$item/$sub"
# List the path even if it doesn't exist yet — it may be created later.
printf '%s\n' "$full"
printf '%s\n' "$item/$sub"
done
return 0
fi
done
# No selective entry — back up the whole directory.
# No selective default — back up the whole directory.
printf '%s\n' "$item"
}
# Write a single ~/.mackup/<name>.cfg for one dot-path.
# Uses selective sub-paths when a matching entry exists in _SSR_MACKUP_SELECTIVE.
# Skips writing if content is unchanged (idempotent).
# Write a single ~/.mackup/<name>.cfg for a NEW item.
# Never called when the file already exists — existing files are user-owned.
_ssr_mackup_write_cfg() {
local cfg_dir="$1" item="$2"
local app_name; app_name="$(_ssr_mackup_cfg_name "$item")"
local cfg_file="$cfg_dir/${app_name}.cfg"
# Build [configuration_files] block.
# Never overwrite existing files — user may have customised them.
[[ -f "$cfg_file" ]] && return 0
local paths_block
paths_block="$(_ssr_mackup_resolve_paths "$item")"
local desired
desired="$(printf '[application]\nname = %s\n\n[configuration_files]\n%s\n' \
"$app_name" "$paths_block")"
if [[ -f "$cfg_file" ]] && [[ "$(cat "$cfg_file")" == "$desired" ]]; then
return 0 # already up-to-date
fi
printf '%s\n' "$desired" > "$cfg_file"
printf '[application]\nname = %s\n\n[configuration_files]\n%s\n' \
"$app_name" "$paths_block" > "$cfg_file"
}
# Build a newline-separated list of all paths already declared in Mackup's