Skip to content

Commit 1b93561

Browse files
committed
keep the subFiles in a Set
fixes #3904
1 parent 5b802c5 commit 1b93561

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.nio.file.Paths;
3434
import java.util.ArrayList;
3535
import java.util.Arrays;
36+
import java.util.Collection;
3637
import java.util.Collections;
3738
import java.util.Date;
3839
import java.util.HashSet;
@@ -1604,10 +1605,10 @@ public void setConfiguration(Configuration configuration, CommandTimeoutType cmd
16041605
* Sets the configuration and performs necessary actions.
16051606
*
16061607
* @param configuration new configuration
1607-
* @param subFileList list of repositories
1608+
* @param subFileList collection of repositories
16081609
* @param cmdType command timeout type
16091610
*/
1610-
public synchronized void setConfiguration(Configuration configuration, List<String> subFileList, CommandTimeoutType cmdType) {
1611+
public synchronized void setConfiguration(Configuration configuration, Collection<String> subFileList, CommandTimeoutType cmdType) {
16111612
try (ResourceLock resourceLock = configLock.writeLockAsResource()) {
16121613
//noinspection ConstantConditions to avoid warning of no reference to auto-closeable
16131614
assert resourceLock != null;

opengrok-indexer/src/main/java/org/opengrok/indexer/history/HistoryGuru.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,10 +804,10 @@ public void removeRepositories(Collection<String> repos) {
804804
/**
805805
* Set list of known repositories which match the list of directories.
806806
* @param repos list of repositories
807-
* @param dirs list of directories that might correspond to the repositories
807+
* @param dirs collection of directories that might correspond to the repositories
808808
* @param cmdType command timeout type
809809
*/
810-
public void invalidateRepositories(Collection<? extends RepositoryInfo> repos, List<String> dirs, CommandTimeoutType cmdType) {
810+
public void invalidateRepositories(Collection<? extends RepositoryInfo> repos, Collection<String> dirs, CommandTimeoutType cmdType) {
811811
if (repos != null && !repos.isEmpty() && dirs != null && !dirs.isEmpty()) {
812812
List<RepositoryInfo> newrepos = new ArrayList<>();
813813
for (RepositoryInfo i : repos) {

opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexCheck.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import java.io.File;
2727
import java.io.IOException;
28-
import java.util.List;
28+
import java.util.Collection;
2929
import java.util.logging.Level;
3030
import java.util.logging.Logger;
3131
import org.apache.lucene.index.SegmentInfos;
@@ -77,13 +77,12 @@ private IndexCheck() {
7777
/**
7878
* Check if version of index(es) matches major Lucene version.
7979
* @param configuration configuration based on which to perform the check
80-
* @param subFilesList list of paths. If non-empty, only projects matching these paths will be checked.
80+
* @param subFilesList collection of paths. If non-empty, only projects matching these paths will be checked.
8181
* @return true on success, false on failure
8282
*/
83-
public static boolean check(@NotNull Configuration configuration, List<String> subFilesList) {
83+
public static boolean check(@NotNull Configuration configuration, Collection<String> subFilesList) {
8484
File indexRoot = new File(configuration.getDataRoot(), IndexDatabase.INDEX_DIR);
85-
LOGGER.log(Level.FINE, "Checking for Lucene index version mismatch in {0}",
86-
indexRoot);
85+
LOGGER.log(Level.FINE, "Checking for Lucene index version mismatch in {0}", indexRoot);
8786
int ret = 0;
8887

8988
if (!subFilesList.isEmpty()) {

opengrok-indexer/src/main/java/org/opengrok/indexer/index/Indexer.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2011, Jens Elkner.
2323
* Portions Copyright (c) 2017, 2020, Chris Fraire <[email protected]>.
2424
*/
@@ -164,7 +164,7 @@ public static void main(String[] argv) {
164164

165165
Executor.registerErrorHandler();
166166
List<String> subFiles = RuntimeEnvironment.getInstance().getSubFiles();
167-
ArrayList<String> subFilesList = new ArrayList<>();
167+
Set<String> subFilesArgs = new HashSet<>();
168168

169169
boolean createDict = false;
170170

@@ -242,10 +242,11 @@ public static void main(String[] argv) {
242242
cfg.setCanonicalRoots(canonicalRoots);
243243

244244
// Assemble the unprocessed command line arguments (possibly a list of paths).
245-
// This will be used to perform more fine-grained checking in invalidateRepositories().
245+
// This will be used to perform more fine-grained checking in invalidateRepositories()
246+
// called from the setConfiguration() below.
246247
for (String arg : argv) {
247248
String path = Paths.get(cfg.getSourceRoot(), arg).toString();
248-
subFilesList.add(path);
249+
subFilesArgs.add(path);
249250
}
250251

251252
// If a user used customizations for projects he perhaps just
@@ -266,10 +267,10 @@ public static void main(String[] argv) {
266267
System.exit(1);
267268
}
268269

269-
if (!IndexCheck.check(cfg, subFilesList)) {
270+
if (!IndexCheck.check(cfg, subFilesArgs)) {
270271
System.err.printf("Index check failed%n");
271272
System.err.print("You might want to remove " +
272-
(!subFilesList.isEmpty() ? "data for projects " + String.join(",", subFilesList) :
273+
(!subFilesArgs.isEmpty() ? "data for projects " + String.join(",", subFilesArgs) :
273274
"all data") + " under the data root and reindex\n");
274275
System.exit(1);
275276
}
@@ -278,7 +279,7 @@ public static void main(String[] argv) {
278279
}
279280

280281
// Set updated configuration in RuntimeEnvironment.
281-
env.setConfiguration(cfg, subFilesList, CommandTimeoutType.INDEXER);
282+
env.setConfiguration(cfg, subFilesArgs, CommandTimeoutType.INDEXER);
282283

283284
// Let repository types to add items to ignoredNames.
284285
// This changes env so is called after the setConfiguration()
@@ -299,7 +300,7 @@ public static void main(String[] argv) {
299300
* directory and not per project data root directory).
300301
* For the check we need to have 'env' already set.
301302
*/
302-
for (String path : subFilesList) {
303+
for (String path : subFilesArgs) {
303304
String srcPath = env.getSourceRootPath();
304305
if (srcPath == null) {
305306
System.err.println("Error getting source root from environment. Exiting.");
@@ -326,7 +327,7 @@ public static void main(String[] argv) {
326327
}
327328
}
328329

329-
if (!subFilesList.isEmpty() && subFiles.isEmpty()) {
330+
if (!subFilesArgs.isEmpty() && subFiles.isEmpty()) {
330331
System.err.println("None of the paths were added, exiting");
331332
System.exit(1);
332333
}

0 commit comments

Comments
 (0)