Skip to content

Commit 1e67c03

Browse files
committed
refs #61 - added more os specific files to warn about
1 parent 512334f commit 1e67c03

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/main/java/gov/loc/repository/bagit/conformance/BagLinter.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ public class BagLinter {
3737
private static final Version LATEST_BAGIT_VERSION = new Version(0, 97);
3838
private static final String THUMBS_DB_FILE = "[Tt][Hh][Uu][Mm][Bb][Ss]\\.[Dd][Bb]";
3939
private static final String DS_STORE_FILE = "\\.[Dd][Ss]_[Ss][Tt][Oo][Rr][Ee]";
40-
private static final String OS_FILES_REGEX = ".*data/(" + THUMBS_DB_FILE + "|" + DS_STORE_FILE + ")";
40+
private static final String SPOTLIGHT_FILE = "\\.[Ss][Pp][Oo][Tt][Ll][Ii][Gg][Hh][Tt]-[Vv]100";
41+
private static final String TRASHES_FILE = "\\.(_.)?[Tt][Rr][Aa][Ss][Hh][Ee][Ss]";
42+
private static final String FS_EVENTS_FILE = "\\.[Ff][Ss][Ee][Vv][Ee][Nn][Tt][Ss][Dd]";
43+
private static final String OS_FILES_REGEX = ".*data/(" + THUMBS_DB_FILE + "|" + DS_STORE_FILE + "|" + SPOTLIGHT_FILE + "|" + TRASHES_FILE + "|" + FS_EVENTS_FILE + ")";
4144

4245
private final BagReader reader;
4346

@@ -308,4 +311,12 @@ private void checkForPayloadOxumMetadata(final Path bagitDir, final Charset enco
308311
public BagReader getReader() {
309312
return reader;
310313
}
314+
315+
/**
316+
* Used only for unit testing
317+
* @return the regex for os specific files to warn about
318+
*/
319+
protected static String getOsFilesRegex() {
320+
return OS_FILES_REGEX;
321+
}
311322
}

src/main/java/gov/loc/repository/bagit/conformance/BagitWarning.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public enum BagitWarning {
1919
"contained in the GNU Coreutils package (md5sum, sha1sum, etc.), collectively referred to here as 'md5sum'. "
2020
+ "This creates slight differences in generated manifests that can cause problems in some implementations."),
2121
OLD_BAGIT_VERSION("The bagit specification version is not the newest. Consider converting to the latest version."),
22-
OS_SPECIFIC_FILES("Files created by the operating system (OS) for its own use. They are non-protable across OS versions "
23-
+ "and should not be included in any manifest. Examples Thumbs.db on Windows or .DS_Store on OSX"),
22+
OS_SPECIFIC_FILES("Files created by the operating system (OS) for its own use. They are non-portable across OS versions "
23+
+ "and should not be included in any manifest. Examples Thumbs.db on Windows or .DS_Store on OS X"),
2424
PAYLOAD_OXUM_MISSING("It is recommended to always include the Payload-Oxum in the bag metadata "
2525
+ "since it allows for a 'quick verification' of the bag."),
2626
TAG_FILES_ENCODING("It is recommended to always use UTF-8"),

src/test/java/gov/loc/repository/bagit/conformance/BagLinterTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ public void setup(){
3131
sut = new BagLinter(mapping);
3232
}
3333

34+
@Test
35+
public void testOSSpecificFilesRegex(){
36+
String regex = BagLinter.getOsFilesRegex();
37+
String[] osFilesToTest = new String[]{"data/Thumbs.db", "data/.DS_Store", "data/.Spotlight-V100", "data/.Trashes",
38+
"data/._.Trashes", "data/.fseventsd"};
39+
40+
for(String osFileToTest : osFilesToTest){
41+
assertTrue(osFileToTest + " should match regex but it doesn't", osFileToTest.matches(regex));
42+
}
43+
}
44+
3445
@Test
3546
public void testLintBag() throws Exception{
3647
Set<BagitWarning> expectedWarnings = new HashSet<>();

0 commit comments

Comments
 (0)