Code Monkey home page Code Monkey logo

Comments (16)

QbProg avatar QbProg commented on August 20, 2024

I also tested it better, it's reproducible in Windows 7 with the same criterias

from git.

QbProg avatar QbProg commented on August 20, 2024

I spotted the cause: mingw_chdir("S:/") fails in mingw.c
this is because normalize_ntpath removes the trailing slash in mingw.c:341 , and if you try to run _wchdir("S:") that function fails (it probably just changes the current drive) , you have to use _wchdir("S:") to switch to the root directory.

I'm not sure how to do a patch without messing-up everything, anyway in 1.9.5 it worked correctly.

from git.

dscho avatar dscho commented on August 20, 2024

@QbProg could you install the Git SDK -- unless you have it already -- and try out this patch?

diff --git a/compat/mingw.c b/compat/mingw.c
index 8e1993f..d1baaeb 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -316,7 +316,7 @@ static void process_phantom_symlinks(void)
 }

 /* Normalizes NT paths as returned by some low-level APIs. */
-static wchar_t *normalize_ntpath(wchar_t *wbuf)
+static wchar_t *normalize_ntpath(wchar_t *wbuf, int keep_trailing_slashes)
 {
    int i;
    /* fix absolute path prefixes */
@@ -338,8 +338,9 @@ static wchar_t *normalize_ntpath(wchar_t *wbuf)
        if (wbuf[i] == '\\')
            wbuf[i] = '/';
    /* remove potential trailing slashes */
-   while (i && wbuf[i - 1] == '/')
-       wbuf[--i] = 0;
+   if (!keep_trailing_slashes)
+       while (i && wbuf[i - 1] == '/')
+           wbuf[--i] = 0;
    return wbuf;
 }

@@ -621,7 +622,7 @@ int mingw_chdir(const char *dirname)
        CloseHandle(hnd);
    }

-   result = _wchdir(normalize_ntpath(wdirname));
+   result = _wchdir(normalize_ntpath(wdirname, 0));
    current_directory_len = GetCurrentDirectoryW(0, NULL);
    return result;
 }
@@ -2290,7 +2291,7 @@ int readlink(const char *path, char *buf, size_t bufsiz)
     * so convert to a (hopefully large enough) temporary buffer, then memcpy
     * the requested number of bytes (including '\0' for robustness).
     */
-   if ((len = xwcstoutf(tmpbuf, normalize_ntpath(wbuf), MAX_LONG_PATH)) < 0)
+   if ((len = xwcstoutf(tmpbuf, normalize_ntpath(wbuf, 1), MAX_LONG_PATH)) < 0)
        return -1;
    memcpy(buf, tmpbuf, min(bufsiz, len + 1));
    return min(bufsiz, len);

from git.

QbProg avatar QbProg commented on August 20, 2024

it seems not working.
IHMO it is the _wchdir(normalize_ntpath(wdirname,0)) which should have 1 for keep_trailing_slashes since it's in that point that the function fails

I don't know if it's correct but you could automatically avoid the trailing slash deletion only if the path is a root. You could check this using Win32 "PathIsRoot" (requires shlwapi) or else just check if
(strlen == 3 && str[1] == L':' && (str[2] == L'' || str[2] == L'/'))
(given that you have a correct absolute path and you already stripped special path indicators)

from git.

QbProg avatar QbProg commented on August 20, 2024

This patch should solve the issue , but I didn't run the tests

diff --git a/compat/mingw.c b/compat/mingw.c
index 1d10707..706b527 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -333,13 +333,18 @@ static wchar_t *normalize_ntpath(wchar_t *wbuf)
            *wbuf = '\\';
        }
    }
+
+   int is_root = (wcslen(wbuf) == 3) && (wbuf[1] == L':') && (wbuf[2] == L'\\' || wbuf[2] == '/');
+
    /* convert backslashes to slashes */
    for (i = 0; wbuf[i]; i++)
        if (wbuf[i] == '\\')
            wbuf[i] = '/';
    /* remove potential trailing slashes */
-   while (i && wbuf[i - 1] == '/')
-       wbuf[--i] = 0;
+   if(!is_root)
+       while (i && wbuf[i - 1] == '/')
+           wbuf[--i] = 0;
+
    return wbuf;
 }

from git.

dscho avatar dscho commented on August 20, 2024

I actually would really prefer to have a solution that does not depend on testing for the root directory. Are you sure that _wchdir(L"C:/Windows/") fails?

from git.

QbProg avatar QbProg commented on August 20, 2024

_wchdir("C:") fails, while _wchdir("C:") succeed. This is windows related I think.

from git.

dscho avatar dscho commented on August 20, 2024

What about _wchdir(L"C:/");? And _wchdir(L"C:/Windows/");?

from git.

QbProg avatar QbProg commented on August 20, 2024

they work. Also _wchdir(L"C:/Windows") works because is not root

the problem is exactly that normalize_ntpath removes the trailing slash.

from git.

dscho avatar dscho commented on August 20, 2024

@QbProg yep, so I just mixed up my 0s and 1s, right? Could you please test my patch again (which would maybe also handle cases such as _wchdir(L"//server/"), at least that is as general as I wanted the patch to be), with the 0 and the 1 properly adjusted, as per your analysis?

from git.

QbProg avatar QbProg commented on August 20, 2024

@dscho the patch with the 0 and 1 switched works!
I was not able to test a network path since I don't have a network here :)
Thank you!

from git.

dscho avatar dscho commented on August 20, 2024

Thanks for testing! As to the network share, I will test that once I am done releasing 2.4.4.1.

from git.

dscho avatar dscho commented on August 20, 2024

@QbProg I am busy working toward a 3rd release candidate of Git for Windows 2.x which will include this fix.

from git.

dscho avatar dscho commented on August 20, 2024

@QbProg could you please test the new Git for Windows 2.4.4.2?

from git.

QbProg avatar QbProg commented on August 20, 2024

tested rc3 (git version 2.4.4.windows.2), it's fixed! thank you!

from git.

dscho avatar dscho commented on August 20, 2024

Excellent!

from git.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.