[BUG] Desktop Export fails in Flatpak when file extension is not provided by user

To reproduce:

  • Install Flatpak
  • flatpak install net.ankiweb.Anki
  • flatpak run net.ankiweb.Anki
  • Create a deck with a card with the Anki UI
  • Export the deck to a text file (UI option “notes in plain text”)
  • In the file chooser, change your target directory from the default (e.g. /run/user/1000/doc/25baf4eb) to something normal (e.g. /home/jrpear)
  • In the file chooser, name the file something without the right extension (e.g. my-deck not my-deck.txt)
  • Save the file

Expected Behavior:

  • There is a new file in the target directory (/home/jrpear)

Actual Behavior:

  • There is no new file in the target directory (/home/jrpear)
  • There is no new file in the initially suggested directory (/run/user/1000/doc/25baf4eb)
  • In the net.ankiweb.Anki namespace, there is a new file in a different directory (/run/user/1000/doc/10c4db7e); that file has the right extension (/run/user/1000/doc/10c4db7e/my-deck.txt)
  • See this with flatpak enter net.ankiweb.Anki find /run -name '*my-deck*'

Other notes:

  • That second directory /run/user/1000/doc/10c4db7e is the new suggested directory next time you try to export. But if you again don’t type out the file extension in the file chooser, the file wont be placed there to be transported to the host. Instead it’s placed in some other directory only visible in the Anki namespace, which will in turn be suggested to the user on the next export.
  • I think I’ve stressed this enough, but this only happens when the extension isn’t typed out. If the user specifies a file name that already has the right extension, everything works perfectly.
  • If you try to save in the suggested directory, Anki hangs and doesn’t respond to a SIGTERM. The suggested directory should probably be fixed too.

My system

I’m running Debian unstable, with GNOME 43.1 (Wayland). Flatpak version 1.14.1. Anki version 2.1.56.

Report in Issues · flathub/net.ankiweb.Anki · GitHub (check if there is a issue to avoid duplicates)

You are welcome to continue using your distro’s version of Anki if you prefer, but if you run into any issues, you will need to report them to your distribution’s package maintainers.
Linux Distro Packages - Anki Manual


I’ve looked into this more, and it seems that the Flatpak xdg-desktop-portal doesn’t allow renames. You must write to the file that the user specifies. I can’t find this said explicitly anywhere, but the docs on the SaveFile interface seem to suggest that that’s the case: Portal API Reference — Flatpak documentation.

IMO the best solution is to check whether Anki is in a sandbox and skip the rename here if so.

It seems that the Flatpak currently just uses the official binary, so they couldn’t maintain an Anki fork to keep this change out of upstream.

1 Like

If they propose a clean PR, I’d be happy to consider it.

1 Like

I’ve found how Qt checks whether it’s in a Flatpak: look for a file in $XDG_RUNTIME_DIR called flatpak-info qibusplatforminputcontext.cpp\ibus\platforminputcontexts\plugins\src - qt/qtbase.git - Qt Base (Core, Gui, Widgets, Network, ...). Pretty straightforward, I’m happy to write up a PR for that.

Done: Fix silent file save failures and bad default save path in Flatpak by jrpear · Pull Request #2427 · ankitects/anki · GitHub

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.