240
240
global _bzr_log_filename
242
242
def create_log_file(filename):
243
"""Create a log file in while avoiding race.
243
"""Create the .bzr.log file.
245
It inherits the ownership and permissions (masked by umask) from
246
the containing directory to cope better with being run under sudo
247
with $HOME still set to the user's homedir.
245
249
buffering = 0 # unbuffered
246
mode = os.O_WRONLY | os.O_APPEND | osutils.O_TEXT
250
flags = os.O_WRONLY | os.O_APPEND | osutils.O_TEXT
249
fd = os.open(filename, mode)
253
fd = os.open(filename, flags)
250
254
logfile = os.fdopen(fd, 'at', buffering)
252
256
except OSError, e:
253
257
if e.errno != errno.ENOENT:
256
fd = os.open(filename, mode | os.O_CREAT | os.O_EXCL)
260
flags = flags | os.O_CREAT | os.O_EXCL
262
fd = os.open(filename, flags, permissions)
257
263
logfile = os.fdopen(fd, 'at', buffering)
258
264
except OSError, e:
259
265
if e.errno != errno.EEXIST:
262
# Copy ownership from parent directory
263
osutils.copy_ownership(filename)
268
osutils.copy_ownership_from_path(filename)