comparison liboctave/system/file-ops.cc @ 28204:9a1b6400c706 stable

Canonicalize case of long parts of path on Windows file systems (bug #58148). * file-ops.cc (canonicalize_file_name): Call GetShortPathNameW before GetLongPathNameW to also get actual letter case for parts of the path that are longer than the 8.3 short file names.
author Markus Mützel <markus.muetzel@gmx.de>
date Sat, 11 Apr 2020 20:46:24 +0200
parents 6ea1e96b69d4
children a6c89130cfaa
comparison
equal deleted inserted replaced
28202:6c88000fed48 28204:9a1b6400c706
734 w_tmp = L"\\\\?\\" + u8_to_wstring (retval); 734 w_tmp = L"\\\\?\\" + u8_to_wstring (retval);
735 735
736 if (! w_tmp.empty ()) 736 if (! w_tmp.empty ())
737 { 737 {
738 // Get a more canonical name wrt case and full names 738 // Get a more canonical name wrt case and full names
739 wchar_t w_long[32767] = L""; 739 // FIXME: To make this work on partitions that don't store short file
740 int w_len = GetLongPathNameW (w_tmp.c_str (), w_long, 32767); 740 // names, use FindFirstFileW on each component of the path.
741 // Insufficient access permissions on parent folders might make this
742 // tricky.
743
744 // Parts of the path that wouldn't fit into a short 8.3 file name are
745 // copied as is by GetLongPathNameW. To also get the correct case
746 // for these parts, first convert to short file names and than back
747 // to long.
748 wchar_t buffer[32767] = L"";
749 int w_len = GetShortPathNameW (w_tmp.c_str (), buffer, 32767);
750 w_len = GetLongPathNameW (buffer, buffer, 32767);
741 751
742 if (! strip_marker) 752 if (! strip_marker)
743 retval = u8_from_wstring (std::wstring (w_long, w_len)); 753 retval = u8_from_wstring (std::wstring (buffer, w_len));
744 else if (w_len > 4) 754 else if (w_len > 4)
745 retval = u8_from_wstring (std::wstring (w_long+4, w_len-4)); 755 retval = u8_from_wstring (std::wstring (buffer+4, w_len-4));
746 756
757 // If root is a drive, use an upper case letter for the drive letter.
747 if (retval.length () > 1 && retval[1] == ':') 758 if (retval.length () > 1 && retval[1] == ':')
748 retval[0] = toupper (retval[0]); 759 retval[0] = toupper (retval[0]);
749 } 760 }
750 #endif 761 #endif
751 762