[Libreoffice-commits] core.git: 4 commits - onlineupdate/source

Markus Mohrhard markus.mohrhard at googlemail.com
Mon Jun 26 13:25:29 UTC 2017


 onlineupdate/source/update/updater/updater.cxx |  143 ++++++++++++++-----------
 1 file changed, 83 insertions(+), 60 deletions(-)

New commits:
commit f808c50c6eece87d515df3b84b1c774395b5d9bc
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Jun 26 15:22:28 2017 +0200

    updater: make it more difficult to misuse the API
    
    Change-Id: Ief5b2e37f289d6bfa92a909701c331d50509b0a3

diff --git a/onlineupdate/source/update/updater/updater.cxx b/onlineupdate/source/update/updater/updater.cxx
index 3587f39d9201..eb6452a9f6a0 100644
--- a/onlineupdate/source/update/updater/updater.cxx
+++ b/onlineupdate/source/update/updater/updater.cxx
@@ -1360,7 +1360,7 @@ RemoveDir::Finish(int status)
 class AddFile : public Action
 {
 public:
-    AddFile(ArchiveReader *ar) : mAdded(false), mArchiveReader(ar) { }
+    AddFile(ArchiveReader& ar) : mAdded(false), mArchiveReader(ar) { }
 
     virtual int Parse(NS_tchar *line);
     virtual int Prepare();
@@ -1371,7 +1371,7 @@ private:
     std::unique_ptr<NS_tchar> mFile;
     std::unique_ptr<NS_tchar> mRelPath;
     bool mAdded;
-    ArchiveReader *mArchiveReader;
+    ArchiveReader& mArchiveReader;
 };
 
 int
@@ -1411,11 +1411,6 @@ AddFile::Execute()
 
     int rv;
 
-    if(!mArchiveReader) {
-        LOG(("AddFile runs without valid ArchiveReader"));
-        return USAGE_ERROR;
-    }
-
     // First make sure that we can actually get rid of any existing file.
     rv = NS_taccess(mFile.get(), F_OK);
     if (rv == 0)
@@ -1440,9 +1435,9 @@ AddFile::Execute()
         return STRING_CONVERSION_ERROR;
     }
 
-    rv = mArchiveReader->ExtractFile(sourcefile, mFile.get());
+    rv = mArchiveReader.ExtractFile(sourcefile, mFile.get());
 #else
