Skip to content

Updating bag-info.txt makes bag invalid #32

Closed

Description

@tongwang

When a bag has a tag manifest file created using an algorithm other than md5, such as the following bag:

bag-info.txt         
bagit.txt            
data                 
manifest-sha1.txt    
tagmanifest-sha1.txt

Updating bag info results in an invalid bag:

>>> import bagit
>>> bag = bagit.Bag('/Users/twan/edeposit/edeposit/apps/signiant/tests/SR1-4444_20140611200739')
>>> bag.is_valid()
True
>>> bag.info['External-Identifier']='xyz'
>>> bag.save()
>>> bag.is_valid()
False

The problem looks like it assumes the tag manifest file always uses md5.

# Update tag-manifest for changes to manifest & bag-info files
        _make_tagmanifest_file('tagmanifest-md5.txt', self.path)

Activity

  1. added a commit that references this issue on Sep 19, 2014
  2. edsu commented on Sep 19, 2014

    @edsu
    Contributor

    @tongwang I added a test case that (I thought) would exercise the problem, but it passes. Can you get it to fail? Also, what do you see as output when you run validate()?

  3. tongwang commented on Sep 19, 2014

    @tongwang
    Author

    @edsu the issue is that in the test case even you create the bag with "sha1", the tag manifest file is still in md5. It is hardwired to md5:

    def _make_tagmanifest_file(tagmanifest_file, bag_dir):
        files = [f for f in listdir(bag_dir) if isfile(join(bag_dir, f))]
        checksums = []
        for f in files:
            if f == tagmanifest_file:
                continue
            fh = open(join(bag_dir, f), 'rb')
            m = hashlib.md5()
            while True:
                bytes = fh.read(16384)
                if not bytes:
                    break
                m.update(bytes)
            checksums.append((m.hexdigest(), f))
            fh.close()
    
        with open(join(bag_dir, tagmanifest_file), 'w') as tagmanifest:
            for digest, filename in checksums:
                tagmanifest.write('%s %s\n' % (digest, filename))
    
  4. edsu commented on Sep 19, 2014

    @edsu
    Contributor

    Ouch! I thought there were tests for sha1 manifest generation. I'll check.

  5. edsu commented on Sep 19, 2014

    @edsu
    Contributor

    It does seem wrong that it would always write a tagmanifest-md5.txt even if you have a manifest-sha1.txt ; but why does this make the bag invalid? Can you construct a test case that fails?

  6. edsu commented on Sep 19, 2014

    @edsu
    Contributor

    Oh, in your example you probably have a bag created with another tool which has a tagmanifest-sha1.txt that is not being updated?

  7. edsu commented on Sep 19, 2014

    @edsu
    Contributor

    Ok, I've got a test case that is failing now over here.

  8. tongwang commented on Sep 19, 2014

    @tongwang
    Author

    Yes, the existing tagmanifest-sha1.txt is not updated, which fails validation.

  9. added a commit that references this issue on Sep 19, 2014
    27176ee
  10. edsu commented on Sep 19, 2014

    @edsu
    Contributor

    @tongwang can you give my latest branch a try? https://github.com/edsu/bagit/tree/issue32 I believe I fixed the issue.

  11. tongwang commented on Sep 19, 2014

    @tongwang
    Author

    @edsu it works great! Thank you for the quick fix.

  12. edsu commented on Sep 19, 2014

    @edsu
    Contributor

    Awesome. I'll send a pull request, maybe you could merge it in (since I no longer work at LC)?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions