linuxwindowsoperating-systemfilesystems

What is the best way to prevent application user from messing with application files?


Let's say there is an app that just creates directories in ~/home/app directory.
The app also, for example, stores in ~/home/app meta.json related to directories it has created. As a developer a want make it difficult for user to delete folders or edit meta.json so these can be changed only via app.

How can I create some "container" directory, that acts for user as "unknown file", but can be easily "mounted" by app as a directory?

e.g. there is *.kra files(created by Krita) which I can open with zip, despite it is not an archive, or like Appimage files that can be read as a directory.
What is mechanism behind that? How i create folder that acts like file? How I create some file like blob.myapp that just a bundle of files and directories.


Solution

  • AppImages are self-extracting binaries with a squashfs file system appended to them. The file system is privately mounted using FUSE, so only the program and its children can see the contents of the mounted directory. On the other hand, Krita files are just ZIP files with a different extension.

    You could try AppImage's approach and use FUSE to mount an archive (e.g. using archivemount), but that would only work on Linux.

    Alternatively, you could do it like Krita and store the data in an archive. When your program starts, you read the archive and keep everything in RAM. When your program finishes (or periodically to avoid data loss), you store the data back into the archive.

    In practice, all of that is more trouble that it's worth. Instead, most applications just store the data in the proper places[1], which are normally hidden from the user anyway. If the user messes with the files, that's on them.


    [1] User data is usually stored in %localappdata% on Windows or in $XDG_CONFIG_HOME / $XDG_DATA_HOME / $XDG_STATE_HOME on Linux (depending on the kind of data -- avoid using the user's home dir directory).