Skip to content

Commit 246545d

Browse files
committed
fixup
1 parent d696b7f commit 246545d

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

mig/shared/useradm.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,20 @@ def verify_user_peers(configuration, db_path, client_id, user, now, verify_peer,
455455
return accepted_peer_list, effective_expire
456456

457457

458+
def _check_directories_unprovisioned(configuration, db_path):
459+
user_db_home = os.path.dirname(db_path)
460+
return not os.path.exists(db_path) and not os.path.exists(user_db_home)
461+
462+
463+
def _provision_directories(configuration):
464+
for config_attr in ('user_db_home', 'user_home', 'user_settings', 'user_cache', 'mrsl_files_dir', 'resource_pending'):
465+
try:
466+
dir_to_create = getattr(configuration, config_attr)
467+
os.mkdir(dir_to_create)
468+
except FileExistsError:
469+
pass
470+
471+
458472
def create_user_in_db(configuration, db_path, client_id, user, now, authorized,
459473
reset_token, reset_auth_type, accepted_peer_list, force,
460474
verbose, ask_renew, default_renew, do_lock,
@@ -476,10 +490,8 @@ def create_user_in_db(configuration, db_path, client_id, user, now, authorized,
476490
if oserr.errno != errno.ENOENT: # FileNotFoundError
477491
raise
478492

479-
user_db_home = os.path.dirname(db_path)
480-
481-
if not os.path.exists(db_path) and not os.path.exists(user_db_home):
482-
os.mkdir(user_db_home)
493+
if _check_directories_unprovisioned(configuration, db_path=db_path):
494+
_provision_directories(configuration)
483495
retry_lock = True
484496
else:
485497
raise Exception("Failed to lock user DB: '%s'" % db_path)

tests/test_mig_server_createuser.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
from __future__ import print_function
3131
import os
32+
import shutil
3233
import sys
3334

3435
from tests.support import MIG_BASE, TEST_OUTPUT_DIR, MigTestCase, testmain
@@ -38,11 +39,17 @@
3839
class TestBooleans(MigTestCase):
3940
def before_each(self):
4041
configuration = self.configuration
41-
test_user_db_home = os.path.join(configuration.state_path, 'user_db_home')
42-
try:
43-
os.rmdir(test_user_db_home)
44-
except:
45-
pass
42+
test_state_path = configuration.state_path
43+
44+
for state_dir in ('user_db_home', 'user_home', 'user_settings', 'user_cache', 'mrsl_files', 'resource_pending'):
45+
stat_dir_path = os.path.join(test_state_path, state_dir)
46+
try:
47+
shutil.rmtree(stat_dir_path)
48+
except:
49+
pass
50+
51+
52+
test_user_db_home = os.path.join(test_state_path, 'user_db_home')
4653
self.expected_user_db_home = test_user_db_home
4754

4855
def _provide_configuration(self):

0 commit comments

Comments
 (0)