Skip to content

Commit 823830a

Browse files
author
Vladimir Kotal
authored
delete ctags temp files at the end of indexing (#3188)
fixes #3183
1 parent 941c457 commit 823830a

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright 2011 Jens Elkner.
2323
* Portions Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>.
2424
*/
@@ -1089,6 +1089,8 @@ public void run() {
10891089
" for executor to finish", exp);
10901090
}
10911091
elapsed.report(LOGGER, "Done indexing data of all repositories");
1092+
1093+
CtagsUtil.deleteTempFiles();
10921094
}
10931095

10941096
public void refreshSearcherManagers(RuntimeEnvironment env, List<String> projects, String host) {

opengrok-indexer/src/main/java/org/opengrok/indexer/util/CtagsUtil.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2019, Chris Fraire <cfraire@me.com>.
2323
*/
2424

@@ -29,10 +29,13 @@
2929
import org.opengrok.indexer.configuration.RuntimeEnvironment;
3030
import org.opengrok.indexer.logger.LoggerFactory;
3131

32+
import java.io.File;
3233
import java.util.ArrayList;
3334
import java.util.List;
3435
import java.util.logging.Level;
3536
import java.util.logging.Logger;
37+
import java.util.regex.Matcher;
38+
import java.util.regex.Pattern;
3639

3740
public class CtagsUtil {
3841

@@ -86,6 +89,39 @@ public static List<String> getLanguages(String ctagsBinary) {
8689
return result;
8790
}
8891

92+
/**
93+
* Deletes Ctags temporary files left over after terminating Ctags processes
94+
* in case of timeout, @see Ctags#doCtags.
95+
*/
96+
public static void deleteTempFiles() {
97+
String[] dirs = {System.getProperty("java.io.tmpdir"),
98+
System.getenv("TMPDIR"), System.getenv("TMP")};
99+
100+
for (String dir : dirs) {
101+
deleteTempFiles(dir);
102+
}
103+
}
104+
105+
private static void deleteTempFiles(String directoryName) {
106+
final Pattern pattern = Pattern.compile("tags\\.\\S{6}"); // ctags uses this pattern to call mkstemp()
107+
108+
if (directoryName == null) {
109+
return;
110+
}
111+
112+
File dir = new File(directoryName);
113+
File[] files = dir.listFiles((dir1, name) -> {
114+
Matcher matcher = pattern.matcher(name);
115+
return matcher.find();
116+
});
117+
118+
for (File file : files) {
119+
if (file.isFile() && !file.delete()) {
120+
LOGGER.log(Level.WARNING, "cannot delete file {0}", file);
121+
}
122+
}
123+
}
124+
89125
/**
90126
* Creates a new instance, and attempts to configure it from the
91127
* environment.

0 commit comments

Comments
 (0)