Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
    
Will it delete directories that are NOT empty and DOES know about them? (the rpm delivered them) –  Jim Apr 6 '12 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 '12 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 '12 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). –  James O'Gorman Apr 6 '12 at 11:28
    
So basically if my rpm spec has in the %files section the hierarchy /opt/internal/com and it delivers that hierarchy, on uninstall it will nor remove everything under com if there are other files dirs even if it delivered them? It delivers them recursively from /opt/internal/com but knows only about /opt/internal/com and not the containing files/folders? –  Jim Apr 6 '12 at 11:34

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.