diff --git a/src/bagit/consts.rs b/src/bagit/consts.rs index bef6d36..a8b391b 100644 --- a/src/bagit/consts.rs +++ b/src/bagit/consts.rs @@ -54,10 +54,11 @@ pub const LABEL_BAG_GROUP_IDENTIFIER: &str = "Bag-Group-Identifier"; pub const LABEL_BAG_COUNT: &str = "Bag-Count"; pub const LABEL_INTERNAL_SENDER_IDENTIFIER: &str = "Internal-Sender-Identifier"; pub const LABEL_INTERNAL_SENDER_DESCRIPTION: &str = "Internal-Sender-Description"; +pub const LABEL_BAGIT_PROFILE_IDENTIFIER: &str = "BagIt-Profile-Identifier"; /// Lookup table that indicates if a reserved bag-info label is repeatable. All label names are /// lowercased here. -pub const LABEL_REPEATABLE: [(&str, bool); 15] = [ +pub const LABEL_REPEATABLE: [(&str, bool); 16] = [ ("bagging-date", false), ("payload-oxum", false), ("bag-software-agent", false), @@ -73,4 +74,5 @@ pub const LABEL_REPEATABLE: [(&str, bool); 15] = [ ("bag-count", false), ("internal-sender-identifier", true), ("internal-sender-description", true), + ("bagit-profile-identifier", true), ]; diff --git a/src/bagit/tag.rs b/src/bagit/tag.rs index 1a4e10a..0c24f82 100644 --- a/src/bagit/tag.rs +++ b/src/bagit/tag.rs @@ -294,6 +294,14 @@ impl BagInfo { self.get_tags(LABEL_INTERNAL_SENDER_DESCRIPTION) } + pub fn add_bagit_profile_identifier>(&mut self, value: S) -> Result<()> { + self.add_repeatable(LABEL_BAGIT_PROFILE_IDENTIFIER, value) + } + + pub fn bagit_profile_identifier(&self) -> Box + '_> { + self.get_tags(LABEL_BAGIT_PROFILE_IDENTIFIER) + } + /// Adds a new tag by first removing all existing tags with the same label. fn add_non_repeatable, S: AsRef>( &mut self, diff --git a/src/bin/bagr.rs b/src/bin/bagr.rs index 481990e..13d19f3 100644 --- a/src/bin/bagr.rs +++ b/src/bin/bagr.rs @@ -134,6 +134,10 @@ pub struct BagCmd { #[clap(long, value_name = "INT_SENDER_DESC", multiple_occurrences = true)] pub internal_sender_description: Vec, + /// Value of the BagIt-Profile-Identifier tag in bag-info.txt. Maybe repeated. + #[clap(long, value_name = "PROFILE_ID", multiple_occurrences = true)] + pub bagit_profile_identifier: Vec, + /// A custom tag to add to bag-info.txt. Tags must be formatted as LABEL:VALUE #[clap(short, long, value_name = "LABEL:VALUE", multiple_occurrences = true)] pub tag: Vec, @@ -290,6 +294,9 @@ fn exec_bag(cmd: BagCmd) -> Result { for id in cmd.internal_sender_identifier { bag_info.add_internal_sender_identifier(id)?; } + for profile in cmd.bagit_profile_identifier { + bag_info.add_bagit_profile_identifier(profile)?; + } for tag in cmd.tag { let split = tag.split_once(':').ok_or_else(|| InvalidTagLine { diff --git a/tests/cmd/bag/basic-all-tags.out/bag-info.txt b/tests/cmd/bag/basic-all-tags.out/bag-info.txt index a568695..b4986d3 100644 --- a/tests/cmd/bag/basic-all-tags.out/bag-info.txt +++ b/tests/cmd/bag/basic-all-tags.out/bag-info.txt @@ -21,6 +21,8 @@ Internal-Sender-Description: int-desc-1 Internal-Sender-Description: int-desc-2 Internal-Sender-Identifier: int-id1 Internal-Sender-Identifier: int-id2 +BagIt-Profile-Identifier: file://profile1.json +BagIt-Profile-Identifier: file://profile2.json custom-1: value-1 custom-2: value-2 custom-2: value-3 diff --git a/tests/cmd/bag/basic-all-tags.out/tagmanifest-sha512.txt b/tests/cmd/bag/basic-all-tags.out/tagmanifest-sha512.txt index 84c12e8..d9b8c9f 100644 --- a/tests/cmd/bag/basic-all-tags.out/tagmanifest-sha512.txt +++ b/tests/cmd/bag/basic-all-tags.out/tagmanifest-sha512.txt @@ -1,3 +1,3 @@ -d5a96223a41edd82fe9c50ca226fcb9de1b12872b29e75497742053e176231e72c16d53e6c5d8e191d86333f9b3e3a2e6f1665b99514b02a0170b36453fb2fb9 bag-info.txt +a3e9d5d6ce9ad246085a41d23d3d656f4a073027a291422c908e306ee4cc391d94eab7947bde526cf49d7d560c384399a8053916e6224f0cd72dd388b34b4142 bag-info.txt 1d73ae108d4109b61f56698a5e19ee1f8947bdf8940bbce6adbe5e0940c2363caace6a547b4f1b3ec6a4fd2b7fa845e9cb9d28823bc72c59971718bb26f2fbd8 bagit.txt 49ed4e071201e8a98e4a01497496916259fffe296e85a6a0d422934c5021a3ff2482feb77d0a4d948a4ddd5204c7f83c4c7b6416c9a90d649185388e2430f8fb manifest-sha512.txt diff --git a/tests/cmd/bag/basic-all-tags.toml b/tests/cmd/bag/basic-all-tags.toml index b42a74b..d19a223 100644 --- a/tests/cmd/bag/basic-all-tags.toml +++ b/tests/cmd/bag/basic-all-tags.toml @@ -27,6 +27,8 @@ bag \ --internal-sender-identifier int-id2 \ --internal-sender-description int-desc-1 \ --internal-sender-description int-desc-2 \ +--bagit-profile-identifier file://profile1.json \ +--bagit-profile-identifier file://profile2.json \ --tag custom-1:value-1 \ --tag custom-2:value-2 \ --tag custom-2:value-3"""