Issue
I have a spec file that needs to check if an older version of a file exists and if so delete it. For some reason, it is running the delete command regardless of whether the file exists and printing a "no such file or directory" error, which leads me to believe my if statement checking if the file exists is at fault. Here is my code.
if [ -e "/foo/bar/file.zip" ]; then
rm -rf /foo/bar/file.zip
fi
Any help is appreciated.
Solution
That rm -rf
command cannot be the source of that error message because -f
tells rm
to never fail (and to never print such error messages, try it locally rm -f /this/is/some/path/that/does/not/exist; echo $?
). (This means, of course, that the test for file existence itself is unnecessary since rm -f
does not care.
Additionally you do not need the -r
flag if you are deleting a file (and it is safer not to include it (or -f
) when you do not need them.
So something else must be printing that message. Do you use that file anywhere else? Does anything from the old package's %preun
use it perhaps?
Answered By - Etan Reisner Answer Checked By - Marie Seifert (WPSolving Admin)