fix fullpath with wildcard in file part 69/21369/8
Antoine ELIAS [Wed, 19 Feb 2020 20:27:02 +0000 (21:27 +0100)]
fullpath(SCI + filesep() + "contrib/../modules/helptools/*.xml")

Change-Id: I0f5325a48400e9be90c275ea864bffbd54667ad5

scilab/modules/fileio/sci_gateway/cpp/sci_mopen.cpp
scilab/modules/fileio/src/c/getFullFilename.c
scilab/modules/fileio/src/cpp/fullpath.cpp

index 7346332..8043344 100644 (file)
@@ -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)
     {
index 2d8d4f3..7719b62 100644 (file)
@@ -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;
index ae6dce2..a2b5618 100644 (file)
@@ -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
 }
-
-