[Libreoffice-commits] core.git: Branch 'feature/mar-updater' - 3 commits - onlineupdate/inc onlineupdate/source

Markus Mohrhard markus.mohrhard at googlemail.com
Fri May 5 04:57:17 UTC 2017


 onlineupdate/inc/types.hxx                         |   25 ++++++
 onlineupdate/source/update/common/readstrings.h    |    7 -
 onlineupdate/source/update/common/updatedefines.h  |    2 
 onlineupdate/source/update/updater/archivereader.h |    7 -
 onlineupdate/source/update/updater/progressui.h    |    3 
 onlineupdate/source/update/updater/updater.cxx     |   80 +++++++++++++++++++--
 6 files changed, 104 insertions(+), 20 deletions(-)

New commits:
commit 5e8da3ee848df84e9376ee450c44ea08a4e649e0
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri May 5 06:55:02 2017 +0200

    second part for user profile in instdir
    
    This handles the replacement request part.
    
    The algorithm moves the user profile out of the backup back into the
    user profile.
    
    Change-Id: Ide45009d7a42b01ee645418b1a0c30b211842510

diff --git a/onlineupdate/source/update/common/updatedefines.h b/onlineupdate/source/update/common/updatedefines.h
index acca6887f422..748f9e098dd6 100644
--- a/onlineupdate/source/update/common/updatedefines.h
+++ b/onlineupdate/source/update/common/updatedefines.h
@@ -70,6 +70,7 @@ static inline int mywcsprintf(WCHAR* dest, size_t count, const WCHAR* fmt, ...)
 # define NS_tstat_t _stat
 # define NS_tstrcat wcscat
 # define NS_tstrcmp wcscmp
+# define NS_tstrncmp wcsncmp
 # define NS_tstricmp wcsicmp
 # define NS_tstrcpy wcscpy
 # define NS_tstrncpy wcsncpy
@@ -115,6 +116,7 @@ static inline int mywcsprintf(WCHAR* dest, size_t count, const WCHAR* fmt, ...)
 # define NS_tlstat lstat
 # define NS_tstrcat strcat
 # define NS_tstrcmp strcmp
+# define NS_tstrncmp strncmp
 # define NS_tstricmp strcasecmp
 # define NS_tstrcpy strcpy
 # define NS_tstrncpy strncpy
diff --git a/onlineupdate/source/update/updater/updater.cxx b/onlineupdate/source/update/updater/updater.cxx
index e6eb3855286c..e81fd89e840b 100644
--- a/onlineupdate/source/update/updater/updater.cxx
+++ b/onlineupdate/source/update/updater/updater.cxx
@@ -332,6 +332,32 @@ get_full_path(const NS_tchar *relpath)
     return s;
 }
 
