Skip to content

Commit a9ff7e6

Browse files
authored
core: skip mount points during backup and clean installs (#16532)
* Skip mount points during backup and clean install Prevent accidental deletion or backup of mount points: - In create_backup(), skip paths that are mount points with a warning - In _deploy_source_tarball(), _deploy_unpacked_archive(), and fetch_and_deploy_from_url(), use find with mountpoint pruning to avoid deleting mount point directories during CLEAN_INSTALL * change comments for new variant Update `_deploy_source_tarball` and related helper comments to note that CLEAN_INSTALL wipes target contents including dotfiles while preserving mount points. This improves guidance around backup/restore of config dotfiles during source deployments.
1 parent d0456f5 commit a9ff7e6

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

misc/tools.func

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,10 @@ create_backup() {
13361336
msg_warn "Skipping backup of '${path}' (not found)"
13371337
continue
13381338
fi
1339+
if mountpoint -q "$path" 2>/dev/null; then
1340+
msg_warn "Skipping backup of '${path}' (is a mount point)"
1341+
continue
1342+
fi
13391343
dest="${store}/files${path}"
13401344
if ! mkdir -p "$(dirname "$dest")" || ! cp -a "$path" "$dest"; then
13411345
msg_error "Backup of '${path}' failed - aborting update"
@@ -2524,9 +2528,9 @@ _download_source_tarball() {
25242528
# directory). Extracts <tarball_path> into <workdir>, then copies the contents
25252529
# of that top-level directory into <target>.
25262530
#
2527-
# - Honors CLEAN_INSTALL=1 (wipes <target> first, dotfiles included — back
2528-
# up config dotfiles like .env via create_backup and call restore_backup
2529-
# BEFORE any build step that sources them).
2531+
# - Honors CLEAN_INSTALL=1 (wipes <target> first, dotfiles included, mount
2532+
# points preserved — back up config dotfiles like .env via create_backup
2533+
# and call restore_backup BEFORE any build step that sources them).
25302534
# - Does NOT own <workdir>: the caller creates it and is responsible for its
25312535
# cleanup (typically via a RETURN trap on its tmpdir).
25322536
# - cp failures are non-fatal here, matching the previous inline behavior.
@@ -2538,7 +2542,7 @@ _deploy_source_tarball() {
25382542

25392543
mkdir -p "$target"
25402544
if [[ "${CLEAN_INSTALL:-0}" == "1" ]]; then
2541-
find "${target:?}" -mindepth 1 -delete
2545+
find "${target:?}" -mindepth 1 \( -type d -exec mountpoint -q {} \; -prune \) -o -delete
25422546
fi
25432547

25442548
tar --no-same-owner -xzf "$tarball" -C "$workdir" || {
@@ -2564,9 +2568,9 @@ _deploy_source_tarball() {
25642568
# a single top-level directory, that directory is stripped (its contents land
25652569
# directly in <target>); otherwise the archive contents are copied as-is.
25662570
#
2567-
# - Honors CLEAN_INSTALL=1 (wipes <target> first, dotfiles included — back
2568-
# up config dotfiles like .env via create_backup and call restore_backup
2569-
# BEFORE any build step that sources them).
2571+
# - Honors CLEAN_INSTALL=1 (wipes <target> first, dotfiles included, mount
2572+
# points preserved — back up config dotfiles like .env via create_backup
2573+
# and call restore_backup BEFORE any build step that sources them).
25702574
# - Does NOT own <workdir>: the caller creates it and cleans it up.
25712575
#
25722576
# Returns: 0 on success, 65 on unsupported format, 251 on extraction failure,
@@ -2627,7 +2631,7 @@ _deploy_unpacked_archive() {
26272631
# was truncated, the archive was unreadable, or it unpacked to nothing.
26282632
mkdir -p "$target"
26292633
if [[ "${CLEAN_INSTALL:-0}" == "1" ]]; then
2630-
find "${target:?}" -mindepth 1 -delete
2634+
find "${target:?}" -mindepth 1 \( -type d -exec mountpoint -q {} \; -prune \) -o -delete
26312635
fi
26322636

26332637
if ! cp -r "$source_dir"/* "$target/"; then
@@ -9368,7 +9372,7 @@ fetch_and_deploy_from_url() {
93689372
mkdir -p "$directory"
93699373
93709374
if [[ "${CLEAN_INSTALL:-0}" == "1" ]]; then
9371-
find "${directory:?}" -mindepth 1 -delete
9375+
find "${directory:?}" -mindepth 1 \( -type d -exec mountpoint -q {} \; -prune \) -o -delete
93729376
fi
93739377
93749378
local unpack_tmp

0 commit comments

Comments
 (0)