-    rv = mArchiveReader->ExtractFile(mRelPath.get(), mFile.get());
+    rv = mArchiveReader.ExtractFile(mRelPath.get(), mFile.get());
 #endif
     if (!rv)
     {
@@ -1465,7 +1460,7 @@ AddFile::Finish(int status)
 class PatchFile : public Action
 {
 public:
-    PatchFile(ArchiveReader *ar) : mPatchFile(nullptr), mPatchIndex(-1), buf(nullptr), mArchiveReader(ar) { }
+    PatchFile(ArchiveReader& ar) : mPatchFile(nullptr), mPatchIndex(-1), buf(nullptr), mArchiveReader(ar) { }
 
     virtual ~PatchFile();
 
@@ -1487,7 +1482,7 @@ private:
     unsigned char *buf;
     NS_tchar spath[MAXPATHLEN];
     AutoFile mPatchStream;
-    ArchiveReader *mArchiveReader;
+    ArchiveReader& mArchiveReader;
 };
 
 int PatchFile::sPatchIndex = 0;
@@ -1602,11 +1597,6 @@ PatchFile::Prepare()
 {
     LOG(("PREPARE PATCH " LOG_S, mFileRelPath.get()));
 
-    if(!mArchiveReader) {
-        LOG(("PatchFile runs without valid ArchiveReader"));
-        return USAGE_ERROR;
-    }
-
     // extract the patch to a temporary file
     mPatchIndex = sPatchIndex++;
 
@@ -1636,9 +1626,9 @@ PatchFile::Prepare()
         return STRING_CONVERSION_ERROR;
     }
 
-    int rv = mArchiveReader->ExtractFileToStream(sourcefile, mPatchStream);
+    int rv = mArchiveReader.ExtractFileToStream(sourcefile, mPatchStream);
 #else
-    int rv = mArchiveReader->ExtractFileToStream(mPatchFile, mPatchStream);
+    int rv = mArchiveReader.ExtractFileToStream(mPatchFile, mPatchStream);
 #endif
 
     return rv;
@@ -1798,7 +1788,7 @@ PatchFile::Finish(int status)
 class AddIfFile : public AddFile
 {
 public:
-    AddIfFile(ArchiveReader* archiveReader);
+    AddIfFile(ArchiveReader& archiveReader);
 
     virtual int Parse(NS_tchar *line);
     virtual int Prepare();
@@ -1809,7 +1799,7 @@ protected:
     std::unique_ptr<NS_tchar> mTestFile;
 };
 
-AddIfFile::AddIfFile(ArchiveReader* archiveReader):
+AddIfFile::AddIfFile(ArchiveReader& archiveReader):
     AddFile(archiveReader)
 {
 }
@@ -1865,7 +1855,7 @@ AddIfFile::Finish(int status)
 class AddIfNotFile : public AddFile
 {
 public:
-    AddIfNotFile(ArchiveReader* archiveReader);
+    AddIfNotFile(ArchiveReader& archiveReader);
 
     virtual int Parse(NS_tchar *line);
     virtual int Prepare();
@@ -1876,7 +1866,7 @@ protected:
     std::unique_ptr<NS_tchar> mTestFile;
 };
 
-AddIfNotFile::AddIfNotFile(ArchiveReader* archiveReader):
+AddIfNotFile::AddIfNotFile(ArchiveReader& archiveReader):
     AddFile(archiveReader)
 {
 }
@@ -1932,7 +1922,7 @@ AddIfNotFile::Finish(int status)
 class PatchIfFile : public PatchFile
 {
 public:
-    PatchIfFile(ArchiveReader* archiveReader);
+    PatchIfFile(ArchiveReader& archiveReader);
 
     virtual int Parse(NS_tchar *line);
     virtual int Prepare(); // should check for patch file and for checksum here
@@ -1943,7 +1933,7 @@ private:
     std::unique_ptr<NS_tchar> mTestFile;
 };
 
-PatchIfFile::PatchIfFile(ArchiveReader* archiveReader):
+PatchIfFile::PatchIfFile(ArchiveReader& archiveReader):
     PatchFile(archiveReader)
 {
 }
@@ -4546,23 +4536,23 @@ int DoUpdate(ArchiveReader& archiveReader)
         }
         else if (NS_tstrcmp(token, NS_T("add")) == 0)
         {
-            action = new AddFile(&archiveReader);
+            action = new AddFile(archiveReader);
         }
         else if (NS_tstrcmp(token, NS_T("patch")) == 0)
         {
-            action = new PatchFile(&archiveReader);
+            action = new PatchFile(archiveReader);
         }
         else if (NS_tstrcmp(token, NS_T("add-if")) == 0)   // Add if exists
         {
-            action = new AddIfFile(&archiveReader);
+            action = new AddIfFile(archiveReader);
         }
         else if (NS_tstrcmp(token, NS_T("add-if-not")) == 0)   // Add if not exists
         {
-            action = new AddIfNotFile(&archiveReader);
+            action = new AddIfNotFile(archiveReader);
         }
         else if (NS_tstrcmp(token, NS_T("patch-if")) == 0)   // Patch if exists
         {
-            action = new PatchIfFile(&archiveReader);
+            action = new PatchIfFile(archiveReader);
         }
         else
         {
commit 07586bc09138f7af3b18d8de7a40898c7303baca
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Jun 26 15:18:30 2017 +0200

    updater: reduce scope of ArchiveReader and pass by reference
    
    Change-Id: Ifbcfa5b612cb0a8670bf3dd0be6e74708cc969c1

diff --git a/onlineupdate/source/update/updater/updater.cxx b/onlineupdate/source/update/updater/updater.cxx
index d407e47b6814..3587f39d9201 100644
--- a/onlineupdate/source/update/updater/updater.cxx
+++ b/onlineupdate/source/update/updater/updater.cxx
@@ -1075,7 +1075,7 @@ static void backup_finish(const NS_tchar *path, const NS_tchar *relPath,
 
 //-----------------------------------------------------------------------------
 
-static int DoUpdate(ArchiveReader *ArchiveReader);
+static int DoUpdate(ArchiveReader& ArchiveReader);
 
 class Action
 {
@@ -2623,59 +2623,52 @@ GetUpdateFileNames(std::vector<tstring>& fileNames)
 }
 
 static int
-CheckSignature(tstring& fileName, ArchiveReader *archiveReader)
+CheckSignature(ArchiveReader& archiveReader)
 {
-    if(!archiveReader)
-        return USAGE_ERROR;
-
-    int rv = archiveReader->Open(fileName.c_str());
-
 #ifdef VERIFY_MAR_SIGNATURE
-    if (rv == OK)
-    {
 #ifdef _WIN32
-        HKEY baseKey = nullptr;
-        wchar_t valueName[] = L"Image Path";
-        wchar_t rasenh[] = L"rsaenh.dll";
-        bool reset = false;
-        if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
-                          L"SOFTWARE\\Microsoft\\Cryptography\\Defaults\\Provider\\Microsoft Enhanced Cryptographic Provider v1.0",
-                          0, KEY_READ | KEY_WRITE,
-                          &baseKey) == ERROR_SUCCESS)
+    HKEY baseKey = nullptr;
+    wchar_t valueName[] = L"Image Path";
+    wchar_t rasenh[] = L"rsaenh.dll";
+    bool reset = false;
+    if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+                      L"SOFTWARE\\Microsoft\\Cryptography\\Defaults\\Provider\\Microsoft Enhanced Cryptographic Provider v1.0",
+                      0, KEY_READ | KEY_WRITE,
+                      &baseKey) == ERROR_SUCCESS)
+    {
+        wchar_t path[MAX_PATH + 1];
+        DWORD size = sizeof(path);
+        DWORD type;
+        if (RegQueryValueExW(baseKey, valueName, 0, &type,
+                             (LPBYTE)path, &size) == ERROR_SUCCESS)
         {
-            wchar_t path[MAX_PATH + 1];
-            DWORD size = sizeof(path);
-            DWORD type;
-            if (RegQueryValueExW(baseKey, valueName, 0, &type,
-                                 (LPBYTE)path, &size) == ERROR_SUCCESS)
+            if (type == REG_SZ && wcscmp(path, rasenh) == 0)
             {
-                if (type == REG_SZ && wcscmp(path, rasenh) == 0)
+                wchar_t rasenhFullPath[] = L"%SystemRoot%\\System32\\rsaenh.dll";
+                if (RegSetValueExW(baseKey, valueName, 0, REG_SZ,
+                                   (const BYTE*)rasenhFullPath,
+                                   sizeof(rasenhFullPath)) == ERROR_SUCCESS)
                 {
-                    wchar_t rasenhFullPath[] = L"%SystemRoot%\\System32\\rsaenh.dll";
-                    if (RegSetValueExW(baseKey, valueName, 0, REG_SZ,
-                                       (const BYTE*)rasenhFullPath,
-                                       sizeof(rasenhFullPath)) == ERROR_SUCCESS)
-                    {
-                        reset = true;
-                    }
+                    reset = true;
                 }
             }
         }
+    }
 #endif
-        rv = archiveReader->VerifySignature();
+    int rv = archiveReader.VerifySignature();
 #ifdef _WIN32
-        if (baseKey)
+    if (baseKey)
+    {
+        if (reset)
         {
-            if (reset)
-            {
-                RegSetValueExW(baseKey, valueName, 0, REG_SZ,
-                               (const BYTE*)rasenh,
-                               sizeof(rasenh));
-            }
-            RegCloseKey(baseKey);
+            RegSetValueExW(baseKey, valueName, 0, REG_SZ,
+                           (const BYTE*)rasenh,
+                           sizeof(rasenh));
         }
-#endif
+        RegCloseKey(baseKey);
     }
+#endif
+
 
     if (rv == OK)
     {
@@ -2701,14 +2694,12 @@ CheckSignature(tstring& fileName, ArchiveReader *archiveReader)
                 MARStrings.MARChannelID[0] = '\0';
             }
 
-            rv = archiveReader->VerifyProductInformation(MARStrings.MARChannelID,
+            rv = archiveReader.VerifyProductInformation(MARStrings.MARChannelID,
                     LIBO_VERSION_DOTTED);
         }
     }
 #endif
 
-    archiveReader->Close();
-
     return rv;
 }
 
@@ -2726,10 +2717,17 @@ UpdateThreadFunc(void * /*param*/)
         std::vector<tstring> fileNames;
         GetUpdateFileNames(fileNames);
 
