summaryrefslogtreecommitdiffstats
path: root/onlineupdate/source
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2017-05-05 06:55:02 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2017-05-19 03:43:33 +0200
commitdb59b84a319c3309985fbe27672e68b84d84d7ad (patch)
tree7331285ec22f872514a88814b968801ca5c0bf13 /onlineupdate/source
parentfirst step into supporting user profile in installation dir (diff)
downloadcore-db59b84a319c3309985fbe27672e68b84d84d7ad.tar.gz
core-db59b84a319c3309985fbe27672e68b84d84d7ad.zip
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
Diffstat (limited to 'onlineupdate/source')
-rw-r--r--onlineupdate/source/update/common/updatedefines.h2
-rw-r--r--onlineupdate/source/update/updater/updater.cxx51
2 files changed, 53 insertions, 0 deletions
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