Merge pull request #176 from kiwix/win_relpath

Win relpath
This commit is contained in:
Matthieu Gautier 2018-11-03 12:33:14 +01:00 committed by GitHub
commit 9fa7d78ba1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 9 deletions

View File

@ -1,3 +1,8 @@
kiwix-lib 3.0.2
===============
* Use the correct path separator when computing relativePath on Windows.
kiwix-lib 3.0.1 kiwix-lib 3.0.1
=============== ===============

View File

@ -1,5 +1,5 @@
project('kiwix-lib', 'cpp', project('kiwix-lib', 'cpp',
version : '3.0.1', version : '3.0.2',
license : 'GPL', license : 'GPL',
default_options : ['c_std=c11', 'cpp_std=c++11', 'werror=true']) default_options : ['c_std=c11', 'cpp_std=c++11', 'werror=true'])

View File

@ -35,9 +35,9 @@
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#define SEPARATOR "\\" const std::string SEPARATOR("\\");
#else #else
#define SEPARATOR "/" const std::string SEPARATOR("/");
#include <unistd.h> #include <unistd.h>
#endif #endif
@ -66,9 +66,7 @@ string computeRelativePath(const string path, const string absolutePath)
while (commonCount < pathParts.size() while (commonCount < pathParts.size()
&& commonCount < absolutePathParts.size() && commonCount < absolutePathParts.size()
&& pathParts[commonCount] == absolutePathParts[commonCount]) { && pathParts[commonCount] == absolutePathParts[commonCount]) {
if (!pathParts[commonCount].empty()) {
commonCount++; commonCount++;
}
} }
string relativePath; string relativePath;
@ -76,18 +74,17 @@ string computeRelativePath(const string path, const string absolutePath)
/* On Windows you have a token more because the root is represented /* On Windows you have a token more because the root is represented
by a letter */ by a letter */
if (commonCount == 0) { if (commonCount == 0) {
relativePath = "../"; relativePath = ".." + SEPARATOR;
} }
#endif #endif
for (unsigned int i = commonCount; i < pathParts.size(); i++) { for (unsigned int i = commonCount; i < pathParts.size(); i++) {
relativePath += "../"; relativePath += ".." + SEPARATOR;
} }
for (unsigned int i = commonCount; i < absolutePathParts.size(); i++) { for (unsigned int i = commonCount; i < absolutePathParts.size(); i++) {
relativePath += absolutePathParts[i]; relativePath += absolutePathParts[i];
relativePath += i + 1 < absolutePathParts.size() ? "/" : ""; relativePath += i + 1 < absolutePathParts.size() ? SEPARATOR : "";
} }
return relativePath; return relativePath;
} }