1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
|
summary: Check that the experimental hidden dir feature migrates the dir
details: |
Check that enabling the experimental hidden-snap-folder feature migrates
snap data directories and corresponding environment variables from ~/snap
to ~/.snap/data during the next refresh. Verify that taking a snapshot
before the migration and restoring it afterwards still restores the data.
Check that the migration is reverted if the feature is unset.
NOTE: there is a significant commented-out portion of this test related to
the introduction of a ~/Snap directory for user-facing data. The plans for
it were put on hold and is unclear when/if they'll be restored.
environment:
NAME: test-snapd-tools
prepare: |
snap pack "$TESTSLIB/snaps/$NAME"
"$TESTSTOOLS"/snaps-state install-local "$NAME"
restore: |
snap unset system experimental.hidden-snap-folder
execute: |
# Checks that the env vars are as expected after the migration.
check_env() {
echo "Check the env vars were migrated"
local CHECK_EXPOSED_HOME="no"
if [ "$1" = "--with-exposed-home" ]; then
CHECK_EXPOSED_HOME="yes"
shift
fi
local REV="$1"
snapEnv=$("$NAME".env)
echo "$snapEnv" | MATCH "SNAP_USER_DATA=$HOME/\.snap/data/$NAME/$REV"
echo "$snapEnv" | MATCH "SNAP_USER_COMMON=$HOME/\.snap/data/$NAME/common"
if [ "$CHECK_EXPOSED_HOME" = "yes" ]; then
echo "Checking core22 migration related env vars"
echo "$snapEnv" | MATCH "HOME=$HOME/Snap/$NAME"
echo "$snapEnv" | MATCH "SNAP_USER_HOME=$HOME/Snap/$NAME"
echo "$snapEnv" | MATCH "XDG_DATA_HOME=$HOME/\.snap/data/$NAME/$REV/xdg-data"
echo "$snapEnv" | MATCH "XDG_CACHE_HOME=$HOME/\.snap/data/$NAME/$REV/xdg-cache"
echo "$snapEnv" | MATCH "XDG_CONFIG_HOME=$HOME/\.snap/data/$NAME/$REV/xdg-config"
else
echo "$snapEnv" | MATCH "HOME=$HOME/\.snap/data/$NAME/$REV"
fi
}
# Checks that the snap dirs are as expected after the migration.
check_dirs() {
echo "Check directories were migrated"
local CHECK_EXPOSED_HOME="no"
if [ "$1" = "--with-exposed-home" ]; then
CHECK_EXPOSED_HOME="yes"
shift
fi
local REV="$1"
test -d "$HOME/.snap/data/$NAME"
test -d "$HOME/.snap/data/$NAME/common"
test -d "$HOME/.snap/data/$NAME/$REV"
if [ "$(readlink "$HOME/.snap/data/$NAME/current")" != "$REV" ]; then
echo "expected 'current' to point to new revision after refresh"
exit 1
fi
not test -d "$HOME/snap/$NAME"
if [ "$CHECK_EXPOSED_HOME" = "yes" ]; then
echo "Checking core22 migration related dirs"
test -d "$HOME/Snap/$NAME"
test -d "$HOME/.snap/data/$NAME/$REV/xdg-data"
test -d "$HOME/.snap/data/$NAME/$REV/xdg-config"
test -d "$HOME/.snap/data/$NAME/$REV/xdg-cache"
fi
}
# Checks that there is a file named 'file' in the new dirs containing the
# expected data
check_data() {
echo "Check that the written data was migrated"
local CHECK_EXPOSED_HOME="no"
if [ "$1" = "--with-exposed-home" ]; then
CHECK_EXPOSED_HOME="yes"
shift
fi
local REV="$1"
local EXPECTED_DATA="$2"
MATCH "$EXPECTED_DATA" < "$HOME/.snap/data/$NAME/common/file"
MATCH "$EXPECTED_DATA" < "$HOME/.snap/data/$NAME/$REV/file"
if [ "$CHECK_EXPOSED_HOME" = "yes" ]; then
MATCH "$EXPECTED_DATA" < "$HOME/Snap/$NAME/file"
fi
}
echo "Set experimental hidden snap folder feature"
snap set system experimental.hidden-snap-folder=true
echo "Check that nothing has been migrated yet"
snapEnv=$("$NAME".env)
echo "$snapEnv" | MATCH "SNAP_USER_DATA=/root/snap/$NAME/x1"
echo "$snapEnv" | MATCH "SNAP_USER_COMMON=/root/snap/$NAME/common"
test -d "$HOME"/snap
not test -d "$HOME"/.snap/data
echo "Take a snapshot"
"$NAME".cmd echo "prev_data" > "$HOME/snap/$NAME/current/file"
# get the snapshot number from the 2nd line (the 1st line is the header)
snapshot=$(snap save "$NAME" | awk 'FNR == 2 {print $1}')
echo "Write data to user data dirs"
data="old_data"
"$NAME".echo "$data" > "$HOME/snap/$NAME/current/file"
"$NAME".echo "$data" > "$HOME/snap/$NAME/common/file"
echo "Refresh the snap"
"$TESTSTOOLS"/snaps-state install-local "$NAME"
# Check env vars, dirs and data after the migration
check_env x2
# Note: some dirs are created just before the snap runs for the 1st time,
# so this check must come after a snap run
check_dirs x2
check_data x2 "$data"
echo "Check the snap can write to the new dirs"
#shellcheck disable=SC2016
"$NAME".cmd sh -c 'echo "new_data" > "$SNAP_USER_DATA"/file'
#shellcheck disable=SC2016
"$NAME".cmd sh -c 'echo "new_data" > "$SNAP_USER_COMMON"/file'
check_data x2 new_data
echo "Restore snapshot and check data was restored"
snap restore "$snapshot"
MATCH "prev_data" < "$HOME/.snap/data/$NAME/x2/file"
echo "Check that snap starts off hidden after a fresh install"
snap remove --purge "$NAME"
"$TESTSTOOLS"/snaps-state install-local "$NAME"
check_env x1
check_dirs x1
data="new_data"
"$NAME".echo "$data" > "$HOME/.snap/data/$NAME/x1/file"
"$NAME".echo "$data" > "$HOME/.snap/data/$NAME/common/file"
check_data x1 "$data"
echo "Revert migration (unset flag and refresh)"
snap unset system experimental.hidden-snap-folder
"$TESTSTOOLS"/snaps-state install-local "$NAME"
echo "Check snap user data was moved back"
not test -d "$HOME"/.snap/data
test -d "$HOME/snap/$NAME"
MATCH "$data" < "$HOME/snap/$NAME/common/file"
MATCH "$data" < "$HOME/snap/$NAME/x2/file"
echo "Check environment variables were restored"
snapEnv=$("$NAME".env)
echo "$snapEnv" | MATCH "SNAP_USER_DATA=$HOME/snap/$NAME/x2"
echo "$snapEnv" | MATCH "SNAP_USER_COMMON=$HOME/snap/$NAME/common"
echo "$snapEnv" | MATCH "HOME=$HOME/snap/$NAME/x2"
data="old_data"
"$NAME".echo "$data" > "$HOME/snap/$NAME/x2/file"
"$NAME".echo "$data" > "$HOME/snap/$NAME/common/file"
# core22 snap isn't available for x86
if os.query is-pc-i386; then
exit 0
fi
# TODO:Snap-folder: no automatic migration for core22 snaps to
# ~/Snap folder for now
#
#echo "Update snap to core22"
## write a file in a default XDG dir so we can check it's migrated
#mkdir "$HOME/snap/$NAME/x2/.config"
#echo "conf-x2" > "$HOME/snap/$NAME/x2/.config/file"
#snap install --edge core22
#cp -rf "$TESTSLIB/snaps/$NAME" "$PWD/$NAME"
#echo -e "\nbase: core22" >> "$PWD/$NAME/meta/snap.yaml"
#snap pack "$PWD/$NAME"
#snap install --dangerous "$NAME"_1.0_all.snap
#check_env --with-exposed-home x3
#check_dirs --with-exposed-home x3
#check_data --with-exposed-home x3 "$data"
## the XDG dirs shouldn't be copied to the new HOME (they stay under the rev dir)
#not test -d "$HOME/Snap/$NAME/.config"
## check data in a default XDG dir was migrated
#MATCH "conf-x2" < "$HOME/.snap/data/$NAME/x3/xdg-config/file"
## write some new data so we can check it's still there after reverting back
##shellcheck disable=SC2016
#"$NAME".cmd sh -c 'echo "x3" > "$SNAP_USER_DATA"/file'
##shellcheck disable=SC2016
#"$NAME".cmd sh -c 'echo "x3" > "$SNAP_USER_COMMON"/file'
##shellcheck disable=SC2016
#"$NAME".cmd sh -c 'echo "x3" > "$HOME"/file'
#echo "Check that revert moves ~/.snap back and disables HOME migration"
#snap revert "$NAME"
#snapEnv=$("$NAME".env)
#echo "$snapEnv" | MATCH "SNAP_USER_DATA=$HOME/snap/$NAME/x2"
#echo "$snapEnv" | MATCH "SNAP_USER_COMMON=$HOME/snap/$NAME/common"
#echo "$snapEnv" | MATCH "HOME=$HOME/snap/$NAME/x2"
#MATCH "$data" < "$HOME/snap/$NAME/x2/file"
#test -d "$HOME/snap/$NAME/x2"
#test -d "$HOME/snap/$NAME/common"
#test -L "$HOME/snap/$NAME/current"
#not test -d "$HOME/.snap/data/$NAME"
#if [ "$(readlink "$HOME/snap/$NAME/current")" != "x2" ]; then
# echo "expected 'current' to be symlink to x2"
# exit 1
#fi
## the revision x3 data is still there
#test "$HOME/snap/$NAME/x3/file"
#test "$HOME/snap/$NAME/common/file"
#test "$HOME/Snap/$NAME/file"
#echo "Revert forward"
#snap revert "$NAME" --revision="x3"
## check everything is restored after reverting back to x3
#check_env --with-exposed-home x3
#check_dirs --with-exposed-home x3
#check_data --with-exposed-home x3 x3
## write something to the new XDG dirs so we can check that a refresh always
## re-initializes them from the default XDG (even if refreshing after a revert)
##shellcheck disable=SC2016
#"$NAME".cmd sh -c 'echo "x3" > "$SNAP_USER_DATA"/xdg-config/file'
##shellcheck disable=SC2016
#"$NAME".cmd sh -c 'echo "x3" > "$SNAP_USER_DATA"/xdg-data/file'
##shellcheck disable=SC2016
#"$NAME".cmd sh -c 'echo "x3" > "$SNAP_USER_DATA"/xdg-cache/file'
#echo "Check that revert w/ experimental flag set disable the ~/Snap migration"
#snap set system experimental.hidden-snap-folder=true
#snap revert "$NAME"
#snapEnv=$("$NAME".env)
#echo "$snapEnv" | MATCH "SNAP_USER_DATA=$HOME/.snap/data/$NAME/x2"
#echo "$snapEnv" | MATCH "SNAP_USER_COMMON=$HOME/.snap/data/$NAME/common"
#echo "$snapEnv" | MATCH "HOME=$HOME/.snap/data/$NAME/x2"
#MATCH "$data" < "$HOME/.snap/data/$NAME/x2/file"
#test -d "$HOME/.snap/data/$NAME/x2"
#test -d "$HOME/.snap/data/$NAME/common"
#test -L "$HOME/.snap/data/$NAME/current"
#test "$HOME/Snap/$NAME/file"
#not test -d "$HOME/snap/$NAME"
#if [ "$(readlink "$HOME/.snap/data/$NAME/current")" != "x2" ]; then
# echo "expected 'current' to be symlink to x2"
# exit 1
#fi
## when we refresh again, the new XDG dirs should be initialized (again) with
## this instead what's currently there ("x3")
#mkdir -p "$HOME/.snap/data/$NAME/x4/.config"
#echo "x4" > "$HOME/.snap/data/$NAME/x4/.config/file"
#mkdir -p "$HOME/.snap/data/$NAME/x4/.cache"
#echo "x4" > "$HOME/.snap/data/$NAME/x4/.cache/file"
#mkdir -p "$HOME/.snap/data/$NAME/x4/.local/share"
#echo "x4" > "$HOME/.snap/data/$NAME/x4/.local/share/file"
#rm -rf "$HOME/Snap/$NAME/*"
#echo "already_there" > "$HOME/Snap/$NAME/file"
#snap install --dangerous "$NAME"_1.0_all.snap
#check_env --with-exposed-home x4
#check_dirs --with-exposed-home x4
#MATCH "$data" < "$HOME/.snap/data/$NAME/x4/file"
## data under ~/Snap isn't rewritten
#MATCH "already_there" < "$HOME/Snap/$NAME/file"
## the config XDG dir was re-initialized w/ revision "x2"'s .config dir
#MATCH "conf-x2" < "$HOME/.snap/data/$NAME/x4/xdg-config/file"
## the other XDG dirs were re-created (x2 didn't have corresponding dirs)
#if [[ -n "$(ls -A "$HOME/.snap/data/$NAME/x4/xdg-cache")" ]]; then
# echo "expected xdg-cache dir to be empty but wasn't"
# exit 1
#fi
#if [[ -n "$(ls -A "$HOME/.snap/data/$NAME/x4/xdg-data")" ]]; then
# echo "expected xdg-data dir to be empty but wasn't"
# exit 1
#fi
#echo "Check migration after remove works"
## ensure dirs under ~/.snap/data are created
#"$NAME".cmd 'true'
#test -d "$HOME/.snap/data/$NAME"
#echo "Remove snap"
#snap remove --purge "$NAME"
## dir is leftover
#test -d "$HOME/.snap/data/$NAME"
#echo "Install snap with data under ~/snap"
#snap pack "$TESTSLIB/snaps/$NAME"
#snap unset system experimental.hidden-snap-folder
#"$TESTSTOOLS"/snaps-state install-local "$NAME"
## create dirs under ~/snap to be migrated
#"$NAME".cmd 'true'
#test -d "$HOME/snap/$NAME"
#echo "Migration to ~/.snap/data works"
#snap set system experimental.hidden-snap-folder=true
#"$TESTSTOOLS"/snaps-state install-local "$NAME"
#test -d "$HOME/.snap/data/$NAME"
#not test -e "$HOME/snap/$NAME"
#echo "Refresh from core22 base to another core22 base revision"
## reset everything
#snap unset system experimental.hidden-snap-folder
#snap remove --purge "$NAME"
#rm -rf ~/.snap ~/snap ~/Snap
#snap pack "$PWD/$NAME"
#snap install --dangerous "$NAME"_1.0_all.snap
#data="fresh"
##shellcheck disable=SC2016
#"$NAME".cmd sh -c 'echo fresh > "$SNAP_USER_DATA/file"'
##shellcheck disable=SC2016
#"$NAME".cmd sh -c 'echo fresh > "$SNAP_USER_COMMON/file"'
##shellcheck disable=SC2016
#"$NAME".cmd sh -c 'echo fresh > "$HOME/file"'
#snap install --dangerous "$NAME"_1.0_all.snap
#check_env --with-exposed-home x2
#check_dirs --with-exposed-home x2
#check_data --with-exposed-home x2 "$data"
#echo "Check fresh install of core22 based snap"
#snap remove --purge "$NAME"
#rm -rf "$HOME"/Snap "$HOME"/.snap/data "$HOME/snap/$NAME"
#snap install --dangerous "$NAME"_1.0_all.snap
#check_env --with-exposed-home x1
#check_dirs --with-exposed-home x1
#"$NAME".cmd sh -c 'true'
#echo "Check remove of freshly installed core22 based snap"
#snap remove --purge "$NAME"
#not test -e "$HOME/.snap/data/$NAME/x1"
#not test -e "$HOME/.snap/data/$NAME/common"
#echo "Now re-install"
#snap install --dangerous "$NAME"_1.0_all.snap
#"$NAME".cmd sh -c 'true'
#check_env --with-exposed-home x1
#check_dirs --with-exposed-home x1
|