0

In my .spec file I create directory and touch a file in in during %post stage:

%post
mkdir -p %{sharedstatedir}/my_app
touch %{sharedstatedir}/my_app/my_app_file.txt

However during dnf upgrade my_app /var/lib/my_app and its contents are deleted and don't get re-created again. I think I could make %{sharedstatedir}/my_app and %{sharedstatedir}/my_app/my_app_file.txt part of the package, i.e. add them in %files section, but is there another way, just re-create the files in %post for example? I don't really care if contents of my_app_file.txt is lost, it serves as temporary storage.

0

1 Answer 1

0

You can add an empty file, declare that an installation object with the %config property, so that its content remains unchanged if it changed on disk before you'd do an update.

Honestly, though: Don't abuse the %config command or run code in %post to create mutable shared state files (which end up in /var/lib); my guess is that rpmlint will complain about what you intend to do, and it will notice it, at least when you use %config. A temporary file should be created by the software itself, when it's not there! So, just %file-create the directory %{sharedstatedir}/my_app, and patch the software to create the file if it's not there. Ideally, the path to the file should be configurable, so that admins can choose to put it e.g. on a faster or less reliable storage.

2
  • Declaring my_app/my_app_file.txt as %config is not what I need - this way it rather won't be deleted on uninstall, however I need it to be completely removed.
    – Mark
    Commented Aug 22, 2022 at 15:27
  • yeah, then see my "honestly, though" section. Commented Aug 22, 2022 at 15:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .