9

I deliver an application via an RPM.

This application delivers various directories and files.
E.g. under /opt/internal/com
a file structure is being copied.

I was expecting that on rpm -e all the file structure delivered under /opt/internal/com will be removed.
But it does not.
There are directories in the file structure that are non-empty.

Is this the reason? But these (non-empty) directories were created by the RPM installation. So I would expect that they would be "owned" by RPM and removed automatically.

Is this wrong? Am I supposed to remove them manually?

2 Answers 2

8

RPM won't delete any files it doesn't know about, so if new files have been created in a directory that are not part of a package, RPM won't remove them, or the directories.

It will delete the directories if they are empty and it knows about them. It depends how the spec file was written.

13
  • 1
    Will it delete directories that are NOT empty and DOES know about them? (the rpm delivered them)
    – Jim
    Apr 6, 2012 at 11:05
  • It depends how the spec file was written. Do you mean I should have removed them in a %postun section?
    – Jim
    Apr 6, 2012 at 11:11
  • 1
    Jim, James is saying that it wont remove directories that are non-empty because they contain files it is not aware of. If you feel that you need to remove these directories during uninstall a %postun is appropriate, but know that this is how most RPMs work.
    – Kyle Smith
    Apr 6, 2012 at 11:14
  • @Jim You could use a %postun to rm -rf the directories, but ordinarily RPM doesn't do this because it's not safe to do so. You might lose data that you didn't intend to just because you removed a package (e.g. config file modifications). Apr 6, 2012 at 11:28
  • 1
    @Jim Was foo/bar/stuff/file1.txt installed by the RPM and specified in %files? If so, rpm -e will remove is as long as it has not been modified. If it wasn't installed by the RPM, then it will not be removed. Apr 6, 2012 at 13:01
3

Answer from James O'Gorman is absolutely right.

One more scenario to add, which I recently encountered, is you need to tell directories owned by RPM package in %files section with a line "%dir /dir/path", so that it will remember all files and directories in RPM database when installed and can be removed (unless contents of the dir not own by that package) during RPM erase.

More care should be taken while specifying owned directories as there is different methods to process RPM erase on different distros.

e.g. if your package contains following files & directories:

**DIR:** /opt/dir1/empty_dir **FILE:** /opt/dir1/file1 **FILE:** /opt/dir1/dir2/file2

then your %files section should look like

%files
%dir /opt/dir1
%dir /opt/dir1/empty_dir
%dir /opt/dir1/dir2
/opt/dir1/file1
/opt/dir1/dir2/file2

Tricky part is, you might miss %dir /opt/dir1 and it won't be removed even if it is empty on some distros.

1
  • This is not correct. "...if a directory is specified in the %files list, the contents of that directory, and the contents of every directory under it, will automatically be included in the package." See the %dir section in this rpm.org doc
    – CivFan
    Jun 23, 2016 at 19:36

You must log in to answer this question.

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