This can be done completely non-racily with os.open - a really picky version could be a function something like:
lomode = os.O_WRONLY | os.O_APPEND | osutils.O_TEXT while True: try: return os.open(filename, lomode) except OSError, e: if e.errno != errno.ENOENT: raise try: fd = os.open(filename, lomode | os.O_CREAT | os.O_EXCL) except OSError, e: if e.errno != errno.EEXIST: raise else: copy_ownership(filename, ownership_src) return fd
And os.fdopen to make a regular file object.
Raises the question though, is it ever going to be right for a osutils.open_with_ownership function to chown the file if it's *not* just created it? Makes me wonder again whether bundling the chown into the open function makes any sense.
« Back to merge proposal
This can be done completely non-racily with os.open - a really picky version could be a function something like:
lomode = os.O_WRONLY | os.O_APPEND | osutils.O_TEXT
raise
raise
copy_ ownership( filename, ownership_src)
while True:
try:
return os.open(filename, lomode)
except OSError, e:
if e.errno != errno.ENOENT:
try:
fd = os.open(filename, lomode | os.O_CREAT | os.O_EXCL)
except OSError, e:
if e.errno != errno.EEXIST:
else:
return fd
And os.fdopen to make a regular file object.
Raises the question though, is it ever going to be right for a osutils. open_with_ ownership function to chown the file if it's *not* just created it? Makes me wonder again whether bundling the chown into the open function makes any sense.