Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publish bug fix: remove sha file entries from NERDm when files are remove #133

Merged
merged 1 commit into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/nistoar/pdr/preserv/bagger/midas.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ def has_cmp_with_path(comps, path):

resmd = self.bagbldr.bag.nerdm_record(False)
for cmp in resmd.get('components', []):
if any([':DataFile' in t for t in cmp.get('@type',[])]) and \
if any([(':DataFile' in t or ':ChecksumFile' in t)
for t in cmp.get('@type',[])]) and \
cmp.get('filepath') and \
not has_cmp_with_path(podnerd.get('components', []),
cmp['filepath']):
Expand Down
14 changes: 14 additions & 0 deletions python/tests/nistoar/pdr/preserv/bagger/test_midas.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,26 +233,40 @@ def test_ensure_res_metadata(self):
self.assertEqual(data['@context'][1]['@base'], data['@id'])

def test_ensure_res_metadata_wremove(self):
# don't use upload version of pod file
self.bagr = midas.MIDASMetadataBagger(self.midasid, self.bagparent,
self.revdir, None)

self.assertFalse(os.path.exists(self.bagdir))
self.assertIsNone(self.bagr.inpodfile)
self.bagr.ensure_res_metadata()

# make sure file components were registered
self.assertTrue(os.path.isfile(
self.bagr.bagbldr.bag.nerd_file_for("trial1.json")))
self.assertTrue(os.path.isfile(
self.bagr.bagbldr.bag.nerd_file_for("trial1.json.sha256")))

# add metadata for a data file that doesn't exist in the source dir
self.bagr.bagbldr.register_data_file(os.path.join("gold","trial5.json"),
os.path.join(self.revdir,
self.midasid[32:],
"trial1.json") )
self.bagr.bagbldr.register_data_file(os.path.join("gold","trial5.json.sha256"),
os.path.join(self.revdir,
self.midasid[32:],
"trial1.json.sha256") )
self.assertTrue(os.path.isfile(
self.bagr.bagbldr.bag.nerd_file_for("gold/trial5.json")))
self.assertTrue(os.path.isfile(
self.bagr.bagbldr.bag.nerd_file_for("gold/trial5.json.sha256")))

# now watch it get erased
self.bagr.ensure_res_metadata(force=True)
self.assertTrue(not os.path.exists(
self.bagr.bagbldr.bag.nerd_file_for("gold/trial5.json")))
self.assertTrue(not os.path.exists(
self.bagr.bagbldr.bag.nerd_file_for("gold/trial5.json.sha256")))
self.assertTrue(not os.path.exists(
self.bagr.bagbldr.bag.nerd_file_for("gold")))
self.assertTrue(not os.path.exists(
Expand Down