Skip to content

Commit 6dc8614

Browse files
committed
fix the test
copyDirectory needs to copy sub-directories as well
1 parent 08db34c commit 6dc8614

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

opengrok-indexer/src/test/java/org/opengrok/indexer/index/IndexDatabaseTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ void testHistoryBasedReindexVsProjectWithDiverseRepos(boolean useCvs) throws Exc
559559
Path destinationPath = Path.of(repository.getSourceRoot(), projectName, subrepoName);
560560
Path sourcePath = Path.of(repository.getSourceRoot(), "cvs_test", "cvsrepo");
561561
assertTrue(sourcePath.toFile().exists());
562+
assertTrue(destinationPath.toFile().mkdirs());
562563
repository.copyDirectory(sourcePath, destinationPath);
563564
assertTrue(destinationPath.toFile().exists());
564565

opengrok-indexer/src/test/java/org/opengrok/indexer/util/TestRepository.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ public void create(@NotNull final URL url) throws IOException, URISyntaxExceptio
104104
}
105105
}
106106

107+
/**
108+
* Assumes the destination directory exists.
109+
* @param src source directory
110+
* @param dest destination directory
111+
* @throws IOException on error
112+
*/
107113
public void copyDirectory(Path src, Path dest) throws IOException {
108114
try (Stream<Path> stream = Files.walk(src)) {
109115
stream.forEach(sourceFile -> {
@@ -112,8 +118,14 @@ public void copyDirectory(Path src, Path dest) throws IOException {
112118
}
113119
try {
114120
Path destRelativePath = getDestinationRelativePath(src, sourceFile);
115-
Files.copy(sourceFile, dest.resolve(destRelativePath.toString()),
116-
REPLACE_EXISTING, COPY_ATTRIBUTES);
121+
Path destPath = dest.resolve(destRelativePath);
122+
if (Files.isDirectory(sourceFile)) {
123+
if (!Files.exists(destPath)) {
124+
Files.createDirectory(destPath);
125+
}
126+
return;
127+
}
128+
Files.copy(sourceFile, destPath, REPLACE_EXISTING, COPY_ATTRIBUTES);
117129
} catch (Exception e) {
118130
throw new RuntimeException(e);
119131
}

0 commit comments

Comments
 (0)