How to copy files in $HOME/.var/app/org.flatpak.AppName/data/custom/directory?

Oct 11, 2022
P

Hello,
here is my current manifest

{
    "app-id": "org.flatpak.AppName",
    "runtime": "org.kde.Platform",
    "runtime-version": "5.15-21.08",
    "sdk": "org.kde.Sdk",
    "base": "io.qt.qtwebengine.BaseApp",
    "base-version": "5.15-21.08",
    "command": "AppName",
    "finish-args": [
        "--share=ipc",
        "--share=network",
        "--socket=fallback-x11",
        "--socket=wayland",
        "--filesystem=host",
        "--device=dri",
	"--env=QTWEBENGINEPROCESS_PATH=/app/bin/QtWebEngineProcess"
    ],
    "cleanup-commands": [
	"/app/cleanup-BaseApp.sh"
    ],
    "modules": [
        {
            "name": "AppName",
            "buildsystem": "cmake",
            "builddir": true,
            "config-opts": [
	        "-DCMAKE_BUILD_TYPE=RelWithDebInfo",
	        "-DFLATPAK=ON"
	    ],
            "sources": [
                {
                    "type": "dir",
                    "path": "../"
                }
	    ],    
	    "post-install": [
                "install -p -D -m 0644 ../config/config.ini -t ${FLATPAK_DEST}/data/custom/directory/"
	    ]
	}
    ]
}

In CMakeLists.txt, I have written this

if(FLATPAK)
    install(FILES ${PROJECT_SOURCE_DIR}/config/config.ini DESTINATION ${CMAKE_INSTALL_PREFIX}/data/custom/directory/)
endif()

Doing so, I would expect that config.ini is copied in $HOME/.var/app/org.flatpak.AppName/data/custom/directory but it is not.

I have created a bundle with these commands:

flatpak-builder build-dir org.flatpak.AppName
flatpak-builder --user --install --subject="Build of AppName software `date`" --force-clean build-dir org.flatpak.AppName
flatpak-builder --repo=repo --force-clean build-dir org.flatpak.AppName
flatpak build-bundle repo/ AppName.flatpak org.flatpak.AppName

When I install the bundle, config.ini is copied in $HOME/.local/share/flatpak/app/org.flatpak.AppName/x86_64/master/ee3755700b7b6209c1df9046af78c3c61ce1c39b2d009d6c8c870a2c6fd2905a/files/data/custom/directory/ while I want it to be in $HOME/.var/app/org.flatpak.AppName/data/custom/directory/.

I’m going round in circles, so thanks in advance to those who have an idea of what’s wrong.

H

Given the build is run on builder, what do you expect happens by copying files into $HOME?

My guess, not what you think it does.

P
Replying to #2

Indeed, it does not do what I want it to do.

What I understand from your reply is I should not put these lines in CMakeLists.txt and manage copy only in the manifest, right? If so, what should I write in the manifest?

H
Replying to #3

No. In neither case. There is no difference. Actually there is one. With flatpak it will fail on our machine as well.

P
Replying to #4

Ouch, I am lost. So probably I am not looking for the good direction. The question is how can I copy data in HOME/.var/app/org.flatpak.AppName/data/custom/directory? What should I write and where?

H
Replying to #5

You can’t do that anywhere in the build process. If you app expect this then your app is broken by design.

P
Replying to #6

Hmmm, actually I use Qt and its QStandardPaths class (QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)) to set directory. As far as I understand, it uses XDG standard.
So when I do not use Flatpak, my file is located in $HOME/.local/share/AppName. It works well.

Now I understood that I cannot write in $HOME/.local/share with Flatpak so I thought Flatpak could write into $HOME/.var/app/org.flatpak.AppName.

But you are telling me that it is not possible…

H
Replying to #7

At runtime there is nothing to do, Qt will deal with it properly.

But all your question was about build time (CMake or flatpak manifest). If you application requires a file to be installed there, it’s broken. It’s not even flatpak specific.

P
Replying to #8

A few words on how my app works.

When it starts, it reads a configuration file that is located in $HOME/.local/share/AppName. The application needs this configuration file to work properly. So my idea was to include this configuration file in the flatpak package so that the application can use it.

I think is very common to do so, so I would like to know how to do it with Flatpak.

H
Replying to #9

no it’s not. It’s a bug. Again it’s not even a flatpak issue.

P
Replying to #10

I am really surprised. How would you design an application that needs to read a configuration file at startup?

I am thinking that my configuration file is actually very similar to an icon image. A lot of software needs to load an image to then display it as an icon. So, the icon image is packed with Flatpak.

H
Replying to #11

icons don’t get installed in the user home directory either.

P
Replying to #12

So the question becomes, where icons are installed and is it possible to set a custom directory for the icons location?