From cb592e552d70bf5032920ea7a4208f1b6a3f08de Mon Sep 17 00:00:00 2001 From: Ray Plante Date: Thu, 30 Apr 2020 14:08:34 -0400 Subject: [PATCH] publish: midas: remove Checksum entries for removed files --- python/nistoar/pdr/preserv/bagger/midas.py | 3 ++- .../tests/nistoar/pdr/preserv/bagger/test_midas.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/python/nistoar/pdr/preserv/bagger/midas.py b/python/nistoar/pdr/preserv/bagger/midas.py index 8d0eaea01..6bcf0465c 100644 --- a/python/nistoar/pdr/preserv/bagger/midas.py +++ b/python/nistoar/pdr/preserv/bagger/midas.py @@ -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']): diff --git a/python/tests/nistoar/pdr/preserv/bagger/test_midas.py b/python/tests/nistoar/pdr/preserv/bagger/test_midas.py index 5d0fce2bd..64bf262f1 100644 --- a/python/tests/nistoar/pdr/preserv/bagger/test_midas.py +++ b/python/tests/nistoar/pdr/preserv/bagger/test_midas.py @@ -233,6 +233,10 @@ 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() @@ -240,19 +244,29 @@ def test_ensure_res_metadata_wremove(self): # 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(