forked from canonical/snapd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd: rename SNAP_MOUNT_DIR to STATIC_SNAP_MOUNT_DIR
Given that most tools now detect the snap mount directory dynamically, picking either /var/lib/snapd/snap or /snap, depending on what is actually being used, it is the right time to rename the remaining option to the more appropriate name of static snap mount directory. The name differs because the value is baked into the files shipped with the distribution-specific packaging. This includes systemd units, environment generators and the management script. We still need this value and it is not going away anytime soon, but it is not the only value and so I think that separating SNAP_MOUNT_DIR from STATIC_SNAP_MOUNT_DIR is well, apt. Signed-off-by: Zygmunt Krynicki <[email protected]>
- Loading branch information
1 parent
4bf73f0
commit f971a46
Showing
7 changed files
with
38 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
set -e | ||
set +x | ||
|
||
SNAP_MOUNT_DIR="@SNAP_MOUNT_DIR@" | ||
STATIC_SNAP_MOUNT_DIR="@STATIC_SNAP_MOUNT_DIR@" | ||
|
||
show_help() { | ||
exec cat <<'EOF' | ||
|
@@ -18,12 +18,12 @@ A simple script to cleanup snap installations. | |
optional arguments: | ||
--help Show this help message and exit | ||
--snap-mount-dir=<path> Provide a path to be used as $SNAP_MOUNT_DIR | ||
--purge Purge all data from $SNAP_MOUNT_DIR | ||
--snap-mount-dir=<path> Provide a path to be used as $STATIC_SNAP_MOUNT_DIR | ||
--purge Purge all data from $STATIC_SNAP_MOUNT_DIR | ||
EOF | ||
} | ||
|
||
SNAP_UNIT_PREFIX="$(systemd-escape -p ${SNAP_MOUNT_DIR})" | ||
SNAP_UNIT_PREFIX="$(systemd-escape -p ${STATIC_SNAP_MOUNT_DIR})" | ||
|
||
systemctl_stop() { | ||
unit="$1" | ||
|
@@ -68,36 +68,36 @@ purge() { | |
systemctl_stop "$unit" | ||
|
||
if echo "$unit" | grep -q '.*\.mount' ; then | ||
# Transform ${SNAP_MOUNT_DIR}/core/3440 -> core/3440 removing any | ||
# Transform ${STATIC_SNAP_MOUNT_DIR}/core/3440 -> core/3440 removing any | ||
# extra / preceding snap name, eg: | ||
# /var/lib/snapd/snap/core/3440 -> core/3440 | ||
# /snap/core/3440 -> core/3440 | ||
# /snap/core//3440 -> core/3440 | ||
# NOTE: we could have used `systemctl show $unit -p Where --value` | ||
# but systemd 204 shipped with Ubuntu 14.04 does not support this | ||
snap_rev=$(systemctl show "$unit" -p Where | sed -e 's#Where=##' -e "s#$SNAP_MOUNT_DIR##" -e 's#^/*##') | ||
snap_rev=$(systemctl show "$unit" -p Where | sed -e 's#Where=##' -e "s#$STATIC_SNAP_MOUNT_DIR##" -e 's#^/*##') | ||
snap=$(echo "$snap_rev" |cut -f1 -d/) | ||
rev=$(echo "$snap_rev" |cut -f2 -d/) | ||
if [ -n "$snap" ]; then | ||
echo "Removing snap $snap" | ||
# aliases | ||
if [ -d "${SNAP_MOUNT_DIR}/bin" ]; then | ||
find "${SNAP_MOUNT_DIR}/bin" -maxdepth 1 -lname "$snap" -delete | ||
find "${SNAP_MOUNT_DIR}/bin" -maxdepth 1 -lname "$snap.*" -delete | ||
if [ -d "${STATIC_SNAP_MOUNT_DIR}/bin" ]; then | ||
find "${STATIC_SNAP_MOUNT_DIR}/bin" -maxdepth 1 -lname "$snap" -delete | ||
find "${STATIC_SNAP_MOUNT_DIR}/bin" -maxdepth 1 -lname "$snap.*" -delete | ||
fi | ||
# generated binaries | ||
rm -f "${SNAP_MOUNT_DIR}/bin/$snap" | ||
rm -f "${SNAP_MOUNT_DIR}/bin/$snap".* | ||
rm -f "${STATIC_SNAP_MOUNT_DIR}/bin/$snap" | ||
rm -f "${STATIC_SNAP_MOUNT_DIR}/bin/$snap".* | ||
# snap mount dir | ||
umount -l "${SNAP_MOUNT_DIR}/$snap/$rev" 2> /dev/null || true | ||
rm -rf "${SNAP_MOUNT_DIR:?}/$snap/$rev" | ||
rm -f "${SNAP_MOUNT_DIR}/$snap/current" | ||
umount -l "${STATIC_SNAP_MOUNT_DIR}/$snap/$rev" 2> /dev/null || true | ||
rm -rf "${STATIC_SNAP_MOUNT_DIR:?}/$snap/$rev" | ||
rm -f "${STATIC_SNAP_MOUNT_DIR}/$snap/current" | ||
# snap data dir | ||
rm -rf "/var/snap/$snap/$rev" | ||
rm -rf "/var/snap/$snap/common" | ||
rm -f "/var/snap/$snap/current" | ||
# opportunistic remove (may fail if there are still revisions left) | ||
for d in "${SNAP_MOUNT_DIR}/$snap" "/var/snap/$snap"; do | ||
for d in "${STATIC_SNAP_MOUNT_DIR}/$snap" "/var/snap/$snap"; do | ||
if [ -d "$d" ]; then | ||
rmdir --ignore-fail-on-non-empty "$d" | ||
fi | ||
|
@@ -135,9 +135,9 @@ purge() { | |
# Units may have been removed do a reload | ||
systemctl -q daemon-reload || true | ||
|
||
# Undo any bind mounts to ${SNAP_MOUNT_DIR} or /var/snap done by parallel | ||
# Undo any bind mounts to ${STATIC_SNAP_MOUNT_DIR} or /var/snap done by parallel | ||
# installs or LP:#1668659 | ||
for mp in "$SNAP_MOUNT_DIR" /var/snap; do | ||
for mp in "$STATIC_SNAP_MOUNT_DIR" /var/snap; do | ||
# btrfs bind mounts actually include subvolume in the filesystem-path | ||
# https://www.mail-archive.com/[email protected]/msg51810.html | ||
if grep -q " $mp $mp " /proc/self/mountinfo || | ||
|
@@ -181,7 +181,7 @@ purge() { | |
rm -rf /var/lib/snapd/features | ||
|
||
echo "Final directory cleanup" | ||
rm -rf "${SNAP_MOUNT_DIR}" | ||
rm -rf "${STATIC_SNAP_MOUNT_DIR}" | ||
rm -rf /var/snap | ||
|
||
echo "Removing leftover snap shared state data" | ||
|
@@ -220,8 +220,8 @@ while [ -n "$1" ]; do | |
exit | ||
;; | ||
--snap-mount-dir=*) | ||
SNAP_MOUNT_DIR=${1#*=} | ||
SNAP_UNIT_PREFIX=$(systemd-escape -p "$SNAP_MOUNT_DIR") | ||
STATIC_SNAP_MOUNT_DIR=${1#*=} | ||
SNAP_UNIT_PREFIX=$(systemd-escape -p "$STATIC_SNAP_MOUNT_DIR") | ||
shift | ||
;; | ||
--purge) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters