From f9a14300603ff9d19d796a8f1962694475366efc Mon Sep 17 00:00:00 2001 From: Antoine ELIAS Date: Wed, 19 Feb 2020 21:27:02 +0100 Subject: [PATCH] fix fullpath with wildcard in file part fullpath(SCI + filesep() + "contrib/../modules/helptools/*.xml") Change-Id: I0f5325a48400e9be90c275ea864bffbd54667ad5 --- .../modules/fileio/sci_gateway/cpp/sci_mopen.cpp | 2 +- scilab/modules/fileio/src/c/getFullFilename.c | 2 +- scilab/modules/fileio/src/cpp/fullpath.cpp | 27 +++++++++++++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/scilab/modules/fileio/sci_gateway/cpp/sci_mopen.cpp b/scilab/modules/fileio/sci_gateway/cpp/sci_mopen.cpp index 7346332..8043344 100644 --- a/scilab/modules/fileio/sci_gateway/cpp/sci_mopen.cpp +++ b/scilab/modules/fileio/sci_gateway/cpp/sci_mopen.cpp @@ -125,7 +125,7 @@ types::Function::ReturnValue sci_mopen(types::typed_list &in, int _iRetCount, ty return types::Function::Error; } - wchar_t* pwstTemp = get_full_pathW((const wchar_t*)pstFilename); + wchar_t* pwstTemp = get_full_pathW(pstFilename); iErr = mopen(pwstTemp, pstMode, iSwap, &iID); if (iErr != MOPEN_NO_ERROR) { diff --git a/scilab/modules/fileio/src/c/getFullFilename.c b/scilab/modules/fileio/src/c/getFullFilename.c index 2d8d4f3..7719b62 100644 --- a/scilab/modules/fileio/src/c/getFullFilename.c +++ b/scilab/modules/fileio/src/c/getFullFilename.c @@ -77,7 +77,7 @@ wchar_t *getFullFilenameW(const wchar_t* FilenameInput) } } - wcTmp = get_full_pathW((const wchar_t*)wcPath); + wcTmp = get_full_pathW(wcPath); wcscpy(wcPath, wcTmp); FREE(wcTmp); wcTmp = NULL; diff --git a/scilab/modules/fileio/src/cpp/fullpath.cpp b/scilab/modules/fileio/src/cpp/fullpath.cpp index ae6dce2..a2b5618 100644 --- a/scilab/modules/fileio/src/cpp/fullpath.cpp +++ b/scilab/modules/fileio/src/cpp/fullpath.cpp @@ -50,6 +50,7 @@ char *get_full_path(const char *_Path) { canonPath /= ""; } + return os_strdup(std::filesystem::absolute(canonPath).string().c_str()); #endif // _MSC_VER } @@ -58,7 +59,18 @@ char *get_full_path(const char *_Path) wchar_t *get_full_pathW(const wchar_t * _wcPath) { #ifdef _MSC_VER - std::filesystem::path relPath = std::filesystem::path(_wcPath); + std::wstring s(_wcPath); + size_t pos = s.find_last_of(L"/\\"); + + //remove "file" part + bool bAppend = false; + if (pos != std::wstring::npos && s.substr(pos + 1) != L"..") + { + s = s.substr(0, pos); + bAppend = true; + } + + std::filesystem::path relPath = std::filesystem::path(s); std::filesystem::path canonPath = std::filesystem::weakly_canonical(relPath); auto relPathIt = relPath.end(); auto canonPathIt = canonPath.end(); @@ -66,7 +78,16 @@ wchar_t *get_full_pathW(const wchar_t * _wcPath) { canonPath /= ""; } - return os_wcsdup(std::filesystem::absolute(canonPath).wstring().c_str()); + + std::filesystem::path p = std::filesystem::absolute(canonPath); + + //add "file" part + if (bAppend) + { + p /= (_wcPath + pos + 1); + } + + return os_wcsdup(p.wstring().c_str()); #else // POSIX char *_FullPath = NULL; wchar_t *wFullPath = NULL; @@ -85,5 +106,3 @@ wchar_t *get_full_pathW(const wchar_t * _wcPath) return wFullPath; #endif // _MSC_VER } - - -- 1.7.9.5