-        ArchiveReader archiveReader;
         for (auto& fileName: fileNames)
         {
-            rv = CheckSignature(fileName, &archiveReader);
+            ArchiveReader archiveReader;
+            rv = archiveReader.Open(fileName.c_str());
+            if (rv != OK)
+            {
+                LOG(("Could not open " LOG_S, fileName.c_str()));
+                break;
+            }
+
+            rv = CheckSignature(archiveReader);
             if (rv != OK)
             {
                 LOG(("Could not verify the signature of " LOG_S, fileName.c_str()));
@@ -2746,9 +2744,9 @@ UpdateThreadFunc(void * /*param*/)
         {
             for (auto& fileName: fileNames)
             {
+                ArchiveReader archiveReader;
                 archiveReader.Open(fileName.c_str());
-                rv = DoUpdate(&archiveReader);
-                archiveReader.Close();
+                rv = DoUpdate(archiveReader);
             }
             NS_tchar updatingDir[MAXPATHLEN];
             NS_tsnprintf(updatingDir, sizeof(updatingDir)/sizeof(updatingDir[0]),
@@ -4457,11 +4455,8 @@ int AddPreCompleteActions(ActionList *list)
     return OK;
 }
 
-int DoUpdate(ArchiveReader *archiveReader)
+int DoUpdate(ArchiveReader& archiveReader)
 {
-    if(!archiveReader)
-        return USAGE_ERROR;
-
     NS_tchar manifest[MAXPATHLEN];
     NS_tsnprintf(manifest, sizeof(manifest)/sizeof(manifest[0]),
                  NS_T("%s/updating/update.manifest"), gWorkingDirPath);
@@ -4470,10 +4465,10 @@ int DoUpdate(ArchiveReader *archiveReader)
     // extract the manifest
     // TODO: moggi: needs adaption for LibreOffice
     // Why would we need the manifest? Even if we need it why would we need 2?
-    int rv = archiveReader->ExtractFile("updatev3.manifest", manifest);
+    int rv = archiveReader.ExtractFile("updatev3.manifest", manifest);
     if (rv)
     {
-        rv = archiveReader->ExtractFile("updatev2.manifest", manifest);
+        rv = archiveReader.ExtractFile("updatev2.manifest", manifest);
         if (rv)
         {
             LOG(("DoUpdate: error extracting manifest file"));
commit 95eae33ae8db583ebf4ff0cdfc3e3a48915a706b
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Jun 26 15:17:37 2017 +0200

    updater: subclasses need to pass the archiveReader parameter to their parents
    
    Change-Id: I1d69d592a05908e4e2a2e832a5b6ef9d13fc2e2c

diff --git a/onlineupdate/source/update/updater/updater.cxx b/onlineupdate/source/update/updater/updater.cxx
index 218595034e55..d407e47b6814 100644
--- a/onlineupdate/source/update/updater/updater.cxx
+++ b/onlineupdate/source/update/updater/updater.cxx
@@ -1367,9 +1367,6 @@ public:
     virtual int Execute();
     virtual void Finish(int status);
 
-protected:
-    AddFile() : mAdded(false), mArchiveReader(nullptr) { }
-
 private:
     std::unique_ptr<NS_tchar> mFile;
     std::unique_ptr<NS_tchar> mRelPath;
@@ -1477,9 +1474,6 @@ public:
     virtual int Execute();
     virtual void Finish(int status);
 
-protected:
-    PatchFile() : mPatchFile(nullptr), mPatchIndex(-1), buf(nullptr), mArchiveReader(nullptr) {}
-
 private:
     int LoadSourceFile(FILE* ofile);
 
@@ -1804,6 +1798,8 @@ PatchFile::Finish(int status)
 class AddIfFile : public AddFile
 {
 public:
+    AddIfFile(ArchiveReader* archiveReader);
+
     virtual int Parse(NS_tchar *line);
     virtual int Prepare();
     virtual int Execute();
@@ -1813,6 +1809,11 @@ protected:
     std::unique_ptr<NS_tchar> mTestFile;
 };
 
+AddIfFile::AddIfFile(ArchiveReader* archiveReader):
+    AddFile(archiveReader)
+{
+}
+
 int
 AddIfFile::Parse(NS_tchar *line)
 {
@@ -1864,6 +1865,8 @@ AddIfFile::Finish(int status)
 class AddIfNotFile : public AddFile
 {
 public:
+    AddIfNotFile(ArchiveReader* archiveReader);
+
     virtual int Parse(NS_tchar *line);
     virtual int Prepare();
     virtual int Execute();
@@ -1873,6 +1876,11 @@ protected:
     std::unique_ptr<NS_tchar> mTestFile;
 };
 
+AddIfNotFile::AddIfNotFile(ArchiveReader* archiveReader):
+    AddFile(archiveReader)
+{
+}
+
 int
 AddIfNotFile::Parse(NS_tchar *line)
 {
@@ -1924,6 +1932,8 @@ AddIfNotFile::Finish(int status)
 class PatchIfFile : public PatchFile
 {
 public:
+    PatchIfFile(ArchiveReader* archiveReader);
+
     virtual int Parse(NS_tchar *line);
     virtual int Prepare(); // should check for patch file and for checksum here
     virtual int Execute();
@@ -1933,6 +1943,11 @@ private:
     std::unique_ptr<NS_tchar> mTestFile;
 };
 
+PatchIfFile::PatchIfFile(ArchiveReader* archiveReader):
+    PatchFile(archiveReader)
+{
+}
+
 int
 PatchIfFile::Parse(NS_tchar *line)
 {
@@ -4536,23 +4551,23 @@ int DoUpdate(ArchiveReader *archiveReader)
         }
         else if (NS_tstrcmp(token, NS_T("add")) == 0)
         {
-            action = new AddFile(archiveReader);
+            action = new AddFile(&archiveReader);
         }
         else if (NS_tstrcmp(token, NS_T("patch")) == 0)
         {
-            action = new PatchFile(archiveReader);
+            action = new PatchFile(&archiveReader);
         }
         else if (NS_tstrcmp(token, NS_T("add-if")) == 0)   // Add if exists
         {
-            action = new AddIfFile();
+            action = new AddIfFile(&archiveReader);
         }
         else if (NS_tstrcmp(token, NS_T("add-if-not")) == 0)   // Add if not exists
         {
-            action = new AddIfNotFile();
+            action = new AddIfNotFile(&archiveReader);
         }
         else if (NS_tstrcmp(token, NS_T("patch-if")) == 0)   // Patch if exists
         {
-            action = new PatchIfFile();
+            action = new PatchIfFile(&archiveReader);
         }
         else
         {
commit c806dab3c99a730430e02ea0d1ccecdb5d688423
Author: Christian Barth <Christian.Barth at zoho.com>
Date:   Sun Jun 25 21:43:42 2017 +0200

    tdf#108563 Transform global variable gArchiveReader to local variable
    
    Change-Id: I0830f00bce19bc4b77d8e9e0cb5684338a4c9e5d
    Signed-off-by: Christian Barth <Christian.Barth at zoho.com>

diff --git a/onlineupdate/source/update/updater/updater.cxx b/onlineupdate/source/update/updater/updater.cxx
index 01ca1a2475a9..218595034e55 100644
--- a/onlineupdate/source/update/updater/updater.cxx
+++ b/onlineupdate/source/update/updater/updater.cxx
@@ -223,7 +223,6 @@ struct MARChannelStringTable
 static NS_tchar* gPatchDirPath;
 static NS_tchar gInstallDirPath[MAXPATHLEN];
 static NS_tchar gWorkingDirPath[MAXPATHLEN];
-static ArchiveReader gArchiveReader;
 static bool gSucceeded = false;
 static bool sStagedUpdate = false;
 static bool sReplaceRequest = false;
@@ -1076,7 +1075,7 @@ static void backup_finish(const NS_tchar *path, const NS_tchar *relPath,
 
 //-----------------------------------------------------------------------------
 
-static int DoUpdate();
+static int DoUpdate(ArchiveReader *ArchiveReader);
 
 class Action
 {
@@ -1361,17 +1360,21 @@ RemoveDir::Finish(int status)
 class AddFile : public Action
 {
 public:
-    AddFile() : mAdded(false) { }
+    AddFile(ArchiveReader *ar) : mAdded(false), mArchiveReader(ar) { }
 
     virtual int Parse(NS_tchar *line);
     virtual int Prepare();
     virtual int Execute();
     virtual void Finish(int status);
 
+protected:
+    AddFile() : mAdded(false), mArchiveReader(nullptr) { }
+
 private:
     std::unique_ptr<NS_tchar> mFile;
     std::unique_ptr<NS_tchar> mRelPath;
     bool mAdded;
+    ArchiveReader *mArchiveReader;
 };
 
 int
@@ -1411,6 +1414,11 @@ AddFile::Execute()
 
     int rv;
 
+    if(!mArchiveReader) {
+        LOG(("AddFile runs without valid ArchiveReader"));
+        return USAGE_ERROR;
+    }
+
     // First make sure that we can actually get rid of any existing file.
     rv = NS_taccess(mFile.get(), F_OK);
     if (rv == 0)
@@ -1435,9 +1443,9 @@ AddFile::Execute()
         return STRING_CONVERSION_ERROR;
     }
 
-    rv = gArchiveReader.ExtractFile(sourcefile, mFile.get());
+    rv = mArchiveReader->ExtractFile(sourcefile, mFile.get());
 #else
-    rv = gArchiveReader.ExtractFile(mRelPath.get(), mFile.get());
+    rv = mArchiveReader->ExtractFile(mRelPath.get(), mFile.get());
 #endif
     if (!rv)
     {
@@ -1460,7 +1468,7 @@ AddFile::Finish(int status)
 class PatchFile : public Action
 {
 public:
-    PatchFile() : mPatchFile(nullptr), mPatchIndex(-1), buf(nullptr) { }
+    PatchFile(ArchiveReader *ar) : mPatchFile(nullptr), mPatchIndex(-1), buf(nullptr), mArchiveReader(ar) { }
 
     virtual ~PatchFile();
 
@@ -1469,6 +1477,9 @@ public:
     virtual int Execute();
     virtual void Finish(int status);
 
+protected:
+    PatchFile() : mPatchFile(nullptr), mPatchIndex(-1), buf(nullptr), mArchiveReader(nullptr) {}
+
 private:
     int LoadSourceFile(FILE* ofile);
 
@@ -1482,6 +1493,7 @@ private:
     unsigned char *buf;
     NS_tchar spath[MAXPATHLEN];
     AutoFile mPatchStream;
+    ArchiveReader *mArchiveReader;
 };
 
 int PatchFile::sPatchIndex = 0;
@@ -1596,6 +1608,11 @@ PatchFile::Prepare()
 {
     LOG(("PREPARE PATCH " LOG_S, mFileRelPath.get()));
 
+    if(!mArchiveReader) {
+        LOG(("PatchFile runs without valid ArchiveReader"));
+        return USAGE_ERROR;
+    }
+
     // extract the patch to a temporary file
     mPatchIndex = sPatchIndex++;
 
@@ -1625,9 +1642,9 @@ PatchFile::Prepare()
         return STRING_CONVERSION_ERROR;
     }
 
-    int rv = gArchiveReader.ExtractFileToStream(sourcefile, mPatchStream);
+    int rv = mArchiveReader->ExtractFileToStream(sourcefile, mPatchStream);
 #else
-    int rv = gArchiveReader.ExtractFileToStream(mPatchFile, mPatchStream);
+    int rv = mArchiveReader->ExtractFileToStream(mPatchFile, mPatchStream);
 #endif
 
     return rv;
@@ -2591,9 +2608,12 @@ GetUpdateFileNames(std::vector<tstring>& fileNames)
 }
 
 static int
-CheckSignature(tstring& fileName)
+CheckSignature(tstring& fileName, ArchiveReader *archiveReader)
 {
-    int rv = gArchiveReader.Open(fileName.c_str());
+    if(!archiveReader)
+        return USAGE_ERROR;
+
+    int rv = archiveReader->Open(fileName.c_str());
 
 #ifdef VERIFY_MAR_SIGNATURE
     if (rv == OK)
@@ -2627,7 +2647,7 @@ CheckSignature(tstring& fileName)
             }
         }
 #endif
-        rv = gArchiveReader.VerifySignature();
+        rv = archiveReader->VerifySignature();
 #ifdef _WIN32
         if (baseKey)
         {
@@ -2666,13 +2686,13 @@ CheckSignature(tstring& fileName)
                 MARStrings.MARChannelID[0] = '\0';
             }
 
-            rv = gArchiveReader.VerifyProductInformation(MARStrings.MARChannelID,
+            rv = archiveReader->VerifyProductInformation(MARStrings.MARChannelID,
                     LIBO_VERSION_DOTTED);
         }
     }
 #endif
 
-    gArchiveReader.Close();
+    archiveReader->Close();
 
     return rv;
 }
@@ -2691,9 +2711,10 @@ UpdateThreadFunc(void * /*param*/)
         std::vector<tstring> fileNames;
         GetUpdateFileNames(fileNames);
 
+        ArchiveReader archiveReader;
         for (auto& fileName: fileNames)
         {
-            rv = CheckSignature(fileName);
+            rv = CheckSignature(fileName, &archiveReader);
             if (rv != OK)
             {
                 LOG(("Could not verify the signature of " LOG_S, fileName.c_str()));
@@ -2710,9 +2731,9 @@ UpdateThreadFunc(void * /*param*/)
         {
             for (auto& fileName: fileNames)
             {
-                gArchiveReader.Open(fileName.c_str());
-                rv = DoUpdate();
-                gArchiveReader.Close();
+                archiveReader.Open(fileName.c_str());
+                rv = DoUpdate(&archiveReader);
+                archiveReader.Close();
             }
             NS_tchar updatingDir[MAXPATHLEN];
             NS_tsnprintf(updatingDir, sizeof(updatingDir)/sizeof(updatingDir[0]),
@@ -4421,8 +4442,11 @@ int AddPreCompleteActions(ActionList *list)
     return OK;
 }
 
-int DoUpdate()
+int DoUpdate(ArchiveReader *archiveReader)
 {
+    if(!archiveReader)
+        return USAGE_ERROR;
+
     NS_tchar manifest[MAXPATHLEN];
     NS_tsnprintf(manifest, sizeof(manifest)/sizeof(manifest[0]),
                  NS_T("%s/updating/update.manifest"), gWorkingDirPath);
@@ -4431,10 +4455,10 @@ int DoUpdate()
     // extract the manifest
     // TODO: moggi: needs adaption for LibreOffice
     // Why would we need the manifest? Even if we need it why would we need 2?
-    int rv = gArchiveReader.ExtractFile("updatev3.manifest", manifest);
+    int rv = archiveReader->ExtractFile("updatev3.manifest", manifest);
     if (rv)
     {
-        rv = gArchiveReader.ExtractFile("updatev2.manifest", manifest);
+        rv = archiveReader->ExtractFile("updatev2.manifest", manifest);
         if (rv)
         {
             LOG(("DoUpdate: error extracting manifest file"));
@@ -4450,7 +4474,6 @@ int DoUpdate()
         return READ_ERROR;
     }
 
-
     ActionList list;
     NS_tchar *line;
     bool isFirstAction = true;
@@ -4513,11 +4536,11 @@ int DoUpdate()
         }
         else if (NS_tstrcmp(token, NS_T("add")) == 0)
         {
-            action = new AddFile();
+            action = new AddFile(archiveReader);
         }
         else if (NS_tstrcmp(token, NS_T("patch")) == 0)
         {
-            action = new PatchFile();
+            action = new PatchFile(archiveReader);
         }
         else if (NS_tstrcmp(token, NS_T("add-if")) == 0)   // Add if exists
         {


More information about the Libreoffice-commits mailing list