Skip to content

Commit 65d41e6

Browse files
authored
avoid truncation when merging config files (#4509)
fixes #4507
1 parent ee009d0 commit 65d41e6

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/ConfigMerge.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.indexer.configuration;
2424

2525
import java.beans.IntrospectionException;
2626
import java.beans.PropertyDescriptor;
2727
import java.io.File;
28+
import java.io.FileOutputStream;
2829
import java.io.IOException;
2930
import java.io.OutputStream;
3031
import java.io.PrintStream;
@@ -140,7 +141,7 @@ public static void main(String[] argv) {
140141
}
141142

142143
int optind = getopt.getOptind();
143-
if (optind < 0 || argv.length - optind != 2) {
144+
if (optind < 0 || argv.length - optind != 3) {
144145
aUsage(System.err);
145146
System.exit(1);
146147
}
@@ -168,14 +169,18 @@ public static void main(String[] argv) {
168169
System.exit(1);
169170
}
170171

171-
// Write the resulting XML representation to standard output.
172-
OutputStream os = System.out;
173-
cfgNew.encodeObject(os);
172+
// Write the resulting XML representation to the output file.
173+
try (OutputStream os = new FileOutputStream(argv[optind + 2])) {
174+
cfgNew.encodeObject(os);
175+
} catch (IOException ex) {
176+
System.err.print(ex);
177+
System.exit(1);
178+
}
174179
}
175180

176181
private static void aUsage(PrintStream out) {
177182
out.println("Usage:");
178-
out.println(NAME + " [-h] <config_file_base> <config_file_new>");
183+
out.println(NAME + " [-h] <config_file_base> <config_file_new> <output_file>");
179184
out.println();
180185
out.println("OPTIONS:");
181186
out.println("Help");

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

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

2020
#
21-
# Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
21+
# Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
2222
#
2323

2424
import argparse
@@ -33,20 +33,20 @@
3333
SUCCESS_EXITVAL
3434
)
3535
"""
36-
Wrapper for Java program merging OpenGrok configuration.
36+
Wrapper for the ConfigMerge Java program merging OpenGrok configuration files.
3737
"""
3838

3939

4040
def merge_config_files(read_only, current, out_file, jar,
4141
loglevel=logging.INFO):
4242

43-
return config_merge_wrapper([read_only, current], jar=jar,
44-
out_file=out_file, loglevel=loglevel)
43+
return config_merge_wrapper([read_only, current, out_file], jar=jar,
44+
loglevel=loglevel)
4545

4646

4747
def config_merge_wrapper(options, loglevel=logging.INFO,
4848
jar=None, java=None, java_opts=None,
49-
doprint=False, out_file=None):
49+
doprint=False):
5050

5151
# Avoid using utils.log.get_console_level() since the stdout of the program
5252
# is interpreted as data.
@@ -63,11 +63,6 @@ def config_merge_wrapper(options, loglevel=logging.INFO,
6363
logger.error(cmd.geterroutput())
6464
logger.error("command failed (return code {})".format(ret))
6565
return FAILURE_EXITVAL
66-
else:
67-
if out_file:
68-
out_file.write(cmd.getoutputstr())
69-
else:
70-
print(cmd.getoutputstr())
7166

7267
return SUCCESS_EXITVAL
7368

0 commit comments

Comments
 (0)