Skip to content

Commit 3ac974c

Browse files
author
Vladimir Kotal
committed
refactor directory creation into method
1 parent 6c637b9 commit 3ac974c

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

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

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -515,25 +515,8 @@ public void storeRenamed(Set<String> renamedFiles, Repository repository, String
515515
LOGGER.log(Level.FINE, "Storing history for {0} renamed files in repository ''{1}''",
516516
new Object[]{renamedFiles.size(), repository.getDirectoryName()});
517517

518-
// The directories for the renamed files have to be created before
519-
// the actual files otherwise storeFile() might be racing for
520-
// mkdirs() if there are multiple renamed files from single directory
521-
// handled in parallel.
522-
for (final String file : renamedFiles) {
523-
File cache;
524-
try {
525-
cache = getCachedFile(new File(env.getSourceRootPath() + file));
526-
} catch (ForbiddenSymlinkException ex) {
527-
LOGGER.log(Level.FINER, ex.getMessage());
528-
continue;
529-
}
530-
File dir = cache.getParentFile();
518+
createDirectoriesForFiles(renamedFiles);
531519

532-
if (!dir.isDirectory() && !dir.mkdirs()) {
533-
LOGGER.log(Level.WARNING,
534-
"Unable to create cache directory ' {0} '.", dir);
535-
}
536-
}
537520
final Repository repositoryF = repository;
538521
final CountDownLatch latch = new CountDownLatch(renamedFiles.size());
539522
AtomicInteger renamedFileHistoryCount = new AtomicInteger();
@@ -565,6 +548,28 @@ public void storeRenamed(Set<String> renamedFiles, Repository repository, String
565548
new Object[]{renamedFileHistoryCount.intValue(), repository.getDirectoryName()});
566549
}
567550

551+
private void createDirectoriesForFiles(Set<String> files) throws HistoryException {
552+
// The directories for the files have to be created before
553+
// the actual files otherwise storeFile() might be racing for
554+
// mkdirs() if there are multiple files from single directory
555+
// handled in parallel.
556+
for (final String file : files) {
557+
File cache;
558+
try {
559+
cache = getCachedFile(new File(env.getSourceRootPath() + file));
560+
} catch (ForbiddenSymlinkException ex) {
561+
LOGGER.log(Level.FINER, ex.getMessage());
562+
continue;
563+
}
564+
File dir = cache.getParentFile();
565+
566+
if (!dir.isDirectory() && !dir.mkdirs()) {
567+
LOGGER.log(Level.WARNING,
568+
"Unable to create cache directory ' {0} '.", dir);
569+
}
570+
}
571+
}
572+
568573
@Override
569574
public History get(File file, Repository repository, boolean withFiles)
570575
throws HistoryException, ForbiddenSymlinkException {

0 commit comments

Comments
 (0)