I have a part of a bash script, which I am executing as root:
rm -f ../../include/profile.h; \
cp profile.h ../../include/profile.h
the file ../../include/profile.h in question has permissions:
-rw-r--r-- 1 root root 12178 Nov 5 02:00 ../../include/profile.h
Most of the time, the snippet executes fine, but very rarely, impossible to reproduce, it fails:
cp: cannot create regular file `../../include/profile.h': File exists
I checked, there is no other part of the program, that would be executed in parallel, which could write the file in between the two statements, thus creating a race condition which would explain the behaviour. There is no other place than the above, which is executed only once, which would write this file.
The system is
kernel:
Linux dev64 2.6.32.63+drm33.26-64.128-a10 #6 SMP Fri Jul 25 15:21:56 PDT 2014 x86_64 x86_64 x86_64 GNU/Linux
distro:
CentOS release 6.3 (Final)
What could possibly cause this failure to appear??