Shortcut on flatpak and a strange fact

HI. Thanks again for the help in the previous post. I have another question I would like to ask. I created a .flatpak file of my program. After installation, the icon for my program (LaMiaVideoteca) appears in the programs menu. If I launch it, it starts without being able to read the archive located in the same directory. Knowing that it works in a sandbox, doing various tests I realized that it is as if it were launched from the home/enrico folder. The strange thing is that I understood (not always) that by starting from the terminal with the command

flatpak run org.tarro.lamiavideoteca

the program started by reading the archive. However, this thing no longer happens now and I don’t understand why because I swear I haven’t changed anything. Having said that I tried to see if I could solve the problem by compiling the flatpak with the following command

flatpak-builder --installation=~/.local/share/flatpak/app build-dir org.tarro.lamiavideoteca.yml

I did this to see if by installing the program in another directory I had permissions (assuming the problem was due) to reading and writing in the archive;
I even tried changing the permissions with Flatseal), but it is not nothing changed. I also tried starting the application with this command

flatpak run --filesystem=/var/lib/flatpak/app/org.tarro.lamiavideoteca/current/active/files/bin org.tarro.lamiavideoteca

to see if instead of starting in /home/enrico it would start in the directory where the archive is located is that the application on a PC where I use Fedora 40 starts with the Gnome interface (app closing window) on the laptop where there is always Fedora 40 starts without a window as you can see in photo explanations.

By doing further tests I realized that the application opens with a complete archive if I launch it from the terminal using the flatpak run org.tarro.lamiavideoteca command and works well. However, if I try to launch it via the menu it doesn’t start. I configured the .desktop file that configures the menu shortcut like this:

[Desktop Entry]
Name=LaMiaVideoteca

Icon=org.tarro.lamiavideoteca.png

Type=Application
Categories=Office;

Exec=flatpak run org.tarro.lamiavideoteca
StartupNotify=false
Terminal=false

I tried changing the command
Exec=org.tarro.lamiavideoteca and to Exec=LaMiaVideoteca. But nothing starts. Among other things, through menulibre I realize that despite whatever I write in Exec there is actually the command /usr/bin/flatpak run --branch=stable --arch=x86_64 --command=org.tarro.lamiavideoteca org. tarro.lamiavideoteca. Which from the terminal gives me error: Invalid id run: Names must contain at least 2 periods. Trying to change the item Exec in menulibre still doesn’t start. It starts without seeing the archive only if I start it from Gnome-Software-Center.

The fact that by launching the flatpak run org.tarro.lamiavideoteca command the software reads the archive and the fact that it is able to write and delete data (I verified this) makes me understand that even if the software works in a sandbox I can read/ write inside the archive which is located in the same directory as the executable (I know that you shouldn’t keep the archive in the same directory as the executable, but for the moment I prefer to keep it that way). I remember that the directory in which the flatpak installs the application is /var/lib/flatpak/app/

It can’t. The whole /app folder is read-only. If this is possible then it would be a bug you can’t rely on.

Given your screenshots: If you run the application from within your build folder, I suspect your application uses the database from the build folder since flatpak will keep your current working directory.

Run from any other location or without any filesystem permissions (flatpak run --sandbox or with --nofilesystem=host) and it doesn’t work anymore. This is happening when running from the desktop file.


Your application must use or create a file in a user writeable folder, preferably in XDG_DATA_HOME (XDG Base Directory Specification, XDG Base Directory - ArchWiki, Qt probably provides a method for this). Inside this you create your own subfolder to put your user files in.


If your application doesn’t require any other files you can then drop all filesystem permissions since the base directories are always available & writeable.

Even if you need access to some files you should check to implement the file portal: XDG Desktop Portal documentation .
This allows you to drop all filesystem permissions but still get access to files (as granted by the user).

Now I’m looking for a command when compiling the flatpak to make the program install in ~/.local/share when it’s installed.

I tryed put on .yml file this: `

  "build-options": {
    "install-dir": "XDG_DATA_HOME"

but not works

`

it’s not like install-dir is mentionned anywhere in the documentation as something usefull.

One doesn’t just invent something expecting it to work.

This doesn’t exist. If your software package require something there it should either be putting it there by itself, or be fixed to not require it.

From what I know it is possible to install the apps in ~/.local/share/flatpak as this folder is used to install single-user flatpaks. I’m convinced that I just need to modify the code of the .yml file…

