Skip to content

Commit 1ccd96b

Browse files
authored
Merge pull request #220 from lorenzorubi-db/create_repos_w_parent_dir
create parent dir for Repo if it does not exist
2 parents 5e58ce2 + 559fed0 commit 1ccd96b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

dbclient/WorkspaceClient.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import base64
2+
import re
3+
24
from dbclient import *
35
import wmconstants
46
import concurrent
@@ -915,6 +917,20 @@ def create_repo(self, repo_str, error_logger, checkpoint_repo_set):
915917
if repo_url:
916918
logging.info("Repo: {0}".format(repo_json.get('path', '')))
917919
resp = self.post(api_path, repo_json)
920+
if (resp.get('error_code') == "RESOURCE_DOES_NOT_EXIST") and \
921+
(resp.get('http_status_code') == 404):
922+
parent_directory = re.sub(r"^RESOURCE_DOES_NOT_EXIST: Parent directory ", '', resp.get('message'))
923+
parent_directory = re.sub(r" does not exist.$", '', parent_directory)
924+
if re.fullmatch(
925+
r'/Repos/.+\@.+', parent_directory
926+
):
927+
logging.info(f"Creating parent directory {parent_directory}")
928+
resp2 = self.post('/workspace/mkdirs', {"path": parent_directory})
929+
if logging_utils.check_error(resp2):
930+
logging_utils.log_response_error(error_logger, resp2)
931+
else:
932+
logging.info(f"2nd attempt to create: {repo_json.get('path', '')}")
933+
resp = self.post(api_path, repo_json)
918934
if logging_utils.check_error(resp):
919935
logging_utils.log_response_error(error_logger, resp)
920936
else:

0 commit comments

Comments
 (0)