Rename online updater functions and strcmp relpath
Try to be more explicit about the newly allocated absolute path and the relative offset and actually compare the relative part. -get_full_path(const NS_tchar *relpath) +new_absolute_path(const NS_tchar *relpath) -get_relative_path(const NS_tchar *fullpath) +get_relative_offset(const NS_tchar *abs_path) Change-Id: I02abd722fc89a1688502b9c5cd375954f9f0bc05 Reviewed-on: https://gerrit.libreoffice.org/60168 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
This commit is contained in:
@@ -301,14 +301,15 @@ EnvHasValue(const char *name)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Coverts a relative update path to a full path.
|
* Coverts a relative update path to a absolute path related to the working
|
||||||
|
* or install directory. Allocates a new NS_tchar[] based path!
|
||||||
*
|
*
|
||||||
* @param relpath
|
* @param relpath
|
||||||
* The relative path to convert to a full path.
|
* The relative path to convert to a full path.
|
||||||
* @return valid filesystem full path or nullptr if memory allocation fails.
|
* @return valid filesystem full path or nullptr if memory allocation fails.
|
||||||
*/
|
*/
|
||||||
static NS_tchar*
|
static NS_tchar*
|
||||||
get_full_path(const NS_tchar *relpath)
|
new_absolute_path(const NS_tchar *relpath)
|
||||||
{
|
{
|
||||||
NS_tchar *destpath = sStagedUpdate ? gWorkingDirPath : gInstallDirPath;
|
NS_tchar *destpath = sStagedUpdate ? gWorkingDirPath : gInstallDirPath;
|
||||||
size_t lendestpath = NS_tstrlen(destpath);
|
size_t lendestpath = NS_tstrlen(destpath);
|
||||||
@@ -358,36 +359,36 @@ bool is_userprofile_in_instdir()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a full update path into a relative path; reverses get_full_path.
|
* Get a pointer in the absolute path, relative to the working or install
|
||||||
|
* directory. Returns itself, if not absolute or outside of the directory.
|
||||||
*
|
*
|
||||||
* @param fullpath
|
* @param abs_path
|
||||||
* The absolute path to convert into a relative path.
|
* An absolute path.
|
||||||
* return pointer to the location within fullpath where the relative path starts
|
* return pointer to the location within fullpath where the relative path starts
|
||||||
* or fullpath itself if it already looks relative.
|
* or fullpath itself if it already looks relative.
|
||||||
*/
|
*/
|
||||||
static const NS_tchar*
|
static const NS_tchar*
|
||||||
get_relative_path(const NS_tchar *fullpath)
|
get_relative_offset(const NS_tchar *abs_path)
|
||||||
{
|
{
|
||||||
// If the path isn't absolute, just return it as-is.
|
// If the path isn't absolute, just return it as-is.
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (fullpath[1] != ':' && fullpath[2] != '\\')
|
if (abs_path[1] != ':' && abs_path[2] != '\\')
|
||||||
{
|
{
|
||||||
#else
|
#else
|
||||||
if (fullpath[0] != '/')
|
if (abs_path[0] != '/')
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
return fullpath;
|
return abs_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_tchar *prefix = sStagedUpdate ? gWorkingDirPath : gInstallDirPath;
|
NS_tchar *prefix = sStagedUpdate ? gWorkingDirPath : gInstallDirPath;
|
||||||
|
|
||||||
// If the path isn't long enough to be absolute, return it as-is.
|
size_t len = NS_tstrlen(prefix);
|
||||||
if (NS_tstrlen(fullpath) <= NS_tstrlen(prefix))
|
if (NS_tstrlen(abs_path) <= len)
|
||||||
{
|
return abs_path;
|
||||||
return fullpath;
|
if (0 != strncmp(abs_path, prefix, len))
|
||||||
}
|
return abs_path;
|
||||||
|
return abs_path + len + 1;
|
||||||
return fullpath + NS_tstrlen(prefix) + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1136,7 +1137,7 @@ RemoveFile::Parse(NS_tchar *line)
|
|||||||
mRelPath.reset(new NS_tchar[MAXPATHLEN]);
|
mRelPath.reset(new NS_tchar[MAXPATHLEN]);
|
||||||
NS_tstrcpy(mRelPath.get(), validPath);
|
NS_tstrcpy(mRelPath.get(), validPath);
|
||||||
|
|
||||||
mFile.reset(get_full_path(validPath));
|
mFile.reset(new_absolute_path(validPath));
|
||||||
if (!mFile)
|
if (!mFile)
|
||||||
{
|
{
|
||||||
return PARSE_ERROR;
|
return PARSE_ERROR;
|
||||||
@@ -1264,7 +1265,7 @@ RemoveDir::Parse(NS_tchar *line)
|
|||||||
mRelPath.reset(new NS_tchar[MAXPATHLEN]);
|
mRelPath.reset(new NS_tchar[MAXPATHLEN]);
|
||||||
NS_tstrcpy(mRelPath.get(), validPath);
|
NS_tstrcpy(mRelPath.get(), validPath);
|
||||||
|
|
||||||
mDir.reset(get_full_path(validPath));
|
mDir.reset(new_absolute_path(validPath));
|
||||||
if (!mDir)
|
if (!mDir)
|
||||||
{
|
{
|
||||||
return PARSE_ERROR;
|
return PARSE_ERROR;
|
||||||
@@ -1390,7 +1391,7 @@ AddFile::Parse(NS_tchar *line)
|
|||||||
mRelPath.reset(new NS_tchar[MAXPATHLEN]);
|
mRelPath.reset(new NS_tchar[MAXPATHLEN]);
|
||||||
NS_tstrcpy(mRelPath.get(), validPath);
|
NS_tstrcpy(mRelPath.get(), validPath);
|
||||||
|
|
||||||
mFile.reset(get_full_path(validPath));
|
mFile.reset(new_absolute_path(validPath));
|
||||||
if (!mFile)
|
if (!mFile)
|
||||||
{
|
{
|
||||||
return PARSE_ERROR;
|
return PARSE_ERROR;
|
||||||
@@ -1586,7 +1587,7 @@ PatchFile::Parse(NS_tchar *line)
|
|||||||
mFileRelPath.reset(new NS_tchar[MAXPATHLEN]);
|
mFileRelPath.reset(new NS_tchar[MAXPATHLEN]);
|
||||||
NS_tstrcpy(mFileRelPath.get(), validPath);
|
NS_tstrcpy(mFileRelPath.get(), validPath);
|
||||||
|
|
||||||
mFile.reset(get_full_path(validPath));
|
mFile.reset(new_absolute_path(validPath));
|
||||||
if (!mFile)
|
if (!mFile)
|
||||||
{
|
{
|
||||||
return PARSE_ERROR;
|
return PARSE_ERROR;
|
||||||
@@ -1812,7 +1813,7 @@ AddIfFile::Parse(NS_tchar *line)
|
|||||||
{
|
{
|
||||||
// format "<testfile>" "<newfile>"
|
// format "<testfile>" "<newfile>"
|
||||||
|
|
||||||
mTestFile.reset(get_full_path(get_valid_path(&line)));
|
mTestFile.reset(new_absolute_path(get_valid_path(&line)));
|
||||||
if (!mTestFile)
|
if (!mTestFile)
|
||||||
return PARSE_ERROR;
|
return PARSE_ERROR;
|
||||||
|
|
||||||
@@ -1879,7 +1880,7 @@ AddIfNotFile::Parse(NS_tchar *line)
|
|||||||
{
|
{
|
||||||
// format "<testfile>" "<newfile>"
|
// format "<testfile>" "<newfile>"
|
||||||
|
|
||||||
mTestFile.reset(get_full_path(get_valid_path(&line)));
|
mTestFile.reset(new_absolute_path(get_valid_path(&line)));
|
||||||
if (!mTestFile)
|
if (!mTestFile)
|
||||||
return PARSE_ERROR;
|
return PARSE_ERROR;
|
||||||
|
|
||||||
@@ -1946,7 +1947,7 @@ PatchIfFile::Parse(NS_tchar *line)
|
|||||||
{
|
{
|
||||||
// format "<testfile>" "<patchfile>" "<filetopatch>"
|
// format "<testfile>" "<patchfile>" "<filetopatch>"
|
||||||
|
|
||||||
mTestFile.reset(get_full_path(get_valid_path(&line)));
|
mTestFile.reset(new_absolute_path(get_valid_path(&line)));
|
||||||
if (!mTestFile)
|
if (!mTestFile)
|
||||||
return PARSE_ERROR;
|
return PARSE_ERROR;
|
||||||
|
|
||||||
@@ -4036,7 +4037,7 @@ int add_dir_entries(const NS_tchar *dirpath, ActionList *list)
|
|||||||
|
|
||||||
NS_tsnprintf(searchspec, sizeof(searchspec)/sizeof(searchspec[0]),
|
NS_tsnprintf(searchspec, sizeof(searchspec)/sizeof(searchspec[0]),
|
||||||
NS_T("%s*"), dirpath);
|
NS_T("%s*"), dirpath);
|
||||||
std::unique_ptr<const NS_tchar[]> pszSpec(get_full_path(searchspec));
|
std::unique_ptr<const NS_tchar[]> pszSpec(new_absolute_path(searchspec));
|
||||||
|
|
||||||
hFindFile = FindFirstFileW(pszSpec.get(), &finddata);
|
hFindFile = FindFirstFileW(pszSpec.get(), &finddata);
|
||||||
if (hFindFile != INVALID_HANDLE_VALUE)
|
if (hFindFile != INVALID_HANDLE_VALUE)
|
||||||
@@ -4116,7 +4117,7 @@ int add_dir_entries(const NS_tchar *dirpath, ActionList *list)
|
|||||||
char chars[MAXNAMLEN];
|
char chars[MAXNAMLEN];
|
||||||
} ent_buf;
|
} ent_buf;
|
||||||
struct dirent* ent;
|
struct dirent* ent;
|
||||||
std::unique_ptr<NS_tchar[]> searchpath(get_full_path(dirpath));
|
std::unique_ptr<NS_tchar[]> searchpath(new_absolute_path(dirpath));
|
||||||
|
|
||||||
DIR* dir = opendir(searchpath.get());
|
DIR* dir = opendir(searchpath.get());
|
||||||
if (!dir)
|
if (!dir)
|
||||||
@@ -4157,7 +4158,7 @@ int add_dir_entries(const NS_tchar *dirpath, ActionList *list)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Add the file to be removed to the ActionList.
|
// Add the file to be removed to the ActionList.
|
||||||
NS_tchar *quotedpath = get_quoted_path(get_relative_path(foundpath));
|
NS_tchar *quotedpath = get_quoted_path(get_relative_offset(foundpath));
|
||||||
if (!quotedpath)
|
if (!quotedpath)
|
||||||
{
|
{
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
@@ -4180,7 +4181,7 @@ int add_dir_entries(const NS_tchar *dirpath, ActionList *list)
|
|||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
// Add the directory to be removed to the ActionList.
|
// Add the directory to be removed to the ActionList.
|
||||||
NS_tchar *quotedpath = get_quoted_path(get_relative_path(dirpath));
|
NS_tchar *quotedpath = get_quoted_path(get_relative_offset(dirpath));
|
||||||
if (!quotedpath)
|
if (!quotedpath)
|
||||||
return PARSE_ERROR;
|
return PARSE_ERROR;
|
||||||
|
|
||||||
@@ -4206,7 +4207,7 @@ int add_dir_entries(const NS_tchar *dirpath, ActionList *list)
|
|||||||
int rv = OK;
|
int rv = OK;
|
||||||
FTS *ftsdir;
|
FTS *ftsdir;
|
||||||
FTSENT *ftsdirEntry;
|
FTSENT *ftsdirEntry;
|
||||||
std::unique_ptr<NS_tchar[]> searchpath(get_full_path(dirpath));
|
std::unique_ptr<NS_tchar[]> searchpath(new_absolute_path(dirpath));
|
||||||
|
|
||||||
// Remove the trailing slash so the paths don't contain double slashes. The
|
// Remove the trailing slash so the paths don't contain double slashes. The
|
||||||
// existence of the slash has already been checked in DoUpdate.
|
// existence of the slash has already been checked in DoUpdate.
|
||||||
@@ -4242,7 +4243,7 @@ int add_dir_entries(const NS_tchar *dirpath, ActionList *list)
|
|||||||
// Add the file to be removed to the ActionList.
|
// Add the file to be removed to the ActionList.
|
||||||
NS_tsnprintf(foundpath, sizeof(foundpath)/sizeof(foundpath[0]),
|
NS_tsnprintf(foundpath, sizeof(foundpath)/sizeof(foundpath[0]),
|
||||||
NS_T("%s"), ftsdirEntry->fts_accpath);
|
NS_T("%s"), ftsdirEntry->fts_accpath);
|
||||||
quotedpath = get_quoted_path(get_relative_path(foundpath));
|
quotedpath = get_quoted_path(get_relative_offset(foundpath));
|
||||||
if (!quotedpath)
|
if (!quotedpath)
|
||||||
{
|
{
|
||||||
rv = UPDATER_QUOTED_PATH_MEM_ERROR;
|
rv = UPDATER_QUOTED_PATH_MEM_ERROR;
|
||||||
@@ -4261,7 +4262,7 @@ int add_dir_entries(const NS_tchar *dirpath, ActionList *list)
|
|||||||
// Add the directory to be removed to the ActionList.
|
// Add the directory to be removed to the ActionList.
|
||||||
NS_tsnprintf(foundpath, sizeof(foundpath)/sizeof(foundpath[0]),
|
NS_tsnprintf(foundpath, sizeof(foundpath)/sizeof(foundpath[0]),
|
||||||
NS_T("%s/"), ftsdirEntry->fts_accpath);
|
NS_T("%s/"), ftsdirEntry->fts_accpath);
|
||||||
quotedpath = get_quoted_path(get_relative_path(foundpath));
|
quotedpath = get_quoted_path(get_relative_offset(foundpath));
|
||||||
if (!quotedpath)
|
if (!quotedpath)
|
||||||
{
|
{
|
||||||
rv = UPDATER_QUOTED_PATH_MEM_ERROR;
|
rv = UPDATER_QUOTED_PATH_MEM_ERROR;
|
||||||
@@ -4384,10 +4385,10 @@ GetManifestContents(const NS_tchar *manifest)
|
|||||||
int AddPreCompleteActions(ActionList *list)
|
int AddPreCompleteActions(ActionList *list)
|
||||||
{
|
{
|
||||||
#ifdef MACOSX
|
#ifdef MACOSX
|
||||||
std::unique_ptr<NS_tchar[]> manifestPath(get_full_path(
|
std::unique_ptr<NS_tchar[]> manifestPath(new_absolute_path(
|
||||||
NS_T("Contents/Resources/precomplete")));
|
NS_T("Contents/Resources/precomplete")));
|
||||||
#else
|
#else
|
||||||
std::unique_ptr<NS_tchar[]> manifestPath(get_full_path(
|
std::unique_ptr<NS_tchar[]> manifestPath(new_absolute_path(
|
||||||
NS_T("precomplete")));
|
NS_T("precomplete")));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user