Skip to content

Missing Warning on Creating Bag of a Bag #186

@theatischbein

Description

@theatischbein

When creating a bag of bag I would expect a warning or confirmation if I really want to create a bag of a bag.

In general it should be possible to create a bag of a bag, but I would not consider it a default case.

Reproduction

bag = bagit.make_bag('/tmp/test_bag', {'Contact-Name': 'Thea'})

This creates a bag with all info, manifest files and the data directory

/tmp/test_bag
| - bag-info.txt
| - bagit.txt
| - data
| - manifest-sha256.txt
| - manifest-sha512.txt
| - tagmanifest-sha256.txt
| - tagmanifest-sha512.txt

If I run make_bag on the same folder again

bag_again = bagit.make_bag('/tmp/test_bag', {'Contact-Name': 'Thea})

this creates a bag with all info, manifest files and the data directory of the first level bag

/tmp/test_bag
| - bag-info.txt
| - bagit.txt
| - data
    | - bag-info.txt
    | - bagit.txt
    | - data
    | - manifest-sha256.txt
    | - manifest-sha512.txt
    | - tagmanifest-sha256.txt
    | - tagmanifest-sha512.txt
| - manifest-sha256.txt
| - manifest-sha512.txt
| - tagmanifest-sha256.txt
| - tagmanifest-sha512.txt

Expection

I would expect a warning or even a confirmation, e.g.

>>> bag = bagit.make_bag('/tmp/test_bag', {'Contact-Name': 'Thea'})

>>> bag_again = bagit.make_bag('/tmp/test_bag', {'Contact-Name': 'Thea'})
WARNING: You are creating a bag of a bag. Do you want to continue? [N/y] 

Realization

To achieve this behaviour we would need to detect, if a folder is already a bag.
One way could be to use the class constructor of Bag and catch the case for valid bag, but continue on Manifest not found.

Example for the make_bag function:

https://github.com/LibraryOfCongress/bagit-python/blob/master/bagit.py#L141C1-L143C3

def make_bag(
    bag_dir, bag_info=None, processes=1, checksums=None, checksum=None, encoding="utf-8"
):

    # ....
    try:
        bagit.Bag(bag_dir)
        while True:
            ans = input("WARNING: You are creating a bag of a bag. Do you want to continue? [N/y]")
            if ans.lower() == 'y':
                break
            elif not ans or ans.lower() == 'n':
                raise UserWarning('Aborted')
    
    except Exception as e:
        pass

    # ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions