Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent creation of clones after reverting to previous snap revision #275

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a related/intended change? If so, why is it related?

Copy link
Collaborator Author

@st3v3nmw st3v3nmw Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed it's repeated. It's on line 37 & 39. I removed the one in line 39.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks!

("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
Loading