diff --git a/configmgr/source/components.cxx b/configmgr/source/components.cxx index 86f2d0928dc6..d40d04fbdb03 100644 --- a/configmgr/source/components.cxx +++ b/configmgr/source/components.cxx @@ -204,7 +204,6 @@ void Components::WriteThread::execute() { } delayOrTerminate_.wait(std::chrono::seconds(1)); // must not throw; result_error is harmless and ignored - osl::MutexGuard g(*lock_); // must not throw try { try { writeModFile(components_, url_, data_); diff --git a/configmgr/source/components.hxx b/configmgr/source/components.hxx index 8f5bd24c8925..c83b56f5a66e 100644 --- a/configmgr/source/components.hxx +++ b/configmgr/source/components.hxx @@ -98,6 +98,8 @@ public: css::beans::Optional< css::uno::Any > getExternalValue(std::u16string_view descriptor); + osl::Mutex & getLock() const { return *lock_; } + private: Components(const Components&) = delete; Components& operator=(const Components&) = delete; diff --git a/configmgr/source/writemodfile.cxx b/configmgr/source/writemodfile.cxx index 51a738d8d31c..10b8a75d4849 100644 --- a/configmgr/source/writemodfile.cxx +++ b/configmgr/source/writemodfile.cxx @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,7 @@ #include #include +#include "components.hxx" #include "data.hxx" #include "groupnode.hxx" #include "localizedpropertynode.hxx" @@ -601,36 +603,41 @@ void writeModFile( // come from the .xcs/.xcu files, anyway (but had been added dynamically // instead): - // For profilesafemode it is necessary to detect changes in the - // registrymodifications file, this is done based on file size in bytes and crc32. - // Unfortunately this write is based on writing unordered map entries, which creates - // valid and semantically equal XML-Files, bubt with different crc32 checksums. For - // the future usage it will be preferable to have easily comparable config files - // which is guaranteed by writing the entries in sorted order. Indeed with this change - // (and in the recursive writeModifications call) the same config files get written - - // copy configmgr::Modifications::Node's to a sortable list. Use pointers - // to just reference the data instead of copying it - std::vector< const ModNodePairEntry* > ModNodePairEntryVector; - ModNodePairEntryVector.reserve(data.modifications.getRoot().children.size()); - - for (const auto& rCand : data.modifications.getRoot().children) { - ModNodePairEntryVector.push_back(&rCand); + osl::MutexGuard g(components.getLock()); + + // For profilesafemode it is necessary to detect changes in the + // registrymodifications file, this is done based on file size in bytes and crc32. + // Unfortunately this write is based on writing unordered map entries, which creates + // valid and semantically equal XML-Files, bubt with different crc32 checksums. For + // the future usage it will be preferable to have easily comparable config files + // which is guaranteed by writing the entries in sorted order. Indeed with this change + // (and in the recursive writeModifications call) the same config files get written + + // copy configmgr::Modifications::Node's to a sortable list. Use pointers + // to just reference the data instead of copying it + std::vector< const ModNodePairEntry* > ModNodePairEntryVector; + ModNodePairEntryVector.reserve(data.modifications.getRoot().children.size()); + + for (const auto& rCand : data.modifications.getRoot().children) + { + ModNodePairEntryVector.push_back(&rCand); + } + + // sort the list + std::sort(ModNodePairEntryVector.begin(), ModNodePairEntryVector.end(), PairEntrySorter()); + + // now use the list to write entries in sorted order + // instead of random as from the unordered map + for (const auto& j : ModNodePairEntryVector) + { + writeModifications( + components, tmp, u"", rtl::Reference< Node >(), j->first, + data.getComponents().findNode(Data::NO_LAYER, j->first), + j->second); + } } - // sort the list - std::sort(ModNodePairEntryVector.begin(), ModNodePairEntryVector.end(), PairEntrySorter()); - - // now use the list to write entries in sorted order - // instead of random as from the unordered map - for (const auto& j : ModNodePairEntryVector) - { - writeModifications( - components, tmp, u"", rtl::Reference< Node >(), j->first, - data.getComponents().findNode(Data::NO_LAYER, j->first), - j->second); - } tmp.writeString("\n"); tmp.closeAndRename(url); }