Skip to content

Commit

Permalink
fix: prevent creation of clones after reverting to previous snap revi…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
st3v3nmw committed Oct 11, 2024
1 parent e29b279 commit 91869d2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
3 changes: 1 addition & 2 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ config_entries = [
("flush-interval", "flush_interval", None),
("exchange-interval", "exchange_interval", None),
("apt-update-interval", "apt_update_interval", None),
("exchange-interval", "exchange_interval", None),
("cloud", "cloud", None),
]

changed = set()
for snapctl_key, landscape_key, mapping_fn in config_entries:
value = _snapctl("get", snapctl_key).strip()
if not value:
# empty, value not has not changed
# empty, value has not changed
continue

if mapping_fn:
Expand Down
26 changes: 26 additions & 0 deletions snap/hooks/post-refresh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh -e

# This hook migrates the client's data from $SNAP_DATA to $SNAP_COMMON.
# It will be kept until all the existing
# clients are migrated to $SNAP_COMMON (using this hook).
# Full bug report: https://bugs.launchpad.net/landscape-client/+bug/2082616

OLD_DIR="$SNAP_DATA/var/lib/landscape/client"
NEW_DIR="$SNAP_COMMON/var/lib/landscape/client"

# Is a migration needed? We check if:
# 1. $OLD_DIR exists
# 2. And that we've not already done the migration
if [ -d "$OLD_DIR" ] && [ ! -f "$NEW_DIR/.migrated" ]; then
# Copy files while preserving attributes, links, etc
cp -a "$OLD_DIR/." "$NEW_DIR/"

# Flush file system buffers, ensuring all pending writes are completed
sync

# Add migration completion marker
touch "$NEW_DIR/.migrated"

# Remove the old directory
rm -rf "$OLD_DIR"
fi
16 changes: 13 additions & 3 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: |
in a Landscape account. It provides the Landscape client and requires a
Landscape account.
grade: stable # must be 'stable' to release into candidate/stable channels
grade: stable
architectures:
- build-on: [amd64]
- build-on: [arm64]
Expand All @@ -33,7 +33,7 @@ slots:
annotations:
interface: content
write:
- $SNAP_DATA/var/lib/landscape/client/annotations.d
- $SNAP_COMMON/var/lib/landscape/client/annotations.d

apps:
landscape-client:
Expand Down Expand Up @@ -61,11 +61,21 @@ apps:
plugs:
- network
- hardware-observe

# Previously, the client's data was stored in $SNAP_DATA
# which led to duplicate machine entries after reverting
# to a previous revision.
# After the migration of /var/lib/landscape/client from
# $SNAP_DATA to $SNAP_COMMON, the snap's layout changed.
# The new epoch 1* means the snap can read the previous
# & new epochs' data but can only write epoch 1 data.
epoch: 1*

layout:
/etc/landscape-client.conf:
bind-file: $SNAP_COMMON/etc/landscape-client.conf
/var/lib/landscape/client:
bind: $SNAP_DATA/var/lib/landscape/client
bind: $SNAP_COMMON/var/lib/landscape/client
/var/log/landscape:
bind: $SNAP_DATA/var/log/landscape

Expand Down

0 comments on commit 91869d2

Please sign in to comment.