From 1e9f87a84b4e21c70ebce141ba50d59d0547b8ea Mon Sep 17 00:00:00 2001 From: Douglas Cerna Date: Tue, 11 Feb 2020 10:49:22 -0600 Subject: [PATCH] Remove redundant compression event on reingest This removes a redundant PREMIS compression event in the pointer file of reingested AIPs. --- storage_service/common/tests/test_utils.py | 2 +- storage_service/common/utils.py | 18 ++++++++++-------- storage_service/locations/models/package.py | 13 +++---------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/storage_service/common/tests/test_utils.py b/storage_service/common/tests/test_utils.py index 3d021cbf4..db44a5269 100644 --- a/storage_service/common/tests/test_utils.py +++ b/storage_service/common/tests/test_utils.py @@ -257,7 +257,7 @@ def test_get_format_info(compression, version, extension, program_name, transfor consistent. """ fsentry = FSEntry() - vers, ext, prog_name = utils.get_compression_transforms(fsentry, compression, 1) + vers, ext, prog_name = utils.set_compression_transforms(fsentry, compression, 1) assert version in vers assert ext == extension assert program_name in prog_name diff --git a/storage_service/common/utils.py b/storage_service/common/utils.py index 193d45455..31ad0d2c0 100644 --- a/storage_service/common/utils.py +++ b/storage_service/common/utils.py @@ -474,16 +474,18 @@ def get_compression_event_detail(compression): return event_detail -def get_compression_transforms(aip, compression, transform_order): - """Return command for compressing the package +def set_compression_transforms(aip, compression, transform_order): + """Set transform files based on the compression mechanism. + + Return information for compressing the package + :param aip: metsrw FSEntry representing the AIP :param compression: one of the constants in ``COMPRESSION_ALGORITHMS``. - :param extract_path: target path for the compressed file - :param basename: base name of the file (without extension) - :param full_path: Path of source files - :returns: (command, compressed_filename) where - `command` is the compression command (as a list of strings) - `compressed_filename` is the full path to the compressed file + :param transform_order: initial order for the transforms + :returns: (version, extension, program_name) where + `version` is the version of the program to compress the AIP + `extension` is the file extension of the compressed AIP + `program_name` is the name of the program to compress the AIP """ if compression in (COMPRESSION_7Z_BZIP, COMPRESSION_7Z_LZMA, COMPRESSION_7Z_COPY): if compression == COMPRESSION_7Z_BZIP: diff --git a/storage_service/locations/models/package.py b/storage_service/locations/models/package.py index 6848dd6a1..3835a30ca 100644 --- a/storage_service/locations/models/package.py +++ b/storage_service/locations/models/package.py @@ -2653,16 +2653,9 @@ def _process_pointer_file_for_reingest( # Update pointer file mets = metsrw.METSDocument.fromfile(self.full_pointer_file_path) aip = mets.get_file(type="Archival Information Package") - # Create a new compression event - event_detail = utils.get_compression_event_detail(compression) - compression_event = premis.create_premis_aip_compression_event( - event_detail, "" - ) - # Since a new event has been created based on the new compression - # mechanism we reset the old decompression transforms + # Reset existing decompression transforms before setting new ones + # based on the current compression mechanism self._filter_and_remove_decompression_transforms(aip) - # Add the new compression event - aip.add_premis_event(compression_event) self._update_pointer_file(compression, mets, path=updated_aip_path) elif was_compressed: # AIP used to be compressed, but is no longer so delete pointer file @@ -2722,7 +2715,7 @@ def _update_pointer_file(self, compression, mets, path=None): transform_order = 2 # encryption is a prior transformation else: transform_order = 1 - version, extension, program_name = utils.get_compression_transforms( + version, extension, program_name = utils.set_compression_transforms( aip, compression, transform_order ) transform_count = len(aip.transform_files)