Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed .bagit to be version 2.0 and implemented 1.0 spec that all ma…
…nifest must list all files
- Loading branch information
1 parent
1e67c03
commit f1a6807
Showing
28 changed files
with
132 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...main/java/gov/loc/repository/bagit/verify/AbstractPayloadFileExistsInManifestsVistor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package gov.loc.repository.bagit.verify; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.FileVisitResult; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.nio.file.SimpleFileVisitor; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Implements {@link SimpleFileVisitor} to ensure that the encountered file is in one of the manifests. | ||
*/ | ||
abstract public class AbstractPayloadFileExistsInManifestsVistor extends SimpleFileVisitor<Path> { | ||
protected static final Logger logger = LoggerFactory.getLogger(AbstractPayloadFileExistsInManifestsVistor.class); | ||
protected transient final boolean ignoreHiddenFiles; | ||
|
||
public AbstractPayloadFileExistsInManifestsVistor(final boolean ignoreHiddenFiles) { | ||
this.ignoreHiddenFiles = ignoreHiddenFiles; | ||
} | ||
|
||
@Override | ||
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException { | ||
if(ignoreHiddenFiles && Files.isHidden(dir) || dir.endsWith(Paths.get(".bagit"))){ | ||
logger.debug("Skipping [{}] cause it is a hidden folder", dir); | ||
return FileVisitResult.SKIP_SUBTREE; | ||
} | ||
|
||
return FileVisitResult.CONTINUE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/gov/loc/repository/bagit/verify/PayloadFileExistsInAllManifestsVistor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package gov.loc.repository.bagit.verify; | ||
|
||
import java.nio.file.FileVisitResult; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.SimpleFileVisitor; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
import java.util.Set; | ||
|
||
import gov.loc.repository.bagit.domain.Manifest; | ||
import gov.loc.repository.bagit.exceptions.FileNotInManifestException; | ||
|
||
/** | ||
* Implements {@link SimpleFileVisitor} to ensure that the encountered file is in one of the manifests. | ||
*/ | ||
public class PayloadFileExistsInAllManifestsVistor extends AbstractPayloadFileExistsInManifestsVistor { | ||
private transient final Set<Manifest> manifests; | ||
|
||
public PayloadFileExistsInAllManifestsVistor(final Set<Manifest> manifests, final boolean ignoreHiddenFiles) { | ||
super(ignoreHiddenFiles); | ||
this.manifests = manifests; | ||
} | ||
|
||
@Override | ||
public FileVisitResult visitFile(final Path path, final BasicFileAttributes attrs)throws FileNotInManifestException{ | ||
if(Files.isRegularFile(path)){ | ||
for(final Manifest manifest : manifests){ | ||
if(!manifest.getFileToChecksumMap().keySet().contains(path.normalize())){ | ||
throw new FileNotInManifestException("File " + path + " is in the payload directory but isn't listed in manifest manifest-" + manifest.getAlgorithm().getBagitName() + ".txt"); | ||
} | ||
} | ||
} | ||
logger.debug("[{}] is in all manifests", path); | ||
return FileVisitResult.CONTINUE; | ||
} | ||
} |
23 changes: 3 additions & 20 deletions
23
...fy/PayloadFileExistsInManifestVistor.java → ...FileExistsInAtLeastOneManifestVistor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...resources/bags/v0_98/bag/.bagit/bagit.txt → .../resources/bags/v2_0/bag/.bagit/bagit.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
BagIt-Version: 0.98 | ||
BagIt-Version: 2.0 | ||
Tag-File-Character-Encoding: UTF-8 |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...bags/v0_98/bag/.bagit/tagmanifest-md5.txt → .../bags/v2_0/bag/.bagit/tagmanifest-md5.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
32f027866d7141a0eaeee6e0cc5123f0 .bagit/bagit.txt | ||
2cdf8709d5921dd1a6422c7e0a9dc017 .bagit/bagit.txt | ||
9ee76b9f81aa504f2af0ef8f3e832d81 .bagit/manifest-md5.txt | ||
68b1dabaea8770a0e9411dc5d99341f9 .bagit/bag-info.txt |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
src/test/resources/notAllFilesListedInAllManifestsBag/bag-info.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Bag-Software-Agent: bagit.py v1.5.4 <http://github.com/libraryofcongress/bagit-python> | ||
Bagging-Date: 2016-12-23 | ||
Payload-Oxum: 0.3 |
2 changes: 2 additions & 0 deletions
2
src/test/resources/notAllFilesListedInAllManifestsBag/bagit.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
BagIt-Version: 1.0 | ||
Tag-File-Character-Encoding: UTF-8 |
Empty file.
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions
3
src/test/resources/notAllFilesListedInAllManifestsBag/manifest-md5.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
d41d8cd98f00b204e9800998ecf8427e data/bar | ||
d41d8cd98f00b204e9800998ecf8427e data/foo | ||
d41d8cd98f00b204e9800998ecf8427e data/ham |
2 changes: 2 additions & 0 deletions
2
src/test/resources/notAllFilesListedInAllManifestsBag/manifest-sha256.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 data/bar | ||
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 data/foo |
3 changes: 3 additions & 0 deletions
3
src/test/resources/notAllFilesListedInAllManifestsBag/tagmanifest-md5.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
121f38b01566d73cc41abaf5f71cc6c6 bag-info.txt | ||
eaa2c609ff6371712f623f5531945b44 bagit.txt | ||
35a2deeb5237cad4460aff97718ae00f manifest-md5.txt |