Skip to content

Add convenience methods for payload management#209

Open
cgaudin wants to merge 8 commits into
LibraryOfCongress:masterfrom
museebolo:upstream/payload-management
Open

Add convenience methods for payload management#209
cgaudin wants to merge 8 commits into
LibraryOfCongress:masterfrom
museebolo:upstream/payload-management

Conversation

@cgaudin

@cgaudin cgaudin commented Jun 17, 2026

Copy link
Copy Markdown

Summary

This PR adds a small set of convenience methods for common payload management operations.

Currently, modifying a Bag payload typically requires manually copying or removing files inside the data directory and then calling:

bag.save(manifests=True)

The new helper methods provide a higher-level API for these common operations while reusing the existing manifest generation and validation logic.

Added APIs

Bag.update_payload()

Convenience wrapper around:

bag.save(manifests=True)

to rebuild payload manifests, tag manifests and update Payload-Oxum.

Bag.payload_oxum()

Returns the current payload size and file count as a tuple:

bytes_count, file_count = bag.payload_oxum()

Bag.add_payload()

Adds files or directories to the payload and updates manifests.

Examples:

bag.add_payload("file.txt")
bag.add_payload("image.jpg", dest="images/image.jpg")
bag.add_payload("directory")

Bag.remove_payload()

Removes payload files or directories and updates manifests.

Examples:

bag.remove_payload("data/file.txt")
bag.remove_payload("data/images", recursive=True)

Motivation

These helpers simplify common Bag modification workflows and reduce the amount of boilerplate required when applications need to add, remove, or replace payload content programmatically.

All functionality is implemented on top of the existing BagIt logic and existing tests continue to pass.

Testing

New unit tests have been added for:

  • payload oxum calculation
  • payload updates
  • file addition
  • file removal
  • destination support
  • recursive directory addition
  • recursive directory removal
  • path safety validation

Comment thread test.py Fixed
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants