basic/source/uno/namecont.cxx |   27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

New commits:
commit 907d4107896234b2e7ebfd42f40cee3bd5b1d01e
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Jan 31 00:44:19 2024 +0600
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Jan 31 03:35:15 2024 +0100

    tdf#159458: make sure to update unexpanded URL when renaming library
    
    1. If passed new source URL is expanded (i.e., trying to expand it in
    SfxLibraryContainer::checkStorageURL didn't change it), previously
    aUnexpandedStorageURL was unchanged. It should be cleared - then it
    will be set automatically to the URL to lib info file.
    
    2. Try to create the "variable" path (starting with "$(USER)/basic/")
    because this avoids absolute paths to the libraries, which make it
    harder to move the profile.
    
    Change-Id: Ie83ea9a32cfddf37727d238547663aeb72487ee3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162777
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx
index beeee133b064..eb04dd2ee767 100644
--- a/basic/source/uno/namecont.cxx
+++ b/basic/source/uno/namecont.cxx
@@ -537,7 +537,9 @@ void SAL_CALL SfxLibraryContainer::storeLibraries(  )
     }
 }
 
-static void checkAndCopyFileImpl( const INetURLObject& rSourceFolderInetObj,
+namespace
+{
+void checkAndCopyFileImpl( const INetURLObject& rSourceFolderInetObj,
                                   const INetURLObject& rTargetFolderInetObj,
                                   std::u16string_view rCheckFileName,
                                   std::u16string_view rCheckExtension,
@@ -559,12 +561,14 @@ static void checkAndCopyFileImpl( const INetURLObject& 
rSourceFolderInetObj,
     }
 }
 
-static void createVariableURL( OUString& rStr, std::u16string_view rLibName,
+constexpr OUString sUserBasicVariablePrefix = u"$(USER)/basic/"_ustr;
+
+void createVariableURL( OUString& rStr, std::u16string_view rLibName,
                                std::u16string_view rInfoFileName, bool bUser )
 {
     if( bUser )
     {
-        rStr = "$(USER)/basic/";
+        rStr = sUserBasicVariablePrefix;
     }
     else
     {
@@ -572,6 +576,7 @@ static void createVariableURL( OUString& rStr, 
std::u16string_view rLibName,
     }
     rStr += OUString::Concat(rLibName) + "/" + rInfoFileName + ".xlb/";
 }
+}
 
 void SfxLibraryContainer::init( const OUString& rInitialDocumentURL, const 
uno::Reference< embed::XStorage >& rxInitialStorage )
 {
@@ -1261,6 +1266,11 @@ void SfxLibraryContainer::checkStorageURL( const 
OUString& aSourceURL,
     {
         aUnexpandedStorageURL = aSourceURL;
     }
+    else
+    {
+        aUnexpandedStorageURL.clear();
+    }
+
     INetURLObject aInetObj( aExpandedSourceURL );
     OUString aExtension = aInetObj.getExtension();
     if( aExtension == "xlb" )
@@ -2515,9 +2525,18 @@ void SAL_CALL SfxLibraryContainer::renameLibrary( const 
OUString& Name, const OU
                                  INetURLObject::EncodeMechanism::All );
         OUString aDestDirPath = aDestInetObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE );
 
+        OUString aDestDirUnexpandedPath = aDestDirPath;
+        if 
(pImplLib->maUnexpandedStorageURL.startsWith(sUserBasicVariablePrefix))
+        {
+            // try to re-create the variable URL: helps moving the profile
+            OUString aUserBasicURL = expand_url(sUserBasicVariablePrefix);
+            if (OUString aRest; aDestDirPath.startsWith(aUserBasicURL, &aRest))
+                aDestDirUnexpandedPath = sUserBasicVariablePrefix + aRest;
+        }
+
         // Store new URL
         OUString aLibInfoFileURL = pImplLib->maLibInfoFileURL;
-        checkStorageURL( aDestDirPath, pImplLib->maLibInfoFileURL, 
pImplLib->maStorageURL,
+        checkStorageURL(aDestDirUnexpandedPath, pImplLib->maLibInfoFileURL, 
pImplLib->maStorageURL,
                          pImplLib->maUnexpandedStorageURL );
 
         try

Reply via email to