diff --git a/xnat_ingest/session.py b/xnat_ingest/session.py index 90d20c0..4ee639d 100644 --- a/xnat_ingest/session.py +++ b/xnat_ingest/session.py @@ -381,20 +381,21 @@ def save(self, save_dir: Path) -> "ImagingSession": resources_dict = {} for resource_name, fileset in scan.resources.items(): resource_dir = save_dir / f"{scan.id}-{scan.type}" / resource_name - if fileset.parent.is_relative_to(resource_dir): + # If data is not already in the save directory, copy it there + if not fileset.parent.is_relative_to(resource_dir): resource_dir.mkdir(parents=True, exist_ok=True) fileset_copy = fileset.copy( resource_dir, mode=fileset.CopyMode.hardlink_or_copy ) self.scans[scan.id].resources[resource_name] = fileset_copy - resources_dict[resource_name] = { - "datatype": to_mime(fileset, official=False), - "fspaths": [ - # Ensure it is a relative path using POSIX forward slashes - str(p.relative_to(save_dir)).replace("\\", "/") - for p in fileset_copy.fspaths - ], - } + resources_dict[resource_name] = { + "datatype": to_mime(fileset, official=False), + "fspaths": [ + # Ensure it is a relative path using POSIX forward slashes + str(p.relative_to(save_dir)).replace("\\", "/") + for p in fileset_copy.fspaths + ], + } dct["scans"][scan.id] = { "type": scan.type, "resources": resources_dict,