cid#1607171 Data race condition
[LibreOffice.git] / desktop / source / deployment / registry / configuration / dp_configuration.cxx
blob67acb9c7cdc7bf4acca9b811c8d1a758eea2b0e9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 //TODO: Large parts of this file were copied from dp_component.cxx; those parts
21 // should be consolidated.
23 #include <config_extensions.h>
25 #include <dp_backend.h>
26 #if HAVE_FEATURE_EXTENSIONS
27 #include <dp_persmap.h>
28 #endif
29 #include <dp_misc.h>
30 #include <dp_ucb.h>
31 #include <rtl/string.hxx>
32 #include <rtl/strbuf.hxx>
33 #include <cppuhelper/exc_hlp.hxx>
34 #include <cppuhelper/supportsservice.hxx>
35 #include <ucbhelper/content.hxx>
36 #include <unotools/ucbhelper.hxx>
37 #include <xmlscript/xml_helper.hxx>
38 #include <comphelper/lok.hxx>
39 #include <comphelper/xmlencode.hxx>
40 #include <svl/inettype.hxx>
41 #include <o3tl/string_view.hxx>
42 #include <com/sun/star/configuration/Update.hpp>
43 #include <com/sun/star/lang/IllegalArgumentException.hpp>
44 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
45 #include <deque>
46 #include <memory>
47 #include <string_view>
48 #include <utility>
50 #include "dp_configurationbackenddb.hxx"
52 using namespace ::dp_misc;
53 using namespace ::com::sun::star;
54 using namespace ::com::sun::star::uno;
55 using namespace ::com::sun::star::ucb;
57 namespace dp_registry::backend::configuration {
58 namespace {
60 class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend
62 class PackageImpl : public ::dp_registry::backend::Package
64 BackendImpl * getMyBackend() const ;
66 const bool m_isSchema;
68 // Package
69 virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
70 ::osl::ResettableMutexGuard & guard,
71 ::rtl::Reference<AbortChannel> const & abortChannel,
72 Reference<XCommandEnvironment> const & xCmdEnv ) override;
73 virtual void processPackage_(
74 ::osl::ResettableMutexGuard & guard,
75 bool registerPackage,
76 bool startup,
77 ::rtl::Reference<AbortChannel> const & abortChannel,
78 Reference<XCommandEnvironment> const & xCmdEnv ) override;
80 public:
81 PackageImpl(
82 ::rtl::Reference<PackageRegistryBackend> const & myBackend,
83 OUString const & url, OUString const & name,
84 Reference<deployment::XPackageTypeInfo> const & xPackageType,
85 bool isSchema, bool bRemoved, OUString const & identifier)
86 : Package( myBackend, url, name, name /* display-name */,
87 xPackageType, bRemoved, identifier),
88 m_isSchema( isSchema )
91 friend class PackageImpl;
93 std::deque<OUString> m_xcs_files;
94 std::deque<OUString> m_xcu_files;
95 std::deque<OUString> & getFiles( bool xcs ) {
96 return xcs ? m_xcs_files : m_xcu_files;
99 bool m_configmgrini_inited;
100 bool m_configmgrini_modified;
101 std::unique_ptr<ConfigurationBackendDb> m_backendDb;
103 // PackageRegistryBackend
104 virtual Reference<deployment::XPackage> bindPackage_(
105 OUString const & url, OUString const & mediaType, bool bRemoved,
106 OUString const & identifier,
107 Reference<XCommandEnvironment> const & xCmdEnv ) override;
109 #if HAVE_FEATURE_EXTENSIONS
110 // for backwards compatibility - nil if no (compatible) back-compat db present
111 std::unique_ptr<PersistentMap> m_registeredPackages;
112 #endif
114 virtual void SAL_CALL disposing() override;
116 const Reference<deployment::XPackageTypeInfo> m_xConfDataTypeInfo;
117 const Reference<deployment::XPackageTypeInfo> m_xConfSchemaTypeInfo;
118 Sequence< Reference<deployment::XPackageTypeInfo> > m_typeInfos;
120 void configmgrini_verify_init(
121 Reference<XCommandEnvironment> const & xCmdEnv );
122 void configmgrini_flush( Reference<XCommandEnvironment> const & xCmdEnv );
124 /* The parameter isURL is false in the case of adding the conf:ini-entry
125 value from the backend db. This entry already contains the path as it
126 is used in the configmgr.ini.
128 void addToConfigmgrIni( bool isSchema, bool isURL, OUString const & url,
129 Reference<XCommandEnvironment> const & xCmdEnv );
130 #if HAVE_FEATURE_EXTENSIONS
131 bool removeFromConfigmgrIni( bool isSchema, OUString const & url,
132 Reference<XCommandEnvironment> const & xCmdEnv );
133 #endif
134 void addDataToDb(OUString const & url, ConfigurationBackendDb::Data const & data);
135 ::std::optional<ConfigurationBackendDb::Data> readDataFromDb(std::u16string_view url);
136 void revokeEntryFromDb(std::u16string_view url);
137 bool hasActiveEntry(std::u16string_view url);
138 bool activateEntry(std::u16string_view url);
140 public:
141 BackendImpl( Sequence<Any> const & args,
142 Reference<XComponentContext> const & xComponentContext );
144 // XServiceInfo
145 virtual OUString SAL_CALL getImplementationName() override;
146 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
147 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
149 // XPackageRegistry
150 virtual Sequence< Reference<deployment::XPackageTypeInfo> > SAL_CALL
151 getSupportedPackageTypes() override;
152 virtual void SAL_CALL packageRemoved(OUString const & url, OUString const & mediaType) override;
154 using PackageRegistryBackend::disposing;
158 void BackendImpl::disposing()
160 try {
161 configmgrini_flush( Reference<XCommandEnvironment>() );
163 PackageRegistryBackend::disposing();
165 catch (const RuntimeException &) {
166 throw;
168 catch (const Exception &) {
169 Any exc( ::cppu::getCaughtException() );
170 throw lang::WrappedTargetRuntimeException(
171 u"caught unexpected exception while disposing..."_ustr,
172 static_cast<OWeakObject *>(this), exc );
177 BackendImpl::BackendImpl(
178 Sequence<Any> const & args,
179 Reference<XComponentContext> const & xComponentContext )
180 : PackageRegistryBackend( args, xComponentContext ),
181 m_configmgrini_inited( false ),
182 m_configmgrini_modified( false ),
183 m_xConfDataTypeInfo( new Package::TypeInfo(
184 u"application/vnd.sun.star.configuration-data"_ustr,
185 u"*.xcu"_ustr,
186 DpResId(RID_STR_CONF_DATA)
187 ) ),
188 m_xConfSchemaTypeInfo( new Package::TypeInfo(
189 u"application/vnd.sun.star.configuration-schema"_ustr,
190 u"*.xcs"_ustr,
191 DpResId(RID_STR_CONF_SCHEMA)
192 ) ),
193 m_typeInfos{ m_xConfDataTypeInfo, m_xConfSchemaTypeInfo }
195 const Reference<XCommandEnvironment> xCmdEnv;
197 if (transientMode())
199 // TODO
201 else
203 OUString dbFile = makeURL(getCachePath(), u"backenddb.xml"_ustr);
204 m_backendDb.reset(
205 new ConfigurationBackendDb(getComponentContext(), dbFile));
206 //clean up data folders which are no longer used.
207 //This must not be done in the same process where the help files
208 //are still registers. Only after revoking and restarting OOo the folders
209 //can be removed. This works now, because the extension manager is a singleton
210 //and the backends are only create once per process.
211 std::vector<OUString> folders = m_backendDb->getAllDataUrls();
212 deleteUnusedFolders(folders);
214 configmgrini_verify_init( xCmdEnv );
216 #if HAVE_FEATURE_EXTENSIONS
217 std::unique_ptr<PersistentMap> pMap;
218 OUString aCompatURL( makeURL( getCachePath(), u"registered_packages.pmap"_ustr ) );
220 // Don't create it if it doesn't exist already
221 if ( ::utl::UCBContentHelper::Exists( expandUnoRcUrl( aCompatURL ) ) )
225 pMap.reset( new PersistentMap( aCompatURL ) );
227 catch (const Exception &e)
229 OUString aStr = "Exception loading legacy package database: '" +
230 e.Message +
231 "' - ignoring file, please remove it.\n";
232 dp_misc::writeConsole( aStr );
235 m_registeredPackages = std::move(pMap);
236 #endif
240 // XServiceInfo
241 OUString BackendImpl::getImplementationName()
243 return u"com.sun.star.comp.deployment.configuration.PackageRegistryBackend"_ustr;
246 sal_Bool BackendImpl::supportsService( const OUString& ServiceName )
248 return cppu::supportsService(this, ServiceName);
251 css::uno::Sequence< OUString > BackendImpl::getSupportedServiceNames()
253 return { BACKEND_SERVICE_NAME };
256 void BackendImpl::addDataToDb(
257 OUString const & url, ConfigurationBackendDb::Data const & data)
259 if (m_backendDb)
260 m_backendDb->addEntry(url, data);
263 ::std::optional<ConfigurationBackendDb::Data> BackendImpl::readDataFromDb(
264 std::u16string_view url)
266 ::std::optional<ConfigurationBackendDb::Data> data;
267 if (m_backendDb)
268 data = m_backendDb->getEntry(url);
269 return data;
272 void BackendImpl::revokeEntryFromDb(std::u16string_view url)
274 if (m_backendDb)
275 m_backendDb->revokeEntry(url);
278 bool BackendImpl::hasActiveEntry(std::u16string_view url)
280 if (m_backendDb)
281 return m_backendDb->hasActiveEntry(url);
282 return false;
285 bool BackendImpl::activateEntry(std::u16string_view url)
287 if (m_backendDb)
288 return m_backendDb->activateEntry(url);
289 return false;
293 // XPackageRegistry
295 Sequence< Reference<deployment::XPackageTypeInfo> >
296 BackendImpl::getSupportedPackageTypes()
298 return m_typeInfos;
300 void BackendImpl::packageRemoved(OUString const & url, OUString const & /*mediaType*/)
302 if (m_backendDb)
303 m_backendDb->removeEntry(url);
306 // PackageRegistryBackend
308 Reference<deployment::XPackage> BackendImpl::bindPackage_(
309 OUString const & url, OUString const & mediaType_,
310 bool bRemoved, OUString const & identifier,
311 Reference<XCommandEnvironment> const & xCmdEnv )
313 OUString mediaType( mediaType_ );
314 if (mediaType.isEmpty())
316 // detect media-type:
317 ::ucbhelper::Content ucbContent;
318 if (create_ucb_content( &ucbContent, url, xCmdEnv ))
320 const OUString title( StrTitle::getTitle( ucbContent ) );
321 if (title.endsWithIgnoreAsciiCase( ".xcu" )) {
322 mediaType = "application/vnd.sun.star.configuration-data";
324 if (title.endsWithIgnoreAsciiCase( ".xcs" )) {
325 mediaType = "application/vnd.sun.star.configuration-schema";
328 if (mediaType.isEmpty())
329 throw lang::IllegalArgumentException(
330 StrCannotDetectMediaType() + url,
331 static_cast<OWeakObject *>(this), static_cast<sal_Int16>(-1) );
334 OUString type, subType;
335 INetContentTypeParameterList params;
336 if (INetContentTypes::parse( mediaType, type, subType, &params ))
338 if (type.equalsIgnoreAsciiCase("application"))
340 OUString name;
341 if (!bRemoved)
343 ::ucbhelper::Content ucbContent( url, xCmdEnv, m_xComponentContext );
344 name = StrTitle::getTitle( ucbContent );
347 if (subType.equalsIgnoreAsciiCase( "vnd.sun.star.configuration-data"))
349 return new PackageImpl(
350 this, url, name, m_xConfDataTypeInfo, false /* data file */,
351 bRemoved, identifier);
353 else if (subType.equalsIgnoreAsciiCase( "vnd.sun.star.configuration-schema")) {
354 return new PackageImpl(
355 this, url, name, m_xConfSchemaTypeInfo, true /* schema file */,
356 bRemoved, identifier);
360 throw lang::IllegalArgumentException(
361 StrUnsupportedMediaType() + mediaType,
362 static_cast<OWeakObject *>(this),
363 static_cast<sal_Int16>(-1) );
367 void BackendImpl::configmgrini_verify_init(
368 Reference<XCommandEnvironment> const & xCmdEnv )
370 if (transientMode())
371 return;
372 const ::osl::MutexGuard guard( m_aMutex );
373 if ( m_configmgrini_inited)
374 return;
376 // common rc:
377 ::ucbhelper::Content ucb_content;
378 if (create_ucb_content(
379 &ucb_content,
380 makeURL( getCachePath(), u"configmgr.ini"_ustr ),
381 xCmdEnv, false /* no throw */ ))
383 OUString line;
384 if (readLine( &line, u"SCHEMA=", ucb_content,
385 RTL_TEXTENCODING_UTF8 ))
387 sal_Int32 index = RTL_CONSTASCII_LENGTH("SCHEMA=");
388 do {
389 OUString token( o3tl::trim(o3tl::getToken(line, 0, ' ', index )) );
390 if (!token.isEmpty()) {
391 //The file may not exist anymore if a shared or bundled
392 //extension was removed, but it can still be in the configmgrini.
393 //After running XExtensionManager::synchronize, the configmgrini is
394 //cleaned up
395 m_xcs_files.push_back( token );
398 while (index >= 0);
400 if (readLine( &line, u"DATA=", ucb_content,
401 RTL_TEXTENCODING_UTF8 )) {
402 sal_Int32 index = RTL_CONSTASCII_LENGTH("DATA=");
403 do {
404 std::u16string_view token( o3tl::trim(o3tl::getToken(line, 0, ' ', index )) );
405 if (!token.empty())
407 if (token[ 0 ] == '?')
408 token = token.substr( 1 );
409 //The file may not exist anymore if a shared or bundled
410 //extension was removed, but it can still be in the configmgrini.
411 //After running XExtensionManager::synchronize, the configmgrini is
412 //cleaned up
413 m_xcu_files.push_back( OUString(token) );
416 while (index >= 0);
419 m_configmgrini_modified = false;
420 m_configmgrini_inited = true;
424 void BackendImpl::configmgrini_flush(
425 Reference<XCommandEnvironment> const & xCmdEnv )
427 if (transientMode())
428 return;
429 if (!m_configmgrini_inited || !m_configmgrini_modified)
430 return;
432 OStringBuffer buf;
433 if (! m_xcs_files.empty())
435 auto iPos( m_xcs_files.cbegin() );
436 auto const iEnd( m_xcs_files.cend() );
437 buf.append( "SCHEMA=" );
438 while (iPos != iEnd) {
439 // encoded ASCII file-urls:
440 const OString item(
441 OUStringToOString( *iPos, RTL_TEXTENCODING_ASCII_US ) );
442 buf.append( item );
443 ++iPos;
444 if (iPos != iEnd)
445 buf.append( ' ' );
447 buf.append(LF);
449 if (! m_xcu_files.empty())
451 auto iPos( m_xcu_files.cbegin() );
452 auto const iEnd( m_xcu_files.cend() );
453 buf.append( "DATA=" );
454 while (iPos != iEnd) {
455 // encoded ASCII file-urls:
456 const OString item(
457 OUStringToOString( *iPos, RTL_TEXTENCODING_ASCII_US ) );
458 buf.append( item );
459 ++iPos;
460 if (iPos != iEnd)
461 buf.append( ' ' );
463 buf.append(LF);
466 // write configmgr.ini:
467 const Reference<io::XInputStream> xData(
468 ::xmlscript::createInputStream(
469 reinterpret_cast<sal_Int8 const *>(buf.getStr()),
470 buf.getLength() ) );
471 ::ucbhelper::Content ucb_content(
472 makeURL( getCachePath(), u"configmgr.ini"_ustr ), xCmdEnv, m_xComponentContext );
473 ucb_content.writeStream( xData, true /* replace existing */ );
475 m_configmgrini_modified = false;
479 void BackendImpl::addToConfigmgrIni( bool isSchema, bool isURL, OUString const & url_,
480 Reference<XCommandEnvironment> const & xCmdEnv )
482 const OUString rcterm( isURL ? dp_misc::makeRcTerm(url_) : url_ );
483 const ::osl::MutexGuard guard( m_aMutex );
484 configmgrini_verify_init( xCmdEnv );
485 std::deque<OUString> & rSet = getFiles(isSchema);
486 if (std::find( rSet.begin(), rSet.end(), rcterm ) == rSet.end()) {
487 rSet.push_front( rcterm ); // prepend to list, thus overriding
488 // write immediately:
489 m_configmgrini_modified = true;
490 configmgrini_flush( xCmdEnv );
494 #if HAVE_FEATURE_EXTENSIONS
495 bool BackendImpl::removeFromConfigmgrIni(
496 bool isSchema, OUString const & url_,
497 Reference<XCommandEnvironment> const & xCmdEnv )
499 const OUString rcterm( dp_misc::makeRcTerm(url_) );
500 const ::osl::MutexGuard guard( m_aMutex );
501 configmgrini_verify_init( xCmdEnv );
502 std::deque<OUString> & rSet = getFiles(isSchema);
503 auto i(std::find(rSet.begin(), rSet.end(), rcterm));
504 if (i == rSet.end() && !isSchema)
506 //in case the xcu contained %origin% then the configmr.ini contains the
507 //url to the file in the user installation (e.g. $BUNDLED_EXTENSIONS_USER)
508 //However, m_url (getURL()) contains the URL for the file in the actual
509 //extension installation.
510 ::std::optional<ConfigurationBackendDb::Data> data = readDataFromDb(url_);
511 if (data)
512 i = std::find(rSet.begin(), rSet.end(), data->iniEntry);
514 if (i == rSet.end()) {
515 return false;
517 rSet.erase(i);
518 // write immediately:
519 m_configmgrini_modified = true;
520 configmgrini_flush( xCmdEnv );
521 return true;
523 #endif
525 // Package
528 BackendImpl * BackendImpl::PackageImpl::getMyBackend() const
530 BackendImpl * pBackend = static_cast<BackendImpl *>(m_myBackend.get());
531 if (nullptr == pBackend)
533 //May throw a DisposedException
534 check();
535 //We should never get here...
536 throw RuntimeException(
537 u"Failed to get the BackendImpl"_ustr,
538 static_cast<OWeakObject*>(const_cast<PackageImpl *>(this)));
540 return pBackend;
543 beans::Optional< beans::Ambiguous<sal_Bool> >
544 BackendImpl::PackageImpl::isRegistered_(
545 ::osl::ResettableMutexGuard &,
546 ::rtl::Reference<AbortChannel> const &,
547 Reference<XCommandEnvironment> const & )
549 BackendImpl * that = getMyBackend();
551 bool bReg = false;
552 if (that->hasActiveEntry(getURL()))
553 bReg = true;
555 #if HAVE_FEATURE_EXTENSIONS
556 const OUString url(getURL());
557 if (!bReg && that->m_registeredPackages)
559 // fallback for user extension registered in berkeley DB
560 bReg = that->m_registeredPackages->has(
561 OUStringToOString( url, RTL_TEXTENCODING_UTF8 ));
563 #endif
564 return beans::Optional< beans::Ambiguous<sal_Bool> >(
565 true, beans::Ambiguous<sal_Bool>( bReg, false ) );
569 OUString replaceOrigin(
570 OUString const & url, std::u16string_view destFolder, Reference< XCommandEnvironment > const & xCmdEnv, Reference< XComponentContext > const & xContext, bool & out_replaced)
572 // looking for %origin%:
573 ::ucbhelper::Content ucb_content( url, xCmdEnv, xContext );
574 std::vector<sal_Int8> bytes( readFile( ucb_content ) );
575 std::vector<sal_Int8> filtered( bytes.size() * 2 );
576 bool use_filtered = false;
577 OString origin;
578 char const * pBytes = reinterpret_cast<char const *>(
579 bytes.data());
580 std::size_t nBytes = bytes.size();
581 size_t write_pos = 0;
582 while (nBytes > 0)
584 // coverity[ tainted_data_return : FALSE ] version 2023.12.2
585 sal_Int32 index = rtl_str_indexOfChar_WithLength( pBytes, nBytes, '%' );
586 if (index < 0) {
587 if (! use_filtered) // opt
588 break;
589 index = nBytes;
592 assert(index >= 0);
594 if ((write_pos + index) > filtered.size())
595 filtered.resize( (filtered.size() + index) * 2 );
596 memcpy( filtered.data() + write_pos, pBytes, index );
597 write_pos += index;
598 pBytes += index;
599 nBytes -= index;
600 if (nBytes == 0)
601 break;
603 // consume %:
604 ++pBytes;
605 --nBytes;
606 char const * pAdd = "%";
607 sal_Int32 nAdd = 1;
608 if (nBytes > 1 && pBytes[ 0 ] == '%')
610 // %% => %
611 ++pBytes;
612 --nBytes;
613 use_filtered = true;
615 else if (rtl_str_shortenedCompare_WithLength(
616 pBytes, nBytes,
617 "origin%",
618 RTL_CONSTASCII_LENGTH("origin%"),
619 RTL_CONSTASCII_LENGTH("origin%")) == 0)
621 if (origin.isEmpty()) {
622 // encode only once
623 origin = OUStringToOString(
624 comphelper::string::encodeForXml( url.subView( 0, url.lastIndexOf( '/' ) ) ),
625 // xxx todo: encode always for UTF-8? => lookup doc-header?
626 RTL_TEXTENCODING_UTF8 );
628 pAdd = origin.getStr();
629 nAdd = origin.getLength();
630 pBytes += RTL_CONSTASCII_LENGTH("origin%");
631 nBytes -= RTL_CONSTASCII_LENGTH("origin%");
632 use_filtered = true;
634 if ((write_pos + nAdd) > filtered.size())
635 filtered.resize( (filtered.size() + nAdd) * 2 );
636 memcpy( filtered.data() + write_pos, pAdd, nAdd );
637 write_pos += nAdd;
639 if (!use_filtered)
640 return url;
641 if (write_pos < filtered.size())
642 filtered.resize( write_pos );
643 OUString newUrl(url);
644 if (!destFolder.empty())
646 //get the file name of the xcu and add it to the url of the temporary folder
647 sal_Int32 i = url.lastIndexOf('/');
648 newUrl = OUString::Concat(destFolder) + url.subView(i);
651 ucbhelper::Content(newUrl, xCmdEnv, xContext).writeStream(
652 xmlscript::createInputStream(std::move(filtered)), true);
653 out_replaced = true;
654 return newUrl;
658 void BackendImpl::PackageImpl::processPackage_(
659 ::osl::ResettableMutexGuard & guard,
660 bool doRegisterPackage,
661 bool startup,
662 ::rtl::Reference<AbortChannel> const &,
663 Reference<XCommandEnvironment> const & xCmdEnv )
665 BackendImpl * that = getMyBackend();
666 OUString url( getURL() );
668 if (doRegisterPackage)
670 if (getMyBackend()->activateEntry(getURL()))
672 ::std::optional<ConfigurationBackendDb::Data> data = that->readDataFromDb(url);
673 OSL_ASSERT(data);
674 that->addToConfigmgrIni( m_isSchema, false, data->iniEntry, xCmdEnv );
676 else
678 ConfigurationBackendDb::Data data;
679 if (!m_isSchema)
681 const OUString sModFolder = that->createFolder(xCmdEnv);
682 bool out_replaced = false;
683 url = replaceOrigin(url, sModFolder, xCmdEnv, that->getComponentContext(), out_replaced);
684 if (out_replaced)
685 data.dataUrl = sModFolder;
686 else
687 deleteTempFolder(sModFolder);
689 //No need for live-deployment for bundled extension, because OOo
690 //restarts after installation
691 if ((that->m_eContext != Context::Bundled && !startup)
692 || comphelper::LibreOfficeKit::isActive())
694 bool bIsSchema = m_isSchema;
695 // tdf#159790 prevent lock-ordering deadlock, the code below might acquire the solar mutex
696 guard.clear();
697 if (bIsSchema)
699 css::configuration::Update::get(
700 that->m_xComponentContext)->insertExtensionXcsFile(
701 that->m_eContext == Context::Shared, expandUnoRcUrl(url));
703 else
705 css::configuration::Update::get(
706 that->m_xComponentContext)->insertExtensionXcuFile(
707 that->m_eContext == Context::Shared, expandUnoRcUrl(url));
709 guard.reset();
711 that->addToConfigmgrIni( m_isSchema, true, url, xCmdEnv );
712 data.iniEntry = dp_misc::makeRcTerm(url);
713 that->addDataToDb(getURL(), data);
716 else // revoke
718 #if HAVE_FEATURE_EXTENSIONS
719 if (!that->removeFromConfigmgrIni(m_isSchema, url, xCmdEnv) &&
720 that->m_registeredPackages) {
721 // Obsolete package database handling - should be removed for LibreOffice 4.0
722 t_string2string_map entries(
723 that->m_registeredPackages->getEntries());
724 for (auto const& entry : entries)
726 //If the xcu file was installed before the configmgr was changed
727 //to use the configmgr.ini, one needed to rebuild to whole directory
728 //structure containing the xcu, xcs files from all extensions. Now,
729 //we just add all other xcu/xcs files to the configmgr.ini instead of
730 //rebuilding the directory structure.
731 OUString url2(
732 OStringToOUString(entry.first, RTL_TEXTENCODING_UTF8));
733 if (url2 != url) {
734 bool schema = entry.second.equalsIgnoreAsciiCase(
735 "vnd.sun.star.configuration-schema");
736 OUString url_replaced(url2);
737 ConfigurationBackendDb::Data data;
738 if (!schema)
740 const OUString sModFolder = that->createFolder(xCmdEnv);
741 bool out_replaced = false;
742 url_replaced = replaceOrigin(
743 url2, sModFolder, xCmdEnv, that->getComponentContext(), out_replaced);
744 if (out_replaced)
745 data.dataUrl = sModFolder;
746 else
747 deleteTempFolder(sModFolder);
749 that->addToConfigmgrIni(schema, true, url_replaced, xCmdEnv);
750 data.iniEntry = dp_misc::makeRcTerm(url_replaced);
751 that->addDataToDb(url2, data);
753 that->m_registeredPackages->erase(entry.first);
757 ::ucbhelper::Content(
758 makeURL( that->getCachePath(), u"registry"_ustr ),
759 xCmdEnv, that->getComponentContext() ).executeCommand(
760 u"delete"_ustr, Any( true /* delete physically */ ) );
762 catch(const Exception&)
764 OSL_ASSERT(false);
767 #endif
768 ::std::optional<ConfigurationBackendDb::Data> data = that->readDataFromDb(url);
769 //If an xcu file was life deployed then always a data entry is written.
770 //If the xcu file was already in the configmr.ini then there is also
771 //a data entry
772 if (!m_isSchema && data)
774 css::configuration::Update::get(
775 that->m_xComponentContext)->removeExtensionXcuFile(expandUnoRcTerm(data->iniEntry));
777 that->revokeEntryFromDb(url);
781 } // anon namespace
783 } // namespace dp_registry
785 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
786 com_sun_star_comp_deployment_configuration_PackageRegistryBackend_get_implementation(
787 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
789 return cppu::acquire(new dp_registry::backend::configuration::BackendImpl(args, context));
792 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */