Skip to content

Commit

Permalink
BagIt Support - Improved ignored files for BagIt handler
Browse files Browse the repository at this point in the history
  • Loading branch information
abujeda committed Jul 16, 2022
1 parent ba0c2ac commit 0f4e6f1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class BagItFileHandlerPostProcessor {

private static final Logger logger = Logger.getLogger(BagItFileHandlerPostProcessor.class.getCanonicalName());

public static final List<String> FILES_TO_IGNORE = Arrays.asList("__", "._", ".DS_Store", "._.DS_Store");
public static final List<String> FILES_TO_IGNORE = Arrays.asList("__", "._", ".DS_Store");

public List<DataFile> process(List<DataFile> items) {
if(items == null) {
Expand All @@ -26,7 +26,11 @@ public List<DataFile> process(List<DataFile> items) {

for(DataFile item: items) {
String fileName = item.getCurrentName();
if(FILES_TO_IGNORE.contains(fileName)) {
if(fileName == null || fileName.isEmpty()) {
continue;
}

if(FILES_TO_IGNORE.stream().anyMatch(prefix -> fileName.startsWith(prefix))) {
logger.fine(String.format("action=BagItFileHandlerPostProcessor result=ignore-entry file=%s", fileName));
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,43 @@ public void should_return_null_when_datafiles_are_null() throws Exception {
@Test
public void should_ignore_mac_control_files() throws Exception {
String bagEntry = UUID.randomUUID().toString();
String macFile01 = "__";
String macFile02 = "._";
String macFile03 = ".DS_Store";
String macFile04 = "._.DS_Store";
List<DataFile> dataFiles = createDataFiles(bagEntry, macFile01, macFile02, macFile03, macFile04);
List<DataFile> dataFiles = createDataFiles(bagEntry, macFile03, macFile04);

List<DataFile> result = target.process(dataFiles);
MatcherAssert.assertThat(result.size(), Matchers.is(1));
MatcherAssert.assertThat(result.get(0).getCurrentName(), Matchers.is(bagEntry));
}

@Test
public void should_ignore_empty_files() throws Exception {
String bagEntry = UUID.randomUUID().toString();
String fileToIgnore = "";
List<DataFile> dataFiles = createDataFiles(bagEntry, fileToIgnore);

List<DataFile> result = target.process(dataFiles);
MatcherAssert.assertThat(result.size(), Matchers.is(1));
MatcherAssert.assertThat(result.get(0).getCurrentName(), Matchers.is(bagEntry));
}

@Test
public void should_ignore_files_that_start_with_dot_underscore() throws Exception {
String bagEntry = UUID.randomUUID().toString();
String fileToIgnore = "._FileNameToIgnore";
List<DataFile> dataFiles = createDataFiles(bagEntry, fileToIgnore);

List<DataFile> result = target.process(dataFiles);
MatcherAssert.assertThat(result.size(), Matchers.is(1));
MatcherAssert.assertThat(result.get(0).getCurrentName(), Matchers.is(bagEntry));
}

@Test
public void should_ignore_files_that_start_with_double_underscore() throws Exception {
String bagEntry = UUID.randomUUID().toString();
String fileToIgnore = "__FileNameToIgnore";
String validFile = "validName";
List<DataFile> dataFiles = createDataFiles(bagEntry, fileToIgnore);

List<DataFile> result = target.process(dataFiles);
MatcherAssert.assertThat(result.size(), Matchers.is(1));
Expand Down

0 comments on commit 0f4e6f1

Please sign in to comment.