/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
class Bootstrap::Impl
{ const OUString m_aImplName; public: // struct to cache the result of a path lookup struct PathData
{
OUString path;
PathStatus status;
PathData()
: status(DATA_UNKNOWN)
{}
}; public: // data members // base install data
PathData aBaseInstall_;
// user install data
PathData aUserInstall_;
// INI files
PathData aBootstrapINI_;
PathData aVersionINI_;
// overall status
Status status_;
public: // construction and initialization
Impl() : m_aImplName(makeImplName())
{
initialize();
}
// path status utility function static PathStatus implCheckStatusOfURL(OUString const& _sURL, osl::DirectoryItem& aDirItem)
{ usingnamespace osl;
PathStatus eStatus = Bootstrap::DATA_UNKNOWN;
if (!_sURL.isEmpty())
{ switch( DirectoryItem::get(_sURL, aDirItem) )
{ case DirectoryItem::E_None: // Success
eStatus = Bootstrap::PATH_EXISTS; break;
case DirectoryItem::E_NOENT: // No such file or directory
eStatus = Bootstrap::PATH_VALID; break;
case DirectoryItem::E_INVAL: // the format of the parameters was not valid case DirectoryItem::E_NAMETOOLONG: // File name too long case DirectoryItem::E_NOTDIR: // A component of the path prefix of path is not a directory
eStatus = Bootstrap::DATA_INVALID; break;
// how to handle these ? case DirectoryItem::E_LOOP: // Too many symbolic links encountered case DirectoryItem::E_ACCES: // permission denied // any other error - what to do ? default:
eStatus = Bootstrap::DATA_UNKNOWN; break;
}
} else
{
eStatus = Bootstrap::DATA_MISSING;
}
if (eStatus == Bootstrap::PATH_EXISTS && !implNormalizeURL(_sURL,aDirItem))
OSL_FAIL("Unexpected failure getting actual URL for existing object");
} return eStatus;
}
// helpers to build and check a nested URL static PathStatus getDerivedPath(
OUString& _rURL,
OUString const& _aBaseURL, PathStatus _aBaseStatus,
std::u16string_view _sRelativeURL,
rtl::Bootstrap const & _rData, OUString const& _sBootstrapParameter
)
{
OUString sDerivedURL;
OSL_PRECOND(!_rData.getFrom(_sBootstrapParameter,sDerivedURL),"Setting for derived path is already defined");
OSL_PRECOND(!_sRelativeURL.empty() && _sRelativeURL[0] != cURLSeparator,"Invalid Relative URL");
PathStatus aStatus = _aBaseStatus;
// do we have a base path ? if (!_aBaseURL.isEmpty())
{
OSL_PRECOND(!_aBaseURL.endsWith(OUStringChar(cURLSeparator)), "Unexpected: base URL ends in slash");
// a derived (nested) URL can only exist or have a lesser status, if the parent exists if (aStatus == Bootstrap::PATH_EXISTS)
aStatus = checkStatusAndNormalizeURL(sDerivedURL);
else// the relative appendix must be valid
OSL_ASSERT(aStatus != Bootstrap::PATH_VALID || dbgCheckStatusOfURL(sDerivedURL) == Bootstrap::PATH_VALID);
OSL_ENSURE(sDerivedURL == _rURL,"Could not set derived URL via Bootstrap default parameter");
SAL_WARN_IF( !(RTL_BOOTSTRAP_DEFAULTS_BROKEN || (_rData.getFrom(_sBootstrapParameter,sDerivedURL) && sDerivedURL==_rURL)), "unotools.config", "Use of default did not affect bootstrap value");
} else
{ // clear the result
_rURL = _aBaseURL;
// if we have no data it can't be a valid path
OSL_ASSERT( aStatus > Bootstrap::PATH_VALID );
}
if (osl_Process_E_None == osl_getExecutableFile(&sExecutable.pData))
{ // split the executable name
sal_Int32 nSepIndex = sExecutable.lastIndexOf(cURLSeparator);
sExecutable = sExecutable.copy(nSepIndex + 1);
// ... and get the basename (strip the extension)
sal_Unicode const cExtensionSep = '.';
case Bootstrap::PATH_VALID:
addMissingDirectoryError(_rBuf, _rData.aUserInstall_.path);
eErrCode = Bootstrap::MISSING_USER_DIRECTORY; break;
// else fall through case Bootstrap::DATA_INVALID: if (_rData.aVersionINI_.status == Bootstrap::PATH_EXISTS)
{
addFileError(_rBuf, _rData.aVersionINI_.path, IS_INVALID);
eErrCode = Bootstrap::INVALID_VERSION_FILE_ENTRY; break;
}
[[fallthrough]];
case Bootstrap::DATA_MISSING: switch (_rData.aVersionINI_.status)
{ case Bootstrap::PATH_EXISTS:
addFileError(_rBuf, _rData.aVersionINI_.path, "does not support the current version");
eErrCode = Bootstrap::MISSING_VERSION_FILE_ENTRY; break;
case Bootstrap::PATH_VALID:
addFileError(_rBuf, _rData.aVersionINI_.path, IS_MISSING);
eErrCode = Bootstrap::MISSING_VERSION_FILE; break;
default: switch (_rData.aBootstrapINI_.status)
{ case Bootstrap::PATH_EXISTS:
addFileError(_rBuf, _rData.aBootstrapINI_.path, IS_INVALID);
bool Bootstrap::Impl::initUserInstallationData(rtl::Bootstrap const & _rData)
{ if (_rData.getFrom(BOOTSTRAP_ITEM_USERINSTALLATION, aUserInstall_.path))
{
updateStatus(aUserInstall_);
} else
{ // should we do just this
aUserInstall_.status = DATA_MISSING;
// ... or this - look for a single-user user directory ?
OUString const csUserDirItem(BOOTSTRAP_ITEM_USERDIR);
OUString sDummy; // look for $BASEINSTALLATION/user only if default UserDir setting is used if (! _rData.getFrom(csUserDirItem, sDummy))
{ if ( PATH_EXISTS == getDerivedPath(sDummy, aBaseInstall_, BOOTSTRAP_DIRNAME_USERDIR, _rData, csUserDirItem) )
aUserInstall_ = aBaseInstall_;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.