Skip to content

Commit

Permalink
add bagit profile id tag
Browse files Browse the repository at this point in the history
  • Loading branch information
pwinckles committed Feb 22, 2022
1 parent 296303e commit 776a395
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/bagit/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
];
8 changes: 8 additions & 0 deletions src/bagit/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@ impl BagInfo {
self.get_tags(LABEL_INTERNAL_SENDER_DESCRIPTION)
}

pub fn add_bagit_profile_identifier<S: AsRef<str>>(&mut self, value: S) -> Result<()> {
self.add_repeatable(LABEL_BAGIT_PROFILE_IDENTIFIER, value)
}

pub fn bagit_profile_identifier(&self) -> Box<dyn Iterator<Item = &Tag> + '_> {
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<L: AsRef<str>, S: AsRef<str>>(
&mut self,
Expand Down
7 changes: 7 additions & 0 deletions src/bin/bagr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ pub struct BagCmd {
#[clap(long, value_name = "INT_SENDER_DESC", multiple_occurrences = true)]
pub internal_sender_description: Vec<String>,

/// 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<String>,

/// 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<String>,
Expand Down Expand Up @@ -290,6 +294,9 @@ fn exec_bag(cmd: BagCmd) -> Result<Bag> {
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 {
Expand Down
2 changes: 2 additions & 0 deletions tests/cmd/bag/basic-all-tags.out/bag-info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/cmd/bag/basic-all-tags.out/tagmanifest-sha512.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
d5a96223a41edd82fe9c50ca226fcb9de1b12872b29e75497742053e176231e72c16d53e6c5d8e191d86333f9b3e3a2e6f1665b99514b02a0170b36453fb2fb9 bag-info.txt
a3e9d5d6ce9ad246085a41d23d3d656f4a073027a291422c908e306ee4cc391d94eab7947bde526cf49d7d560c384399a8053916e6224f0cd72dd388b34b4142 bag-info.txt
1d73ae108d4109b61f56698a5e19ee1f8947bdf8940bbce6adbe5e0940c2363caace6a547b4f1b3ec6a4fd2b7fa845e9cb9d28823bc72c59971718bb26f2fbd8 bagit.txt
49ed4e071201e8a98e4a01497496916259fffe296e85a6a0d422934c5021a3ff2482feb77d0a4d948a4ddd5204c7f83c4c7b6416c9a90d649185388e2430f8fb manifest-sha512.txt
2 changes: 2 additions & 0 deletions tests/cmd/bag/basic-all-tags.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

0 comments on commit 776a395

Please sign in to comment.