@@ -800,7 +800,7 @@ public void update() throws IOException {
800
800
801
801
/**
802
802
* The traversal of the uid terms done in {@link #processFile(IndexDownArgs, File, String)}
803
- * and {@link #processFileIncremental (IndexDownArgs, File, String)} needs to skip over deleted documents
803
+ * and {@link #processFileHistoryBased (IndexDownArgs, File, String)} needs to skip over deleted documents
804
804
* that are often found in multi-segment indexes. This method stores the uids of these documents
805
805
* and is expected to be called before the traversal for the top level directory is started.
806
806
* @throws IOException if the index cannot be read for some reason
@@ -932,8 +932,11 @@ void indexDownUsingHistory(File sourceRoot, IndexDownArgs args) throws IOExcepti
932
932
try (Progress progress = new Progress (LOGGER , String .format ("collecting files for %s" , project ),
933
933
fileCollector .getFiles ().size ())) {
934
934
for (String path : fileCollector .getFiles ()) {
935
+ if (isInterrupted ()) {
936
+ return ;
937
+ }
935
938
File file = new File (sourceRoot , path );
936
- processFileIncremental (args , file , path );
939
+ processFileHistoryBased (args , file , path );
937
940
progress .increment ();
938
941
}
939
942
}
@@ -1288,6 +1291,7 @@ private static void cleanupResources(Document doc) {
1288
1291
1289
1292
/**
1290
1293
* Check if I should accept this file into the index database.
1294
+ * Directories are automatically accepted.
1291
1295
*
1292
1296
* @param file the file to check
1293
1297
* @param ret defined instance whose {@code localRelPath} property will be
@@ -1306,53 +1310,49 @@ private boolean accept(File file, AcceptSymlinkRet ret) {
1306
1310
}
1307
1311
1308
1312
if (!file .canRead ()) {
1309
- LOGGER .log (Level .WARNING , "Could not read {0}" , absolutePath );
1313
+ LOGGER .log (Level .WARNING , "Could not read '' {0}'' " , absolutePath );
1310
1314
return false ;
1311
1315
}
1312
1316
1313
1317
try {
1314
1318
Path absolute = Paths .get (absolutePath );
1315
1319
if (Files .isSymbolicLink (absolute )) {
1316
1320
File canonical = file .getCanonicalFile ();
1317
- if (!absolutePath .equals (canonical .getPath ()) &&
1318
- !acceptSymlink (absolute , canonical , ret )) {
1321
+ if (!absolutePath .equals (canonical .getPath ()) && !acceptSymlink (absolute , canonical , ret )) {
1319
1322
if (ret .localRelPath == null ) {
1320
1323
LOGGER .log (Level .FINE , "Skipped symlink ''{0}'' -> ''{1}''" ,
1321
1324
new Object [] {absolutePath , canonical });
1322
1325
}
1323
1326
return false ;
1324
1327
}
1325
1328
}
1326
- //below will only let go files and directories, anything else is considered special and is not added
1329
+ // Below will only let go files and directories, anything else is considered special and is not added.
1327
1330
if (!file .isFile () && !file .isDirectory ()) {
1328
- LOGGER .log (Level .WARNING , "Ignored special file {0}" ,
1329
- absolutePath );
1331
+ LOGGER .log (Level .WARNING , "Ignored special file ''{0}''" , absolutePath );
1330
1332
return false ;
1331
1333
}
1332
1334
} catch (IOException exp ) {
1333
- LOGGER .log (Level .WARNING , "Failed to resolve name: {0}" ,
1334
- absolutePath );
1335
+ LOGGER .log (Level .WARNING , "Failed to resolve name: ''{0}''" , absolutePath );
1335
1336
LOGGER .log (Level .FINE , "Stack Trace: " , exp );
1336
1337
}
1337
1338
1338
1339
if (file .isDirectory ()) {
1339
- // always accept directories so that their files can be examined
1340
+ // Always accept directories so that their files can be examined.
1340
1341
return true ;
1341
1342
}
1342
1343
1343
-
1344
1344
RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
1345
1345
// Lookup history if indexing versioned files only.
1346
1346
// Skip the lookup entirely (which is expensive) if unversioned files are allowed
1347
1347
if (env .isIndexVersionedFilesOnly ()) {
1348
1348
if (HistoryGuru .getInstance ().hasHistory (file )) {
1349
- // versioned files should always be accepted
1349
+ // Versioned files should always be accepted.
1350
1350
return true ;
1351
1351
}
1352
1352
LOGGER .log (Level .FINER , "not accepting unversioned {0}" , absolutePath );
1353
1353
return false ;
1354
1354
}
1355
- // unversioned files are allowed
1355
+ // Unversioned files are allowed.
1356
1356
return true ;
1357
1357
}
1358
1358
@@ -1374,7 +1374,7 @@ private boolean accept(File parent, File file, AcceptSymlinkRet ret) {
1374
1374
File f1 = parent .getCanonicalFile ();
1375
1375
File f2 = file .getCanonicalFile ();
1376
1376
if (f1 .equals (f2 )) {
1377
- LOGGER .log (Level .INFO , "Skipping links to itself...: {0} {1}" ,
1377
+ LOGGER .log (Level .INFO , "Skipping links to itself...: '' {0}'' '' {1}'' " ,
1378
1378
new Object []{parent .getAbsolutePath (), file .getAbsolutePath ()});
1379
1379
return false ;
1380
1380
}
@@ -1383,15 +1383,15 @@ private boolean accept(File parent, File file, AcceptSymlinkRet ret) {
1383
1383
File t1 = f1 ;
1384
1384
while ((t1 = t1 .getParentFile ()) != null ) {
1385
1385
if (f2 .equals (t1 )) {
1386
- LOGGER .log (Level .INFO , "Skipping links to parent...: {0} {1}" ,
1386
+ LOGGER .log (Level .INFO , "Skipping links to parent...: '' {0}'' '' {1}'' " ,
1387
1387
new Object []{parent .getAbsolutePath (), file .getAbsolutePath ()});
1388
1388
return false ;
1389
1389
}
1390
1390
}
1391
1391
1392
1392
return accept (file , ret );
1393
1393
} catch (IOException ex ) {
1394
- LOGGER .log (Level .WARNING , "Failed to resolve name: {0} {1}" ,
1394
+ LOGGER .log (Level .WARNING , "Failed to resolve name: '' {0}'' '' {1}'' " ,
1395
1395
new Object []{parent .getAbsolutePath (), file .getAbsolutePath ()});
1396
1396
}
1397
1397
return false ;
@@ -1423,7 +1423,7 @@ private boolean acceptSymlink(Path absolute, File canonical, AcceptSymlinkRet re
1423
1423
if (isLocal (canonical1 )) {
1424
1424
if (!isCanonicalDir ) {
1425
1425
if (LOGGER .isLoggable (Level .FINEST )) {
1426
- LOGGER .log (Level .FINEST , "Local {0} has symlink from {1}" ,
1426
+ LOGGER .log (Level .FINEST , "Local '' {0}'' has symlink from '' {1}'' " ,
1427
1427
new Object [] {canonical1 , absolute1 });
1428
1428
}
1429
1429
/*
@@ -1452,7 +1452,7 @@ private boolean acceptSymlink(Path absolute, File canonical, AcceptSymlinkRet re
1452
1452
* the file already -- but we are forced to handle.
1453
1453
*/
1454
1454
LOGGER .log (Level .WARNING , String .format (
1455
- "Unexpected error getting relative for %s " , canonical ), e );
1455
+ "Unexpected error getting relative for '%s' " , canonical ), e );
1456
1456
absolute0 = absolute1 ;
1457
1457
}
1458
1458
indexed1 = new IndexedSymlink (absolute0 , canonical1 , true );
@@ -1477,7 +1477,7 @@ private boolean acceptSymlink(Path absolute, File canonical, AcceptSymlinkRet re
1477
1477
Paths .get (indexed0 .getAbsolute ())).toString ();
1478
1478
1479
1479
if (LOGGER .isLoggable (Level .FINEST )) {
1480
- LOGGER .log (Level .FINEST , "External dir {0} has symlink from {1} after first {2}" ,
1480
+ LOGGER .log (Level .FINEST , "External dir '' {0}'' has symlink from '' {1}'' after first '' {2}'' " ,
1481
1481
new Object [] {canonical1 , absolute1 , indexed0 .getAbsolute ()});
1482
1482
}
1483
1483
return false ;
@@ -1495,7 +1495,7 @@ private boolean acceptSymlink(Path absolute, File canonical, AcceptSymlinkRet re
1495
1495
if (!isCanonicalDir ) {
1496
1496
if (LOGGER .isLoggable (Level .FINEST )) {
1497
1497
LOGGER .log (Level .FINEST ,
1498
- "External file {0} has symlink from {1} under previous {2}" ,
1498
+ "External file '' {0}'' has symlink from '' {1}'' under previous '' {2}'' " ,
1499
1499
new Object [] {canonical1 , absolute1 , absolute0 });
1500
1500
}
1501
1501
// Do not add to indexedSymlinks for a non-directory.
@@ -1512,7 +1512,7 @@ private boolean acceptSymlink(Path absolute, File canonical, AcceptSymlinkRet re
1512
1512
1513
1513
if (LOGGER .isLoggable (Level .FINEST )) {
1514
1514
LOGGER .log (Level .FINEST ,
1515
- "External dir {0} has symlink from {1} under previous {2}" ,
1515
+ "External dir '' {0}'' has symlink from '' {1}'' under previous '' {2}'' " ,
1516
1516
new Object [] {canonical1 , absolute1 , absolute0 });
1517
1517
}
1518
1518
return false ;
@@ -1523,7 +1523,7 @@ private boolean acceptSymlink(Path absolute, File canonical, AcceptSymlinkRet re
1523
1523
for (String canonicalRoot : canonicalRoots ) {
1524
1524
if (canonical1 .startsWith (canonicalRoot )) {
1525
1525
if (LOGGER .isLoggable (Level .FINEST )) {
1526
- LOGGER .log (Level .FINEST , "Allowed symlink {0} per canonical root {1}" ,
1526
+ LOGGER .log (Level .FINEST , "Allowed symlink '' {0}'' per canonical root '' {1}'' " ,
1527
1527
new Object [] {absolute1 , canonical1 });
1528
1528
}
1529
1529
if (isCanonicalDir ) {
@@ -1540,7 +1540,7 @@ private boolean acceptSymlink(Path absolute, File canonical, AcceptSymlinkRet re
1540
1540
try {
1541
1541
allowedTarget = new File (allowedSymlink ).getCanonicalPath ();
1542
1542
} catch (IOException e ) {
1543
- LOGGER .log (Level .FINE , "unresolvable symlink: {0}" , allowedSymlink );
1543
+ LOGGER .log (Level .FINE , "unresolvable symlink: '' {0}'' " , allowedSymlink );
1544
1544
continue ;
1545
1545
}
1546
1546
/*
@@ -1610,9 +1610,8 @@ private void handleSymlink(String path, AcceptSymlinkRet ret) {
1610
1610
* {@link #removeFile(boolean)}. New or updated files are noted for indexing.
1611
1611
* @param dir the root indexDirectory to generate indexes for
1612
1612
* @param parent path to parent directory
1613
- * @param args arguments to control execution and for collecting a list of
1613
+ * @param args arguments to control execution and for collecting a list of files for indexing
1614
1614
* @param progress {@link Progress} instance
1615
- * files for indexing
1616
1615
*/
1617
1616
@ VisibleForTesting
1618
1617
void indexDown (File dir , String parent , IndexDownArgs args , Progress progress ) throws IOException {
@@ -1629,8 +1628,7 @@ void indexDown(File dir, String parent, IndexDownArgs args, Progress progress) t
1629
1628
1630
1629
File [] files = dir .listFiles ();
1631
1630
if (files == null ) {
1632
- LOGGER .log (Level .SEVERE , "Failed to get file listing for: {0}" ,
1633
- dir .getPath ());
1631
+ LOGGER .log (Level .SEVERE , "Failed to get file listing for: ''{0}''" , dir .getPath ());
1634
1632
return ;
1635
1633
}
1636
1634
Arrays .sort (files , FILENAME_COMPARATOR );
@@ -1660,7 +1658,7 @@ void indexDown(File dir, String parent, IndexDownArgs args, Progress progress) t
1660
1658
* @throws IOException on error
1661
1659
*/
1662
1660
@ VisibleForTesting
1663
- void processFileIncremental (IndexDownArgs args , File file , String path ) throws IOException {
1661
+ void processFileHistoryBased (IndexDownArgs args , File file , String path ) throws IOException {
1664
1662
final boolean fileExists = file .exists ();
1665
1663
1666
1664
path = Util .fixPathIfWindows (path );
@@ -1689,9 +1687,7 @@ void processFileIncremental(IndexDownArgs args, File file, String path) throws I
1689
1687
checkSettings (termFile , termPath );
1690
1688
if (!matchOK ) {
1691
1689
removeFile (false );
1692
-
1693
- args .curCount ++;
1694
- args .works .add (new IndexFileWork (termFile , termPath ));
1690
+ addWorkHistoryBased (args , termFile , termPath );
1695
1691
}
1696
1692
} else {
1697
1693
removeFile (!fileExists );
@@ -1703,10 +1699,33 @@ void processFileIncremental(IndexDownArgs args, File file, String path) throws I
1703
1699
}
1704
1700
}
1705
1701
1706
- // The function would not be called if the file was not changed in some way.
1707
- if (fileExists ) {
1702
+ // This function would not be called if the file was not changed in some way (including deletion).
1703
+ // That said, it is necessary to check whether the file can be accepted. This is done in the function below.
1704
+ // Also, allow for broken symbolic links (File.exists() returns false for these).
1705
+ if (fileExists || Files .isSymbolicLink (file .toPath ())) {
1706
+ addWorkHistoryBased (args , file , path );
1707
+ }
1708
+ }
1709
+
1710
+ /**
1711
+ * Check if file can be accepted into the index database. If yes, change the {@code args} argument appropriately.
1712
+ * @param args {@link IndexDownArgs} instance to which an entry will be added if deemed acceptable
1713
+ * @param file file object
1714
+ * @param path path of the file relative to given source root (not necessarily global source root)
1715
+ */
1716
+ private void addWorkHistoryBased (IndexDownArgs args , File file , String path ) {
1717
+ AcceptSymlinkRet ret = new AcceptSymlinkRet ();
1718
+ if (accept (file , ret )) {
1719
+ // accept() returns true for directories because it was made to work with indexDown().
1720
+ if (file .isDirectory ()) {
1721
+ LOGGER .log (Level .FINER , "not accepting directory ''{0}'' into the index" , file );
1722
+ return ;
1723
+ }
1724
+
1708
1725
args .curCount ++;
1709
1726
args .works .add (new IndexFileWork (file , path ));
1727
+ } else {
1728
+ handleSymlink (file .getParent (), ret );
1710
1729
}
1711
1730
}
1712
1731
@@ -2210,7 +2229,7 @@ boolean checkSettings(File file, String path) throws IOException {
2210
2229
project .getTabSize () : 0 ;
2211
2230
Integer actTabSize = settings .getTabSize ();
2212
2231
if (actTabSize != null && !actTabSize .equals (reqTabSize )) {
2213
- LOGGER .log (Level .FINE , "Tabsize mismatch: {0}" , path );
2232
+ LOGGER .log (Level .FINE , "Tabsize mismatch: '' {0}'' " , path );
2214
2233
return false ;
2215
2234
}
2216
2235
@@ -2222,7 +2241,7 @@ boolean checkSettings(File file, String path) throws IOException {
2222
2241
// Read a limited-fields version of the document.
2223
2242
Document doc = storedFields .document (postsIter .docID (), CHECK_FIELDS );
2224
2243
if (doc == null ) {
2225
- LOGGER .log (Level .FINER , "No Document: {0}" , path );
2244
+ LOGGER .log (Level .FINER , "No Document for '' {0}'' " , path );
2226
2245
continue ;
2227
2246
}
2228
2247
@@ -2243,7 +2262,7 @@ boolean checkSettings(File file, String path) throws IOException {
2243
2262
fileTypeName = doc .get (QueryBuilder .TYPE );
2244
2263
if (fileTypeName == null ) {
2245
2264
// (Should not get here, but break just in case.)
2246
- LOGGER .log (Level .FINEST , "Missing TYPE field: {0}" , path );
2265
+ LOGGER .log (Level .FINEST , "Missing TYPE field: '' {0}'' " , path );
2247
2266
break ;
2248
2267
}
2249
2268
@@ -2257,14 +2276,14 @@ boolean checkSettings(File file, String path) throws IOException {
2257
2276
* selection of analyzer or return a value to indicate the
2258
2277
* analyzer is now mis-matched.
2259
2278
*/
2260
- LOGGER .log (Level .FINER , "Guru version mismatch: {0}" , path );
2279
+ LOGGER .log (Level .FINER , "Guru version mismatch: '' {0}'' " , path );
2261
2280
2262
2281
fa = getAnalyzerFor (file , path );
2263
2282
fileTypeName = fa .getFileTypeName ();
2264
2283
String oldTypeName = doc .get (QueryBuilder .TYPE );
2265
2284
if (!fileTypeName .equals (oldTypeName )) {
2266
2285
if (LOGGER .isLoggable (Level .FINE )) {
2267
- LOGGER .log (Level .FINE , "Changed {0} to {1}: {2}" ,
2286
+ LOGGER .log (Level .FINE , "Changed {0} to {1}: '' {2}'' " ,
2268
2287
new Object []{oldTypeName , fileTypeName , path });
2269
2288
}
2270
2289
return false ;
@@ -2276,7 +2295,7 @@ boolean checkSettings(File file, String path) throws IOException {
2276
2295
Long actVersion = settings .getAnalyzerVersion (fileTypeName );
2277
2296
if (actVersion == null || !actVersion .equals (reqVersion )) {
2278
2297
if (LOGGER .isLoggable (Level .FINE )) {
2279
- LOGGER .log (Level .FINE , "{0} version mismatch: {1}" ,
2298
+ LOGGER .log (Level .FINE , "{0} version mismatch: '' {1}'' " ,
2280
2299
new Object []{fileTypeName , path });
2281
2300
}
2282
2301
return false ;
@@ -2290,14 +2309,14 @@ boolean checkSettings(File file, String path) throws IOException {
2290
2309
break ;
2291
2310
}
2292
2311
if (n < 1 ) {
2293
- LOGGER .log (Level .FINER , "Missing index Documents: {0}" , path );
2312
+ LOGGER .log (Level .FINER , "Missing index Documents: '' {0}'' " , path );
2294
2313
return false ;
2295
2314
}
2296
2315
2297
2316
// If the economy mode is on, this should be treated as a match.
2298
2317
if (!env .isGenerateHtml ()) {
2299
2318
if (xrefExistsFor (path )) {
2300
- LOGGER .log (Level .FINEST , "Extraneous {0} , removing its xref file" , path );
2319
+ LOGGER .log (Level .FINEST , "Extraneous '' {0}'' , removing its xref file" , path );
2301
2320
removeXrefFile (path );
2302
2321
}
2303
2322
return true ;
0 commit comments