Failure to rename files that have active file handles
davecb at Canada.Sun.COM
Tue Nov 17 21:13:42 GMT 1998
| However we have come across one little problem, which may be down to
| configuration, that has left us "worried" about ditching our NFS
| solution completely. That is we seem to be unable to rename a file
| has an open file handle (either owned by the same process doing the
| rename or a different process), this is not a problem on a local NT
| drive or on an NFS mounted drive. This showed up in "makedepend" which
| has code like this:
| fdin = fopen("Makefile",...)
| fdout = freopen("Makefile","w",stdout)
Er: that's wrong.
The algorithm you're thinking of is
1) copy x x.bak
2) open x and rewind
4) while reading x.bak, rewrite x.
This preserves the permissions on the file, and
tends to leave it in a recoverable state for as
long as possible, while always leaving a .bak file
in a sane state.
The algorith's a variant on "how to update a master file"
from the ACM, back in the algol/fortran days. And it
is one that Windows locking allows...
David Collier-Brown, | Always do right. This will gratify some people
185 Ellerslie Ave., | and astonish the rest. -- Mark Twain
Willowdale, Ontario | http://java.science.yorku.ca/~davecb
Work: (905) 477-0437, Home: (416) 223-8968, Email: davecb at canada.sun.com
More information about the samba