Desktop-launch causes "failed to create symbolic link"

Hi All,

Sometime recently, I think after snapcraft 2.28, the desktop-launch
script had the following code added:

# GTK theme and behavior modifier
# Those can impact the theme engine used by Qt as well
gtk_configs=(.config/gtk-3.0/settings.ini .config/gtk-3.0/bookmarks .config/gtk-2.0/gtkfilechooser.ini)
for f in ${gtk_configs[@]}; do
  dest="$SNAP_USER_DATA/$f"
  mkdir -p `dirname $dest`
  ln -s /home/$USER/$f $dest
done

The code blindly attempts to create the symbolic links, which means that
after the first time the application is run error messages similar to:

ln: failed to create symbolic link ‘/home/alistair/snap/pharo/x1/.config/gtk-3.0/settings.ini’: File exists
ln: failed to create symbolic link ‘/home/alistair/snap/pharo/x1/.config/gtk-3.0/bookmarks’: File exists
ln: failed to create symbolic link ‘/home/alistair/snap/pharo/x1/.config/gtk-2.0/gtkfilechooser.ini’: File exists

appear each time the application is started.

I’m a bit surprised that no one else has reported this, so was wondering
if I’m doing something unusual.

Can someone either confirm the issue, or suggest what I might be doing
wrong?

The problem occurs with both snapcraft 2.29 and 2.30 (on Ubuntu 16.04).

Thanks,
Alistair

@didrocks ping, this sound like you ^

Thanks, elopio.

I should add that this is a glib-only application, i.e.

parts:
  pharo:
    source: ./
    plugin: make
    after:
        - desktop-glib-only

Thanks again,
Alistair

I just pushed a fix for this. I didn’t caught it despite my trials, but anyway, protecting them should work, keep me posted!

Btw: you should only have that part executed on snap upgrade (first time you launch after installing a new version). The whole logic is skipped once you launched it once and don’t upgrade again. (or it means, the script is failing, which we can debug).

Thanks @akgrant! At least, I know now that we have at least one consumer of glib-only (I was wondering about this).

1 Like

Thanks for the fast response, @didrocks!

Can I get access to the patch early, or do I need to wait for the next release (2.31?)?

Thanks again,
Alistair

No need to wait, just rebuild your snap and you should get the new launcher :slight_smile:

1 Like

That’s cool, I’m getting the updated version, thanks!

You’ve implemented it as:

for f in ${gtk_configs[@]}; do
  dest="$SNAP_USER_DATA/$f"
  mkdir -p `dirname $dest`
  if [ ! -e $dest ]; then
    ln -s /home/$USER/$f $dest
  fi
done

The limitation with this is that it fails if the symbolic link is broken (which I have, I don’t know how). I think a safer version is:

for f in ${gtk_configs[@]}; do
  dest="$SNAP_USER_DATA/$f"
  if [ ! -L "$dest" ]
  then
    mkdir -p `dirname $dest`
    ln -s /home/$USER/$f $dest
  fi
done

(the important bit being the “-L” test instead of “-e”)

What do you think?

Thanks,
Alistair

1 Like

AHHHHHHHHHHHHH, I get it now! The issue is that the unity7 interface with my changes are not available to you yet (to get access to that file) So, yeah, -L should make sense!

Want to do a PR on https://github.com/ubuntu/snapcraft-desktop-helpers? The file to change is at https://github.com/ubuntu/snapcraft-desktop-helpers/blob/master/common/desktop-exports#L183.

If you don’t have the time, I can just push it right away. Thanks! :slight_smile:

1 Like

Done:

https://github.com/ubuntu/snapcraft-desktop-helpers/pull/64

Thanks!
Alistair

1 Like

And merged, thanks to you :slight_smile:

Lovely, thanks @akgrant and @didrocks!