[IMP] tools: avoid concurrent creation of the session_dir
Instead of: 1. testing the existance 2. creating the directory if not exists (which would not work if a concurrent creation is done between step 1 and 2) do: 1. try to create the directory 2. skip if it fails Ask forgiveness, not permission Closes #24210
This commit is contained in:
@@ -6,6 +6,7 @@ try:
|
||||
except ImportError:
|
||||
import ConfigParser
|
||||
|
||||
import errno
|
||||
import logging
|
||||
import optparse
|
||||
import os
|
||||
@@ -620,9 +621,11 @@ class configmanager(object):
|
||||
@property
|
||||
def session_dir(self):
|
||||
d = os.path.join(self['data_dir'], 'sessions')
|
||||
if not os.path.exists(d):
|
||||
try:
|
||||
os.makedirs(d, 0o700)
|
||||
else:
|
||||
except OSError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
raise
|
||||
assert os.access(d, os.W_OK), \
|
||||
"%s: directory is not writable" % d
|
||||
return d
|
||||
|
||||
Reference in New Issue
Block a user