+namespace {
+
+bool is_userprofile_in_instdir()
+{
+    // the algorithm is:
+    // 1.) if userprofile path length is smaller than installation dir,
+    //      the profile is surely not in instdir
+    // 2.) else comparing the two paths looking only at the installation dir
+    //      characters should yield an equal string
+    NS_tchar userprofile[MAXPATHLEN];
+    NS_tstrcpy(userprofile, gPatchDirPath);
+    NS_tchar *slash = (NS_tchar *) NS_tstrrchr(userprofile, NS_T('/'));
+    if (slash)
+        *slash = NS_T('\0');
+
+    size_t userprofile_len = NS_tstrlen(userprofile);
+    size_t installdir_len = NS_tstrlen(gInstallDirPath);
+
+    if (userprofile_len < installdir_len)
+        return false;
+
+    return NS_tstrncmp(userprofile, gInstallDirPath, installdir_len) == 0;
+}
+
+}
+
 /**
  * Converts a full update path into a relative path; reverses get_full_path.
  *
@@ -2406,6 +2432,31 @@ ProcessReplaceRequest()
         return rv;
     }
 
+    if (is_userprofile_in_instdir())
+    {
+        // 1.) calculate path of the user profile in the backup directory
+        // 2.) move the user profile from the backup to the install directory
+        NS_tchar backup_user_profile[MAXPATHLEN];
+        NS_tchar userprofile[MAXPATHLEN];
+
+        NS_tstrcpy(userprofile, gPatchDirPath);
+        NS_tchar *slash = (NS_tchar *) NS_tstrrchr(userprofile, NS_T('/'));
+        if (slash)
+            *slash = NS_T('\0');
+        NS_tstrcpy(backup_user_profile, tmpDir);
+        size_t installdir_len = NS_tstrlen(destDir);
+
+        NS_tstrcat(backup_user_profile, userprofile + installdir_len);
+        if (slash)
+            *slash = NS_T('/');
+        LOG(("copy user profile back from " LOG_S " to " LOG_S, backup_user_profile, userprofile));
+        int rv2 = rename_file(backup_user_profile, userprofile);
+        if (rv2)
+        {
+            LOG(("failed to copy user profile back"));
+        }
+    }
+
 #if !defined(_WIN32) && !defined(MACOSX)
     // Platforms that have their updates directory in the installation directory
     // need to have the last-update.log and backup-update.log files moved from the
commit 79ec65870e7afda17176ee9b51c2230e010ea57e
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri May 5 04:46:30 2017 +0200

    first step into supporting user profile in installation dir
    
    Change-Id: I2485ad2b69ed28b7f964540ac3eecd22099b4f7c

diff --git a/onlineupdate/source/update/updater/updater.cxx b/onlineupdate/source/update/updater/updater.cxx
index 1e36b4d300f8..e6eb3855286c 100644
--- a/onlineupdate/source/update/updater/updater.cxx
+++ b/onlineupdate/source/update/updater/updater.cxx
@@ -735,6 +735,11 @@ struct copy_recursive_skiplist
         NS_tsnprintf(paths[index], MAXPATHLEN, NS_T("%s/%s"), path, suffix);
     }
 
+    void append(unsigned index, const NS_tchar* path)
+    {
+        NS_tstrcpy(paths[index], path);
+    }
+
     bool find(const NS_tchar *path)
     {
         for (int i = 0; i < static_cast<int>(N); ++i)
@@ -2262,18 +2267,28 @@ CopyInstallDirToDestDir()
 {
     // These files should not be copied over to the updated app
 #ifdef _WIN32
-#define SKIPLIST_COUNT 3
+#define SKIPLIST_COUNT 4
 #elif defined(MACOSX)
-#define SKIPLIST_COUNT 0
+#define SKIPLIST_COUNT 1
 #else
-#define SKIPLIST_COUNT 2
+#define SKIPLIST_COUNT 3
 #endif
     copy_recursive_skiplist<SKIPLIST_COUNT> skiplist;
+
+    std::unique_ptr<NS_tchar> pUserProfile(new NS_tchar[MAXPATHLEN]);
+    NS_tstrcpy(pUserProfile.get(), gPatchDirPath);
+    NS_tchar *slash = (NS_tchar *) NS_tstrrchr(pUserProfile.get(), NS_T('/'));
+    if (slash)
+        *slash = NS_T('\0');
+
+    LOG(("ignore user profile directory during copy: " LOG_S, pUserProfile.get()));
+
+    skiplist.append(0, pUserProfile.get());
 #ifndef MACOSX
-    skiplist.append(0, gInstallDirPath, NS_T("updated"));
-    skiplist.append(1, gInstallDirPath, NS_T("updates/0"));
+    skiplist.append(1, gInstallDirPath, NS_T("updated"));
+    skiplist.append(2, gInstallDirPath, NS_T("updates/0"));
 #ifdef _WIN32
-    skiplist.append(2, gInstallDirPath, NS_T("updated.update_in_progress.lock"));
+    skiplist.append(4, gInstallDirPath, NS_T("updated.update_in_progress.lock"));
 #endif
 #endif
 
@@ -2289,6 +2304,8 @@ CopyInstallDirToDestDir()
 static int
 ProcessReplaceRequest()
 {
+    // TODO: moggi: handle the user profile in the installation dir also
+    // during the replacement request
     // The replacement algorithm is like this:
     // 1. Move destDir to tmpDir.  In case of failure, abort.
     // 2. Move newDir to destDir.  In case of failure, revert step 1 and abort.
commit d3d75a6c26e4a71ca0acd3a029cfcf84c3e26425
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri May 5 03:07:02 2017 +0200

    extract string typedefs to a shared file
    
    Change-Id: I6e5d7c828f56b6a3f562ed8a9dd5f63a9d603ce0

diff --git a/onlineupdate/inc/types.hxx b/onlineupdate/inc/types.hxx
new file mode 100644
index 000000000000..3e83a19c7d78
--- /dev/null
+++ b/onlineupdate/inc/types.hxx
@@ -0,0 +1,25 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_ONLINEUPDATE_TYPES_HXX
+#define INCLUDED_ONLINEUPDATE_TYPES_HXX
+
+#include <string>
+
+#if defined(_WIN32)
+typedef std::wstring tstring;
+typedef WCHAR NS_tchar;
+#else
+typedef std::string tstring;
+typedef char NS_tchar;
+#endif
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/onlineupdate/source/update/common/readstrings.h b/onlineupdate/source/update/common/readstrings.h
index bc837ef326b5..747081394c10 100644
--- a/onlineupdate/source/update/common/readstrings.h
+++ b/onlineupdate/source/update/common/readstrings.h
@@ -11,14 +11,9 @@
 
 #ifdef _WIN32
 # include <windows.h>
-typedef WCHAR NS_tchar;
-#else
-typedef char NS_tchar;
 #endif
 
-#ifndef NULL
-#define NULL 0
-#endif
+#include "types.hxx"
 
 struct StringTable
 {
diff --git a/onlineupdate/source/update/updater/archivereader.h b/onlineupdate/source/update/updater/archivereader.h
index 9b7885dc0103..090b787f9cf5 100644
--- a/onlineupdate/source/update/updater/archivereader.h
+++ b/onlineupdate/source/update/updater/archivereader.h
@@ -9,12 +9,7 @@
 
 #include <stdio.h>
 #include <onlineupdate/mar.h>
-
-#ifdef _WIN32
-typedef WCHAR NS_tchar;
-#else
-typedef char NS_tchar;
-#endif
+#include "types.hxx"
 
 // This class provides an API to extract files from an update archive.
 class ArchiveReader
diff --git a/onlineupdate/source/update/updater/progressui.h b/onlineupdate/source/update/updater/progressui.h
index 455ae125180a..cb1468d3949c 100644
--- a/onlineupdate/source/update/updater/progressui.h
+++ b/onlineupdate/source/update/updater/progressui.h
@@ -8,12 +8,11 @@
 #define PROGRESSUI_H__
 
 #include "updatedefines.h"
+#include "types.hxx"
 
 #if defined(_WIN32)
-typedef WCHAR NS_tchar;
 #define NS_main wmain
 #else
-typedef char NS_tchar;
 #define NS_main main
 #endif
 


More information about the Libreoffice-commits mailing list