def _create_tempfile(self, pathname): # pragma: no cover
path = self.join(pathname)
dirname = os.path.dirname(path)
if not os.path.exists(dirname):
tracing.trace('os.makedirs(%s)' % dirname)
try:
os.makedirs(dirname, mode=obnamlib.NEW_DIR_MODE)
except OSError as e: # pragma: no cover
# This avoids a race condition: another Obnam process
# may have created the directory between our check and
# creation attempt. If so, we ignore it. As long as
# the directory exists, all's good.
if e.errno != errno.EEXIST:
raise
fd, tempname = tempfile.mkstemp(dir=dirname)
os.fchmod(fd, obnamlib.NEW_FILE_MODE)
os.close(fd)
f = self.open(tempname, 'wb')
f.close()
return tempname
评论列表
文章目录