238
238
This sets the global _bzr_log_filename.
240
240
global _bzr_log_filename
242
def create_log_file(filename):
243
"""Create a log file in while avoiding race.
245
buffering = 0 # unbuffered
246
mode = os.O_WRONLY | os.O_APPEND | osutils.O_TEXT
248
fd = os.open(filename, mode)
249
logfile = os.fdopen(fd, 'at', buffering)
252
if e.errno != errno.ENOENT:
255
fd = os.open(filename, mode | os.O_CREAT | os.O_EXCL)
256
logfile = os.fdopen(fd, 'at', buffering)
258
if e.errno != errno.EEXIST:
261
# Copy ownership from parent directory
262
osutils.copy_ownership(filename)
241
266
_bzr_log_filename = _get_bzr_log_filename()
242
267
_rollover_trace_maybe(_bzr_log_filename)
244
buffering = 0 # unbuffered
245
if os.path.exists(_bzr_log_filename):
246
bzr_log_file = open(_bzr_log_filename, 'at', buffering=buffering)
248
# create log file with ownership of containing directory
249
bzr_log_file = osutils.open_with_ownership(_bzr_log_filename,
251
# bzr_log_file.tell() on windows always return 0 until some writing done
269
bzr_log_file = create_log_file(_bzr_log_filename)
252
270
bzr_log_file.write('\n')
253
271
if bzr_log_file.tell() <= 2:
254
272
bzr_log_file.write("this is a debug log for diagnosing/reporting problems in bzr\n")