Issue
My deb file installs to /opt/myCompany/myProgram, when I purge the package with dpkg -P myProgram everything is removed - even /opt (if mine is the only package with files in /opt) - How can I avoid removing the /opt folder during a purge?
I have tried checking if /opt exist in the postrm and adding it if it doesn't but no joy...It seems that the folder is deleted after the postrm script is run. Currently I am adding a hidden file in /opt with postinst - this stops opt from being removed but feels hackey - there should be a better way.
Thank you,
Solution
That's just debian. Whenever it removes a package from a non-debian standard directory (such as /opt
in your case) and there are no files left in that directory, dpkg
will try to remove that directory.
If there are some other files in /opt
at the time of removal, you'll get a message in the lines of "/opt is not empty; not removed" and that's it.
Another "hacky" way would be to add re-creation of /opt in postrm
, but it's not way cleaner than your hidden file :)
Answered By - favoretti