diff --git a/folder.py b/folder.py index f5ad0dd43..6cb88a9dd 100644 --- a/folder.py +++ b/folder.py @@ -204,6 +204,7 @@ def precheck_folder_secure(ctx, coll): found, last_run = get_last_run_time(ctx, coll) if (not correct_copytovault_start_status(ctx, coll) + or not correct_copytovault_start_location(coll) or not misc.last_run_time_acceptable(coll, found, last_run, config.vault_copy_backoff_time)): return False @@ -318,6 +319,18 @@ def correct_copytovault_start_status(ctx, coll): return False +def correct_copytovault_start_location(coll): + """Confirm that the folder to be copied is in the correct location. + For example: in a research or deposit folder and not in the trash. + + :param coll: Source collection (folder being secured) + + :returns: True when a valid start location + """ + space, _, _, _ = pathutil.info(coll) + return space in (pathutil.Space.RESEARCH, pathutil.Space.DEPOSIT) + + def get_last_run_time(ctx, coll): """Get the last run time, if found""" found = False @@ -420,9 +433,8 @@ def folder_secure_set_retry(ctx, coll): if new_retry_count > config.vault_copy_max_retries: folder_secure_fail(ctx, coll) send_folder_secure_notification(ctx, coll, "Data package failed to copy to vault after maximum retries") - else: - if not folder_secure_set_retry_avus(ctx, coll, new_retry_count): - send_folder_secure_notification(ctx, coll, "Failed to set retry state on data package") + elif not folder_secure_set_retry_avus(ctx, coll, new_retry_count): + send_folder_secure_notification(ctx, coll, "Failed to set retry state on data package") def folder_secure_set_retry_avus(ctx, coll, retry_count): diff --git a/vault_archive.py b/vault_archive.py index 4794b1b1f..893d67b56 100644 --- a/vault_archive.py +++ b/vault_archive.py @@ -134,11 +134,11 @@ def create_archive(ctx, coll): def extract_archive(ctx, coll): while True: state = ctx.dmattr(package_archive_path(ctx, coll), config.data_package_archive_fqdn, "")["arguments"][2] - if state != "UNM" and state != "MIG": + if state not in ("UNM", "MIG"): break time.sleep(10) - if state != "DUL" and state != "REG" and state != "INV": + if state not in ("DUL", "REG", "INV"): log.write(ctx, "Archive of data package <{}> is not available, state is <{}>".format(coll, state)) raise Exception("Archive is not available")