Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/trestle/core/commands/merge_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def test_merge_expanded_metadata_into_catalog(testdata_dir, tmp_trestle_dir, kee
expected_plan.add_action(write_destination_action)
delete_element_action = RemovePathAction(metadata_file)
expected_plan.add_action(delete_element_action)
delete_metadata_dir_action = RemovePathAction(metadata_dir.resolve())
expected_plan.add_action(delete_metadata_dir_action)

# Call merge()
generated_plan = MergeCmd.merge(Path.cwd(), ElementPath('catalog.metadata'), tmp_trestle_dir)
Expand Down
11 changes: 8 additions & 3 deletions trestle/core/commands/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ def merge(cls, effective_cwd: Path, element_path: ElementPath, trestle_root: Pat
write_destination_action = WriteFileAction(
destination_model_path, merged_destination_element, content_type=file_type
)
# FIXME this will delete metadata.json but it will leave metadata/roles/roles.*
# need to clean up all lower dirs
trace.log(f'remove path action {target_model_filename}')
delete_target_action = RemovePathAction(target_model_filename)

Expand All @@ -203,6 +201,13 @@ def merge(cls, effective_cwd: Path, element_path: ElementPath, trestle_root: Pat
plan.add_action(write_destination_action)
plan.add_action(delete_target_action)

# TODO: Destination model directory is empty or already merged? Then clean up.
# If merge loaded from <alias>.json and a sibling distributed folder <alias>/ exists,
# remove it as well to avoid leaving stale decomposed content behind.
if target_model_filename.is_file():
distributed_target_dir = target_model_filename.with_suffix('')
if distributed_target_dir.exists() and distributed_target_dir.is_dir():
trace.log(f'remove distributed target dir action {distributed_target_dir}')
delete_distributed_target_action = RemovePathAction(distributed_target_dir)
plan.add_action(delete_distributed_target_action)

return plan
Loading