Skip to content

Commit

Permalink
Merge pull request #133 from usnistgov/fix/del-sha-comp
Browse files Browse the repository at this point in the history
publish bug fix: remove sha file entries from NERDm when files are remove
  • Loading branch information
RayPlante authored May 5, 2020
2 parents 925a6df + cb592e5 commit d2ed297
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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

0 comments on commit d2ed297

Please sign in to comment.