Skip to content

Commit 20bf34d

Browse files
committed
create all directories in deploy_war()
fixes #3985
1 parent 318c505 commit 20bf34d

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

tools/src/main/python/opengrok_tools/deploy.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# CDDL HEADER END
1919

2020
#
21-
# Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
21+
# Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
2222
# Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
2323
#
2424

@@ -116,7 +116,10 @@ def deploy_war(logger, source_war, target_war, config_file=None,
116116
config_file, insert_path)
117117
source_war = tmp_war.name
118118

119-
logger.debug("Installing {} to {}".format(source_war, target_war))
119+
logger.debug(f"Installing '{source_war}' to '{target_war}'")
120+
target_dir = os.path.dirname(target_war)
121+
if not os.path.isdir(target_dir):
122+
os.makedirs(target_dir)
120123
copyfile(source_war, target_war)
121124

122125
if tmp_war:
@@ -150,7 +153,7 @@ def main():
150153
try:
151154
deploy_war(logger, args.source_war[0], args.target_war[0], args.config,
152155
args.insert)
153-
except XMLProcessingException as e:
156+
except (XMLProcessingException, OSError) as e:
154157
return fatal(e, exit=False)
155158

156159

tools/src/test/python/test_deploy.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
3+
#
4+
# CDDL HEADER START
5+
#
6+
# The contents of this file are subject to the terms of the
7+
# Common Development and Distribution License (the "License").
8+
# You may not use this file except in compliance with the License.
9+
#
10+
# See LICENSE.txt included in this distribution for the specific
11+
# language governing permissions and limitations under the License.
12+
#
13+
# When distributing Covered Code, include this CDDL HEADER in each
14+
# file and include the License file at LICENSE.txt.
15+
# If applicable, add the following below this CDDL HEADER, with the
16+
# fields enclosed by brackets "[]" replaced with your own identifying
17+
# information: Portions Copyright [yyyy] [name of copyright owner]
18+
#
19+
# CDDL HEADER END
20+
#
21+
22+
#
23+
# Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
24+
#
25+
26+
import logging
27+
import os
28+
import tempfile
29+
30+
from opengrok_tools.deploy import deploy_war
31+
32+
33+
def test_deploy_dirs():
34+
logger = logging.getLogger(__name__)
35+
36+
with tempfile.NamedTemporaryFile() as source_war_fp, tempfile.TemporaryDirectory() as tmp_dir:
37+
source_war = source_war_fp.name
38+
assert os.path.isfile(source_war)
39+
target_war = os.path.join(tmp_dir, "foo", "bar", "my.war")
40+
target_dir = os.path.dirname(target_war)
41+
deploy_war(logger, source_war, target_war)
42+
assert os.path.isdir(target_dir)
43+
assert os.path.isfile(target_war)

0 commit comments

Comments
 (0)