diff --git a/src/main/java/edu/unc/lib/boxc/migration/cdm/services/SourceFileService.java b/src/main/java/edu/unc/lib/boxc/migration/cdm/services/SourceFileService.java index 89c0d24d..9200c5cb 100644 --- a/src/main/java/edu/unc/lib/boxc/migration/cdm/services/SourceFileService.java +++ b/src/main/java/edu/unc/lib/boxc/migration/cdm/services/SourceFileService.java @@ -20,6 +20,7 @@ import org.slf4j.Logger; import java.io.BufferedWriter; +import java.io.File; import java.io.IOException; import java.io.Reader; import java.nio.file.FileSystems; @@ -222,13 +223,14 @@ private Map> gatherCandidatePaths(GenerateSourceFileMapping Files.walkFileTree(basePath, new SimpleFileVisitor() { @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { - if (pathPattern == null || pathMatcher.matches(path)) { + var relativePath = basePath.relativize(path); + if (pathPattern == null || pathMatcher.matches(relativePath)) { String filename = path.getFileName().toString(); if (options.isLowercaseTemplate()) { filename = filename.toLowerCase(); } List paths = candidatePaths.computeIfAbsent(filename, f -> new ArrayList<>()); - paths.add(basePath.relativize(path).toString()); + paths.add(relativePath.toString()); } return FileVisitResult.CONTINUE; } diff --git a/src/test/java/edu/unc/lib/boxc/migration/cdm/services/SourceFileServiceTest.java b/src/test/java/edu/unc/lib/boxc/migration/cdm/services/SourceFileServiceTest.java index 61cf8f1d..b03b4d88 100644 --- a/src/test/java/edu/unc/lib/boxc/migration/cdm/services/SourceFileServiceTest.java +++ b/src/test/java/edu/unc/lib/boxc/migration/cdm/services/SourceFileServiceTest.java @@ -190,6 +190,26 @@ public void generateNestedMatchesTest() throws Exception { assertMappedDatePresent(); } + @Test + public void generateBasePathMatchesTest() throws Exception { + testHelper.indexExportData("mini_gilmer"); + GenerateSourceFileMappingOptions options = makeDefaultOptions(); + // test source files are in the source subdirectory of the base path + options.setPathPattern("source/*.tif"); + // add nested path + testHelper.addSourceFile("nested/path/276_182_E.tif"); + Path basePath = testHelper.addSourceFile("276_183_E.tif"); + + service.generateMapping(options); + + SourceFilesInfo info = service.loadMappings(); + assertMappingPresent(info, "25", "276_182_E.tif", null); + assertMappingPresent(info, "26", "276_183_E.tif", basePath); + assertMappingPresent(info, "27", "276_203_E.tif", null); + + assertMappedDatePresent(); + } + @Test public void generateTransformedNestedMatchTest() throws Exception { testHelper.indexExportData("mini_gilmer"); @@ -822,11 +842,6 @@ private void assertExceptionContains(String expected, Exception e) { "Expected message exception to contain '" + expected + "', but was: " + e.getMessage()); } - private void setIndexedDate() throws Exception { - project.getProjectProperties().setIndexedDate(Instant.now()); - ProjectPropertiesSerialization.write(project); - } - private void assertMappedDatePresent() throws Exception { MigrationProjectProperties props = ProjectPropertiesSerialization.read(project.getProjectPropertiesPath()); assertNotNull(props.getSourceFilesUpdatedDate());