Skip to content

Commit

Permalink
Snaps: Fix symlinked XDG_SPECIAL_DIRS in HOME
Browse files Browse the repository at this point in the history
When a user has one or several `XDG_SPECIAL_DIRS` folders symlinked in
their real home folder to elsewhere in their real home folder
`desktop-common.sh` will attempt to mv those folders to themselves.
Because we are executing this script with `bash -e`, this prevents any
Snap with the `home` interface built with these scripts from launching
when the user has moved any of their Documents, Pictures, Music, etc.
and replaced with a symlink.

* guard `mv` calls with test for `is_subpath` to ensure that we're only
  moving symlinks we created.

See related PRs on Snapcraft-desktop-helpers and Snapcraft:

* ubuntu/snapcraft-desktop-helpers#220
* canonical/snapcraft#3435

Signed-off-by: Daniel Llewellyn <diddledan@ubuntu.com>
  • Loading branch information
Daniel Llewellyn committed Feb 9, 2021
1 parent a465281 commit 68ce583
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/package-format/snap/desktop-scripts/desktop-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ else
for ((i = 0; i < ${#XDG_SPECIAL_DIRS[@]}; i++)); do
old="${XDG_SPECIAL_DIRS_INITIAL_PATHS[$i]}"
new="${XDG_SPECIAL_DIRS_PATHS[$i]}"
if [ -L "$old" ] && [ -d "$new" ] && [ "$(readlink "$old")" != "$new" ]; then
if [ -L "$old" ] && [ -d "$new" ] && [ "$(readlink "$old")" != "$new" ] &&
(is_subpath "$old" "$SNAP_USER_DATA" || is_subpath "$old" "$SNAP_USER_COMMON"); then
mv -vn "$old"/* "$new"/ 2>/dev/null
elif [ -d "$old" ] && [ -d "$new" ] && [ "$old" != "$new" ] &&
(is_subpath "$old" "$SNAP_USER_DATA" || is_subpath "$old" "$SNAP_USER_COMMON"); then
Expand Down

0 comments on commit 68ce583

Please sign in to comment.