id: org.tarro.lamiavideoteca
runtime: org.kde.Platform 
runtime-version: '6.6' 
sdk: org.kde.Sdk 
command: LaMiaVideoteca 
modules: 
  - name: LaMiaVideoteca 
    buildsystem: simple 
    
    sources: 
      - type: file 
        path: LaMiaVideoteca 
      - type: file 
        path: BluRay4KUHD 
      - type: file 
        path: BluRayDisc 
      - type: file 
        path: 'BluRayHD&UHD' 
      - type: file 
        path: 'DVD&BluRayDisc' 
      - type: file 
        path: DVDVideo 
      - type: file 
        path: LaMiaVideoteca.ico 
      - type: file 
        path: rimuoviimmagine.png 
      - type: file 
        path: VHS 
      - type: file 
        path: lamiavideoteca.db 
      - type: dir
        path: /home/enrico/MEGA/Informatica/Programmazione/C/Qt Creator/Linux/LaMiaVideoteca/Setup/Release 2.45/FLATPAK/lamiavideoteca
        
               
    build-commands: 
      - mkdir /app/lib
      - mkdir /app/share
      - mkdir /app/bin
      - mkdir /app/bin/Copertine
      - install -D LaMiaVideoteca /app/bin/LaMiaVideoteca 
      - install -T BluRay4KUHD /app/bin/BluRay4KUHD 
      - install -T BluRayDisc /app/bin/BluRayDisc 
      - install -T 'BluRayHD&UHD' /app/bin/'BluRayHD&UHD' 
      - install -T 'DVD&BluRayDisc' /app/bin/'DVD&BluRayDisc' 
      - install -T DVDVideo /app/bin/DVDVideo 
      - install -T LaMiaVideoteca.ico /app/bin/LaMiaVideoteca.ico 
      - install -T rimuoviimmagine.png /app/bin/rimuoviimmagine.png 
      - install -T VHS /app/bin/VHS 
      - install -T lamiavideoteca.db /app/bin/lamiavideoteca.db 
      - cp -r lib/* /app/lib
      - cp -r share/* /app/share
      - cp -r Copertine/* /app/bin/Copertine
        
             
finish-args:
  # X11 + XShm access
  - --share=ipc
  - --socket=x11
  - --socket=fallback-x11
  # Wayland access
  - --socket=wayland
  # GPU acceleration if needed
  - --device=dri
  # Needs to save files locally
  - --filesystem=home

If you know what. I thank everyone in advance.

Not exactly. The user can decide to install it with --user into XDG_DATA_DIR/flatpak, that’s true. But this only changes the installation location of the files on the system.

The application is still run inside its sandbox with all files located in the read-only folder /app. That’s not something you can change. The flatpak will always only consist of files you put into /app & you can’t modify these files.

That’s actually not flatpak specific, read-only access to the files is the standard for basically all packaging formats (deb, rpm, AppImage etc.). Isn’t this even the case on modern Windows when installing into C:\Program Files?

No, I’ve never had this kind of problem. Through innosetup however, you could easily choose the default directory and allow the user to change it. I always chose as the default directory: C:/Users/(user)/AppData/Local/Programs. I’m sure there must be a way. However even if flatpaks work in a sandbox it should be possible to access a sqlite archive in the same directory. Furthermore, I have already packaged the same application via AppImage and .deb and I had no problems.

Ok… I understood why the archive was being read to me from the terminal. In practice, if I give the command from the terminal (flatpak run org.tarro.lamiavideoteca) from a directory in which an archive is located, then the program searches in the directory in which the command was given from the terminal. I tried launching the program from the directory where the program is installed (var/lib/flatpak/app/org.tarro.lamiavideoteca) and I actually can’t modify the archive. From all this I deduce that I must necessarily modify the source code of the program and choose a fixed directory in which to put the archive and the editable files, then be able to install during the installation of the flatpak in a directory under /home in which the program with full read and write access. Furthermore, if I try to start the program from the /home/user/.local/share/flatpak/app directory, the program will look for the archive in the /home/user folder and not in /home/user/.local/share/flatpak /app. (clearly user is the user’s name).

So I asked myself what is the folder used (in flatpaks) to contain the editable files (like an archive) of the program? Searching online I discovered that it is ~/.var/app. After modifying the source code I have to try to put these files in the ~/.var/app/org.tarro.lamiavideoteca directory (directory that is created automatically when you launch the application after installing it via flatpak) . First I told: “Furthermore, I have already packaged the same application via AppImage and .deb and I had no problems.” Now that I remember, however, I had placed the archive in a folder under /home/user. So it is obvious that I could access the program files without any problems.

So I changed the executable code so that the application reads the archive and the necessary files in the ~/.var/app/org.tarro.lamiavideoteca/data directory. The .yml is:

    build-commands: 
      - mkdir /app/lib
      - mkdir /app/share
      - mkdir /app/bin
      - mkdir -p ~/.var/app/org.tarro.lamiavideoteca/data/Copertine/'Supporto Cassetta'
      - mkdir -p ~/.var/app/org.tarro.lamiavideoteca/data/Copertine/'Supporto Disco'
      - install -D LaMiaVideoteca /app/bin/LaMiaVideoteca 
      - install -D BluRay4KUHD ~/.var/app/org.tarro.lamiavideoteca/data/BluRay4KUHD 
      - install -D BluRayDisc ~/.var/app/org.tarro.lamiavideoteca/data/BluRayDisc 
      - install -D 'BluRayHD&UHD' ~/.var/app/org.tarro.lamiavideoteca/data/'BluRayHD&UHD' 
      - install -D 'DVD&BluRayDisc' ~/.var/app/org.tarro.lamiavideoteca/data/'DVD&BluRayDisc' 
      - install -D DVDVideo ~/.var/app/org.tarro.lamiavideoteca/data/DVDVideo 
      - install -D LaMiaVideoteca.ico ~/.var/app/org.tarro.lamiavideoteca/data/LaMiaVideoteca.ico 
      - install -D rimuoviimmagine.png ~/.var/app/org.tarro.lamiavideoteca/data/rimuoviimmagine.png 
      - install -D VHS /~/.var/app/org.tarro.lamiavideoteca/data/VHS 
      - install -C -D  lamiavideoteca.db ~/.var/app/org.tarro.lamiavideoteca/data/lamiavideoteca.db 
      - cp -r lib/* /app/lib
      - cp -r share/* /app/share
      - install -C -D Copertine/'Supporto Cassetta'/1 ~/.var/app/org.tarro.lamiavideoteca/data/Copertine/'Supporto Cassetta'/1
      - install -C -D Copertine/'Supporto Cassetta'/2 ~/.var/app/org.tarro.lamiavideoteca/data/Copertine/'Supporto Cassetta'/2
      - install -C -D Copertine/'Supporto Cassetta'/3 ~/.var/app/org.tarro.lamiavideoteca/data/Copertine/'Supporto Cassetta'/3
      - install -C -D Copertine/'Supporto Cassetta'/'Nessuna Immagine Disponibile' ~/.var/app/org.tarro.lamiavideoteca/data/Copertine/'Supporto Cassetta'/'Nessuna Immagine Disponibile'
      - install -C -D Copertine/'Supporto Disco'/1 ~/.var/app/org.tarro.lamiavideoteca/data/Copertine/'Supporto Disco'/1
      - install -C -D Copertine/'Supporto Disco'/2 ~/.var/app/org.tarro.lamiavideoteca/data/Copertine/'Supporto Disco'/2
      - install -C -D Copertine/'Supporto Disco'/3 ~/.var/app/org.tarro.lamiavideoteca/data/Copertine/'Supporto Disco'/3
      - install -C -D Copertine/'Supporto Disco'/'Nessuna Immagine Disponibile' ~/.var/app/org.tarro.lamiavideoteca/data/Copertine/'Supporto Disco'/'Nessuna Immagine Disponibile'

I compile and create the .flatpak file but when I install it the files that need to be installed in the ~/.var/app/org.tarro.lamiavideoteca/data directory are not put. The .flatpak file actually weighs a bit less, so I imagine they won’t be included. Any idea?

This was already answered, it’s not possible. You have to handle this when running your application.

And as was said: Prefer XDG_DATA_HOME (don’t forget the fallback/default location as documented). This will be set to ~/.var/app/org.tarro.lamiavideoteca/data in the sandbox. There should be an Qt-API for this which will work for all operating systems.

Now I’m trying to copy the files after the installation is finished through a script. The problem is that it doesn’t start.

id: org.tarro.lamiavideoteca
runtime: org.kde.Platform 
runtime-version: '6.6' 
sdk: org.kde.Sdk 
command: LaMiaVideoteca 
modules: 
  - name: LaMiaVideoteca 
    buildsystem: simple 
    
    sources: 
      - type: file 
        path: LaMiaVideoteca 
      - type: file 
        path: BluRay4KUHD 
      - type: file 
        path: BluRayDisc 
      - type: file 
        path: 'BluRayHD&UHD' 
      - type: file 
        path: 'DVD&BluRayDisc' 
      - type: file 
        path: DVDVideo 
      - type: file 
        path: LaMiaVideoteca.ico 
      - type: file 
        path: rimuoviimmagine.png 
      - type: file 
        path: VHS 
      - type: file 
        path: lamiavideoteca.db 
      - type: dir
        path: /home/enrico/MEGA/Informatica/Programmazione/C/Qt Creator/Linux/LaMiaVideoteca/Setup/Release 2.45/FLATPAK/lamiavideoteca
        
               
    build-commands: 
      - mkdir /app/lib
      - mkdir /app/share
      - mkdir /app/bin
      - mkdir /app/data
      - mkdir /app/data/Copertine
      - install -D LaMiaVideoteca /app/bin/LaMiaVideoteca 
      - install -D BluRay4KUHD /app/data/BluRay4KUHD 
      - install -D BluRayDisc /app/data/BluRayDisc 
      - install -D 'BluRayHD&UHD' /app/data/'BluRayHD&UHD' 
      - install -D 'DVD&BluRayDisc' /app/data/'DVD&BluRayDisc' 
      - install -D DVDVideo /app/data/DVDVideo 
      - install -D LaMiaVideoteca.ico /app/data/LaMiaVideoteca.ico 
      - install -D rimuoviimmagine.png /app/data/rimuoviimmagine.png 
      - install -D VHS /app/data/VHS 
      - install -D lamiavideoteca.db /app/data/lamiavideoteca.db 
      - cp -r lib/* /app/lib
      - cp -r share/* /app/share
      - cp -rn Copertine/* /app/data/Copertine
        
             
finish-args:
  # X11 + XShm access
  - --share=ipc
  - --socket=x11
  - --socket=fallback-x11
  # Wayland access
  - --socket=wayland
  # GPU acceleration if needed
  - --device=dri
  # Needs to save files locally 
  - --filesystem=host
  - --filesystem=home
  
    
scripts:
    post-installation:
        - mkdir -p ~/.var/app/org.tarro.lamiavideoteca/data
        - cp -rn /var/lib/flatpak/app/org.tarro.lamiavideoteca/current/active/files/data/ ~/.var/app/org.tarro.lamiavideoteca/


Now I tried to create a script and run it after the installation is complete. But even though the script works and has permission to run, it is not launched

id: org.tarro.lamiavideoteca
runtime: org.kde.Platform 
runtime-version: '6.6' 
sdk: org.kde.Sdk 
command: LaMiaVideoteca 
modules: 
  - name: LaMiaVideoteca 
    buildsystem: simple 
    
    sources: 
      - type: file 
        path: LaMiaVideoteca 
      - type: file 
        path: BluRay4KUHD 
      - type: file 
        path: BluRayDisc 
      - type: file 
        path: 'BluRayHD&UHD' 
      - type: file 
        path: 'DVD&BluRayDisc' 
      - type: file 
        path: DVDVideo 
      - type: file 
        path: LaMiaVideoteca.ico 
      - type: file 
        path: rimuoviimmagine.png 
      - type: file 
        path: VHS 
      - type: file 
        path: lamiavideoteca.db 
      - type: script 
        path: post-install.sh
      - type: dir
        path: /home/enrico/MEGA/Informatica/Programmazione/C/Qt Creator/Linux/LaMiaVideoteca/Setup/Release 2.45/FLATPAK/lamiavideoteca
        
               
    build-commands: 
      - mkdir /app/lib
      - mkdir /app/share
      - mkdir /app/bin
      - mkdir /app/data
      - mkdir /app/data/Copertine
      - install -D LaMiaVideoteca /app/bin/LaMiaVideoteca 
      - install -D BluRay4KUHD /app/data/BluRay4KUHD 
      - install -D BluRayDisc /app/data/BluRayDisc 
      - install -D 'BluRayHD&UHD' /app/data/'BluRayHD&UHD' 
      - install -D 'DVD&BluRayDisc' /app/data/'DVD&BluRayDisc' 
      - install -D DVDVideo /app/data/DVDVideo 
      - install -D LaMiaVideoteca.ico /app/data/LaMiaVideoteca.ico 
      - install -D rimuoviimmagine.png /app/data/rimuoviimmagine.png 
      - install -D VHS /app/data/VHS 
      - install -D lamiavideoteca.db /app/data/lamiavideoteca.db 
      - install -D post-install.sh /app/data/post-install.sh 
      - cp -r lib/* /app/lib
      - cp -r share/* /app/share
      - cp -rn Copertine/* /app/data/Copertine
        
             
finish-args:
  # X11 + XShm access
  - --share=ipc
  - --socket=x11
  - --socket=fallback-x11
  # Wayland access
  - --socket=wayland
  # GPU acceleration if needed
  - --device=dri
  # Needs to save files locally
  - --filesystem=host
  - --filesystem=home
  # Script di post-installazione 
  - post-install: post-install.sh
override-cmd: /post-install.sh

what override-cmd and which part of the documentation talks about it. I’m trying to figure why you all put random things expecting them to work…