Kaydet (Commit) db59b84a authored tarafından Markus Mohrhard's avatar Markus Mohrhard

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
üst 5e1d8ada
...@@ -70,6 +70,7 @@ static inline int mywcsprintf(WCHAR* dest, size_t count, const WCHAR* fmt, ...) ...@@ -70,6 +70,7 @@ static inline int mywcsprintf(WCHAR* dest, size_t count, const WCHAR* fmt, ...)
# define NS_tstat_t _stat # define NS_tstat_t _stat
# define NS_tstrcat wcscat # define NS_tstrcat wcscat
# define NS_tstrcmp wcscmp # define NS_tstrcmp wcscmp
# define NS_tstrncmp wcsncmp
# define NS_tstricmp wcsicmp # define NS_tstricmp wcsicmp
# define NS_tstrcpy wcscpy # define NS_tstrcpy wcscpy
# define NS_tstrncpy wcsncpy # define NS_tstrncpy wcsncpy
...@@ -115,6 +116,7 @@ static inline int mywcsprintf(WCHAR* dest, size_t count, const WCHAR* fmt, ...) ...@@ -115,6 +116,7 @@ static inline int mywcsprintf(WCHAR* dest, size_t count, const WCHAR* fmt, ...)
# define NS_tlstat lstat # define NS_tlstat lstat
# define NS_tstrcat strcat # define NS_tstrcat strcat
# define NS_tstrcmp strcmp # define NS_tstrcmp strcmp
# define NS_tstrncmp strncmp
# define NS_tstricmp strcasecmp # define NS_tstricmp strcasecmp
# define NS_tstrcpy strcpy # define NS_tstrcpy strcpy
# define NS_tstrncpy strncpy # define NS_tstrncpy strncpy
......
...@@ -332,6 +332,32 @@ get_full_path(const NS_tchar *relpath) ...@@ -332,6 +332,32 @@ get_full_path(const NS_tchar *relpath)
return s; 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. * Converts a full update path into a relative path; reverses get_full_path.
* *
...@@ -2406,6 +2432,31 @@ ProcessReplaceRequest() ...@@ -2406,6 +2432,31 @@ ProcessReplaceRequest()
return rv; 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) #if !defined(_WIN32) && !defined(MACOSX)
// Platforms that have their updates directory in the installation directory // 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 // need to have the last-update.log and backup-update.log files moved from the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment