diff options
author | Armin Le Grand <Armin.Le.Grand@cib.de> | 2016-09-23 18:21:54 +0200 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@cib.de> | 2016-10-11 13:56:22 +0200 |
commit | 7db23b6346ff601449e8017fd585e9fbc295ed34 (patch) | |
tree | 696b232a1a372d13bbaf605586a9c9f4637744d2 /configmgr | |
parent | 9fa4eff9be5e440099517a522a83e20debaf2955 (diff) |
profilesafe: Collect copies in single *.pack file
Enhanced helper classes for BackupFileHelper to
allow writing a stack of rescued last valid
configuration files to a single file package.
Added configuration values for enabling this and
defining the number of entries, added max entry
limitation. Using FileSize and CRC32 now to dectect
if config file did change. To make this work I added
sorting to writing the configuration so that with no
change the same configuration file is written.
Use std::vector for better mem performance for sorting,
defined static const for buffer size of manipulation,
prepare inflate/deflate usages. Fixes to setPos, warnings
Change-Id: Ib286e2a3f25b0085a1e3ae4f50c9ff1ff3a5dcf5
Diffstat (limited to 'configmgr')
-rw-r--r-- | configmgr/source/components.cxx | 18 | ||||
-rw-r--r-- | configmgr/source/writemodfile.cxx | 60 |
2 files changed, 65 insertions, 13 deletions
diff --git a/configmgr/source/components.cxx b/configmgr/source/components.cxx index a193da06b167..206d3462a15e 100644 --- a/configmgr/source/components.cxx +++ b/configmgr/source/components.cxx @@ -643,18 +643,22 @@ Components::~Components() (*i)->setAlive(false); } - // test backup of registrymodifications - static bool bFeatureSecureUserConfig(true); - if (!bExitWasCalled && - bFeatureSecureUserConfig && ModificationTarget::File == modificationTarget_ && !modificationFileUrl_.isEmpty()) { - static sal_uInt16 nNumCopies(5); - comphelper::BackupFileHelper aBackupFileHelper(modificationFileUrl_, nNumCopies); + // test backup of registrymodifications + sal_uInt16 nSecureUserConfigNumCopies(0); + + // read configuration from soffice.ini + const bool bSecureUserConfig(comphelper::BackupFileHelper::getSecureUserConfig(nSecureUserConfigNumCopies)); - aBackupFileHelper.tryPush(); + if (bSecureUserConfig) + { + comphelper::BackupFileHelper aBackupFileHelper(modificationFileUrl_, nSecureUserConfigNumCopies); + + aBackupFileHelper.tryPush(); + } } } diff --git a/configmgr/source/writemodfile.cxx b/configmgr/source/writemodfile.cxx index 1d20c189c462..381ab004a99e 100644 --- a/configmgr/source/writemodfile.cxx +++ b/configmgr/source/writemodfile.cxx @@ -400,6 +400,16 @@ void writeNode( } } +// helpers to allow sorting of configmgr::Modifications::Node +typedef std::pair< const rtl::OUString, configmgr::Modifications::Node > ModNodePairEntry; +struct PairEntrySorter +{ + bool operator() (const ModNodePairEntry* pValue1, const ModNodePairEntry* pValue2) const + { + return pValue1->first.compareTo(pValue2->first) < 0; + } +}; + void writeModifications( Components & components, TempFile &handle, OUString const & parentPathRepresentation, @@ -459,11 +469,27 @@ void writeModifications( OUString pathRep( parentPathRepresentation + "/" + Data::createSegment(node->getTemplateName(), nodeName)); - for (const auto & i : modifications.children) + + // 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(modifications.children.size()); + + for (const auto& rCand : modifications.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 & i : ModNodePairEntryVector) { writeModifications( - components, handle, pathRep, node, i.first, - node->getMember(i.first), i.second); + components, handle, pathRep, node, i->first, + node->getMember(i->first), i->second); } } } @@ -601,9 +627,31 @@ void writeModFile( //TODO: Do not write back information about those removed items that did not // come from the .xcs/.xcu files, anyway (but had been added dynamically // instead): - for (Modifications::Node::Children::const_iterator j( - data.modifications.getRoot().children.begin()); - j != data.modifications.getRoot().children.end(); ++j) + + // 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 preferrable 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, "", rtl::Reference< Node >(), j->first, |