Kaydet (Commit) 5f1a338d authored tarafından Armin Le Grand's avatar Armin Le Grand

profilesafe: Multiple adaptions

Added own directory in User config to where the
saved content is written and taken from, adapted
to also handle ExtensionConfiguration, changed
point for creating backups of configuration to
doShutdown, create no configuration when a restart
is triggered (untested configuration)

Change-Id: Id7a96195b765842c31cacf81cc08d2965a205281
Reviewed-on: https://gerrit.libreoffice.org/29729Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarArmin Le Grand <Armin.Le.Grand@cib.de>
üst 802f2a42
...@@ -613,18 +613,22 @@ Components::Components( ...@@ -613,18 +613,22 @@ Components::Components(
Components::~Components() Components::~Components()
{ {
// get flag if _exit was already called which is a sign to not to secure user config // get flag if _exit was already called which is a sign to not secure user config.
// this is used for win only currently where calling _exit() unfortunately still
// calls destructors (what is not wanted). May be needed for other systems, too
// (unknown yet) but can do no harm
const bool bExitWasCalled(comphelper::BackupFileHelper::getExitWasCalled()); const bool bExitWasCalled(comphelper::BackupFileHelper::getExitWasCalled());
#ifndef WNT #ifndef WNT
// we can add a SAL_WARN here for other systems where the destructor gets called after // we can add a SAL_WARN here for other systems where the destructor gets called after
// an _exit() call - which should not happen. Still safe - the getExitWasCalled() is // an _exit() call. Still safe - the getExitWasCalled() is used, but a hint that _exit
// used, but a hint that _exit behaves different on a system // behaves different on a system
SAL_WARN_IF(bExitWasCalled, "configmgr", "Components::~Components() called after _exit() call"); SAL_WARN_IF(bExitWasCalled, "configmgr", "Components::~Components() called after _exit() call");
#endif #endif
if (bExitWasCalled) if (bExitWasCalled)
{ {
// do not write, re-join thereads
osl::MutexGuard g(*lock_); osl::MutexGuard g(*lock_);
if (writeThread_.is()) if (writeThread_.is())
...@@ -634,30 +638,13 @@ Components::~Components() ...@@ -634,30 +638,13 @@ Components::~Components()
} }
else else
{ {
// write changes
flushModifications(); flushModifications();
} }
for (WeakRootSet::iterator i(roots_.begin()); i != roots_.end(); ++i) { for (WeakRootSet::iterator i(roots_.begin()); i != roots_.end(); ++i) {
(*i)->setAlive(false); (*i)->setAlive(false);
} }
if (!bExitWasCalled &&
ModificationTarget::File == modificationTarget_ &&
!modificationFileUrl_.isEmpty())
{
// test backup of registrymodifications
sal_uInt16 nSecureUserConfigNumCopies(0);
// read configuration from soffice.ini
const bool bSecureUserConfig(comphelper::BackupFileHelper::getSecureUserConfig(nSecureUserConfigNumCopies));
if (bSecureUserConfig)
{
comphelper::BackupFileHelper aBackupFileHelper(modificationFileUrl_, nSecureUserConfigNumCopies);
aBackupFileHelper.tryPush();
}
}
} }
void Components::parseFileLeniently( void Components::parseFileLeniently(
......
...@@ -818,6 +818,42 @@ OUString Desktop::CreateErrorMsgString( ...@@ -818,6 +818,42 @@ OUString Desktop::CreateErrorMsgString(
return MakeStartupErrorMessage( aMsg ); return MakeStartupErrorMessage( aMsg );
} }
// helper method to test if SecureUserConfig is active, detect the num copies
// and extract the User's config directory URL
bool testSecureUserConfigActive(sal_uInt16& rnSecureUserConfigNumCopies, OUString& raUserConfigDir)
{
// read configuration from soffice.ini
if(comphelper::BackupFileHelper::getSecureUserConfig(rnSecureUserConfigNumCopies))
{
// try to asccess user layer configuration file
OUString conf("${CONFIGURATION_LAYERS}");
rtl::Bootstrap::expandMacros(conf);
const OUString aTokenUser("user:");
sal_Int32 nStart(conf.indexOf(aTokenUser));
if (-1 != nStart)
{
nStart += aTokenUser.getLength();
sal_Int32 nEnd(conf.indexOf(' ', nStart));
if (-1 == nEnd)
{
nEnd = conf.getLength();
}
raUserConfigDir = conf.copy(nStart, nEnd - nStart);
raUserConfigDir.startsWith("!", &raUserConfigDir);
}
if (!raUserConfigDir.isEmpty())
{
return true;
}
}
return false;
}
void Desktop::HandleBootstrapErrors( void Desktop::HandleBootstrapErrors(
BootstrapError aBootstrapError, OUString const & aErrorMessage ) BootstrapError aBootstrapError, OUString const & aErrorMessage )
{ {
...@@ -951,75 +987,50 @@ void Desktop::HandleBootstrapErrors( ...@@ -951,75 +987,50 @@ void Desktop::HandleBootstrapErrors(
} }
else if ( aBootstrapError == BE_OFFICECONFIG_BROKEN ) else if ( aBootstrapError == BE_OFFICECONFIG_BROKEN )
{ {
// test restore of registrymodifications // test if SecureUserConfig is active
sal_uInt16 nSecureUserConfigNumCopies(0); sal_uInt16 nSecureUserConfigNumCopies(0);
OUString aUserConfigDir;
bool bFireOriginalError(true); bool bFireOriginalError(true);
// read configuration from soffice.ini if (testSecureUserConfigActive(nSecureUserConfigNumCopies, aUserConfigDir))
const bool bSecureUserConfig(comphelper::BackupFileHelper::getSecureUserConfig(nSecureUserConfigNumCopies));
if (bSecureUserConfig)
{ {
// try to asccess user layer configuration file comphelper::BackupFileHelper aBackupFileHelper(aUserConfigDir, nSecureUserConfigNumCopies);
OUString conf("${CONFIGURATION_LAYERS}");
rtl::Bootstrap::expandMacros(conf);
const OUString aTokenUser("user:");
sal_Int32 nStart(conf.indexOf(aTokenUser));
OUString aUser;
if (-1 != nStart) if (aBackupFileHelper.isPopPossible())
{ {
nStart += aTokenUser.getLength(); // for linux (and probably others?) we need to instantiate XDesktop2
sal_Int32 nEnd(conf.indexOf(' ', nStart)); // to be able to open a *.ui-file based dialog, so do this here locally.
// does no harm on win, so better always do this (in error case only anyways)
if (-1 == nEnd) Reference< XComponentContext > xLocalContext = ::comphelper::getProcessComponentContext();
Reference< XDesktop2 > xDesktop = css::frame::Desktop::create(xLocalContext);
ScopedVclPtrInstance< MessageDialog > aQueryShouldRestore(
Application::GetDefDialogParent(),
"QueryTryToRestoreConfigurationDialog",
"desktop/ui/querytrytorestoreconfigurationdialog.ui");
if (aQueryShouldRestore.get())
{ {
nEnd = conf.getLength(); if (!aErrorMessage.isEmpty())
} {
OUString aPrimaryText(aQueryShouldRestore->get_primary_text());
aUser = conf.copy(nStart, nEnd - nStart);
aUser.startsWith("!", &aUser);
}
if (!aUser.isEmpty()) aPrimaryText += "\n(\"" + aErrorMessage + "\")";
{ aQueryShouldRestore->set_primary_text(aPrimaryText);
comphelper::BackupFileHelper aBackupFileHelper(aUser, nSecureUserConfigNumCopies); }
if (aBackupFileHelper.isPopPossible()) if (RET_YES == aQueryShouldRestore->Execute())
{
// for linux (and probably others?) we need to instantiate XDesktop2
// to be able to open a *.ui-file based dialog, so do this here locally.
// does no harm on win, so better always do this (in error case only anyways)
Reference< XComponentContext > xLocalContext = ::comphelper::getProcessComponentContext();
Reference< XDesktop2 > xDesktop = css::frame::Desktop::create(xLocalContext);
ScopedVclPtrInstance< MessageDialog > aQueryShouldRestore(
Application::GetDefDialogParent(),
"QueryTryToRestoreConfigurationDialog",
"desktop/ui/querytrytorestoreconfigurationdialog.ui");
if (aQueryShouldRestore.get())
{ {
if (!aErrorMessage.isEmpty()) aBackupFileHelper.tryPop();
{ bFireOriginalError = false;
OUString aPrimaryText(aQueryShouldRestore->get_primary_text());
aPrimaryText += "\n(\"" + aErrorMessage + "\")";
aQueryShouldRestore->set_primary_text(aPrimaryText);
}
if (RET_YES == aQueryShouldRestore->Execute())
{
aBackupFileHelper.tryPop();
bFireOriginalError = false;
}
} }
} }
} }
} }
// set flag at BackupFileHelper to be able to know if _exit was called and // set flag at BackupFileHelper to be able to know if _exit was called and
// actions are executed after this // actions are executed after this. This method we are in will not return,
// but end up in a _exit() call
comphelper::BackupFileHelper::setExitWasCalled(); comphelper::BackupFileHelper::setExitWasCalled();
if (bFireOriginalError) if (bFireOriginalError)
...@@ -1836,7 +1847,34 @@ int Desktop::doShutdown() ...@@ -1836,7 +1847,34 @@ int Desktop::doShutdown()
// remove temp directory // remove temp directory
RemoveTemporaryDirectory(); RemoveTemporaryDirectory();
// flush evtl. configuration changes so that all config files in user
// dir are written
FlushConfiguration(); FlushConfiguration();
if (pExecGlobals->bRestartRequested)
{
// a restart is already requested, usually due to a configuration change
// that needs a restart to get active. If this is the case, do not try
// to use SecureUserConfig to safe this still untested new configuration
}
else
{
// Test if SecureUserConfig is active. If yes and we are at this point, regular shutdown
// is in progress and the currently used configuration was working. Try to secure this
// working configuration for later eventually necessary restores
sal_uInt16 nSecureUserConfigNumCopies(0);
OUString aUserConfigDir;
if (testSecureUserConfigActive(nSecureUserConfigNumCopies, aUserConfigDir))
{
// try to push registrymodifications.xcu
comphelper::BackupFileHelper aBackupFileHelper(aUserConfigDir, nSecureUserConfigNumCopies);
aBackupFileHelper.tryPush();
}
}
// The acceptors in the AcceptorMap must be released (in DeregisterServices) // The acceptors in the AcceptorMap must be released (in DeregisterServices)
// with the solar mutex unlocked, to avoid deadlock: // with the solar mutex unlocked, to avoid deadlock:
{ {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -144,8 +144,14 @@ namespace comphelper ...@@ -144,8 +144,14 @@ namespace comphelper
private: private:
// internal helper methods // internal helper methods
bool splitBaseURL(); bool splitBaseURL();
bool baseFileExists(); const rtl::OUString getPackDirName() const;
rtl::OUString getName(); const rtl::OUString getPackFileName(const rtl::OUString& rFileName) const;
bool tryPush_basefile(bool bCompress);
bool tryPush_extensionInfo(bool bCompress);
bool isPopPossible_basefile();
bool isPopPossible_extensionInfo();
bool tryPop_basefile();
bool tryPop_extensionInfo();
}; };
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment