diff --git a/src/Operations/FindFiles.cc b/src/Operations/FindFiles.cc index a379d2f3..cac84927 100644 --- a/src/Operations/FindFiles.cc +++ b/src/Operations/FindFiles.cc @@ -121,8 +121,10 @@ bool FindFiles(Drover& DICOM_data, bool ret = true; - // Store the original state of the key in the global parameter table. - const auto orig_val = get_as(InvocationMetadata, Key); + // Stow a copy of the original state of the key in the global parameter table. + auto metadata_stow = stow_metadata(InvocationMetadata, {}, Key); + // Automaticaly restores the stowed metadata when exiting this scope. + metadata_stow_guard msg( InvocationMetadata, metadata_stow ); // Search for files/directories. std::list< std::filesystem::path > paths; @@ -170,12 +172,6 @@ bool FindFiles(Drover& DICOM_data, } } - // Restore the key to its original state in the global parameter table. - InvocationMetadata.erase(Key); - if(orig_val){ - InvocationMetadata[Key] = orig_val.value(); - } - return ret; }