diff --git a/src/common/filename.cpp b/src/common/filename.cpp index a57816daf0..13629a51af 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -2232,16 +2232,27 @@ wxString wxFileName::GetLongPath() const return pathOut; } } + else // GetLongPathName() failed. + { + // The error returned for non-existent UNC paths is different, to make + // things more interesting. + const DWORD err = ::GetLastError(); + if ( err == ERROR_FILE_NOT_FOUND || err == ERROR_BAD_NETPATH ) + { + // No need to try to do anything else, we're not going to be able + // to find a long path form of a non-existent path anyhow. + return path; + } + } - // Some other error occured. + // File exists, but some other error occurred. // We need to call FindFirstFile on each component in turn. WIN32_FIND_DATA findFileData; HANDLE hFind; if ( HasVolume() ) - pathOut = GetVolume() + - GetVolumeSeparator(wxPATH_DOS) + + pathOut = wxGetVolumeString(GetVolume(), wxPATH_DOS) + GetPathSeparator(wxPATH_DOS); else pathOut.clear(); diff --git a/tests/filename/filenametest.cpp b/tests/filename/filenametest.cpp index 03ab862a3e..4bc97850b5 100644 --- a/tests/filename/filenametest.cpp +++ b/tests/filename/filenametest.cpp @@ -545,15 +545,29 @@ TEST_CASE("wxFileName::ShortLongPath", "[filename]") #endif // __WINDOWS__ +// Small helper to make things slightly less verbose in the tests below. +static wxString GetDOSPath(const wxFileName& fn) +{ + return fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS); +} + TEST_CASE("wxFileName::UNC", "[filename]") { wxFileName fn("//share/path/name.ext", wxPATH_DOS); CHECK( fn.GetVolume() == "\\\\share" ); - CHECK( fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) == "\\path" ); + CHECK( GetDOSPath(fn) == "\\path" ); fn.Assign("\\\\share2\\path2\\name.ext", wxPATH_DOS); CHECK( fn.GetVolume() == "\\\\share2" ); - CHECK( fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) == "\\path2" ); + CHECK( GetDOSPath(fn) == "\\path2" ); + + fn.SetPath("\\\\server\\volume\\path", wxPATH_DOS); + fn.AppendDir("subdir"); + CHECK( fn.GetFullPath(wxPATH_DOS) == "\\\\server\\volume\\path\\subdir\\name.ext" ); + + // Check for a bug with normalization breaking the path (#22275). + fn.Normalize(wxPATH_NORM_LONG); + CHECK( fn.GetFullPath(wxPATH_DOS) == "\\\\server\\volume\\path\\subdir\\name.ext" ); #ifdef __WINDOWS__ // Check that doubled backslashes in the beginning of the path are not @@ -574,13 +588,13 @@ TEST_CASE("wxFileName::VolumeUniqueName", "[filename]") wxFileName fn("\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\", wxPATH_DOS); CHECK( fn.GetVolume() == "\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}" ); - CHECK( fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) == "\\" ); + CHECK( GetDOSPath(fn) == "\\" ); CHECK( fn.GetFullPath(wxPATH_DOS) == "\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\" ); fn.Assign("\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\" "Program Files\\setup.exe", wxPATH_DOS); CHECK( fn.GetVolume() == "\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}" ); - CHECK( fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) == "\\Program Files" ); + CHECK( GetDOSPath(fn) == "\\Program Files" ); CHECK( fn.GetFullPath(wxPATH_DOS) == "\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\Program Files\\setup.exe" ); }