Accessing files with python in flatpak

I have a code like this which works fine when running directly:

def on_button_clicked(button):
   button.filedialog.open(callback=on_filedialog_response)

def on_filedialog_response(filedialog, task):
   try:
       file = filedialog.open_finish(task)
   except GLib.GError:
       # gtk-dialog-error-quark: Dismissed by user
       pass
   else:
       print(file.get_uri())
       data = file.read()
       print(data)

But when I run it in flatpak, I can’t access the file. The output is:

file:///run/user/1000/doc/19c44102/gvimrc
Traceback (most recent call last):
  File "/app/lib/python3.11/site-packages/carburetor/handler.py", line 300, in on_filedialog_response
    data = file.read()
           ^^^^^^^^^^^
gi.repository.GLib.GError: g-io-error-quark: Error opening file /run/user/1000/doc/19c44102/gvimrc: No such file or directory (1)

Edited: Sorry, Emmanuele is right, I just miss the file path is under "
///run/user/1000"

You need permission to access the directory, this is done by adding some type of filesystem access permission to your application manifest, something like:

–filesystem=/path/path

No, you don’t need access permission for files in the document storage; that’s the whole point of the document and file selection portals.

Where is the original gvimrc file located?

That exact file is in /etc/vim/, but it really doesn’t matter where the file is located. I tried many files from different locations on different machines.

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