To: vim_dev@googlegroups.com Subject: Patch 8.1.1784 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.1784 Problem: MS-Windows: resolve() does not work if serial nr duplicated. Solution: Use another method to get the full path. (Ken Takata, closes #4661) Files: src/os_mswin.c *** ../vim-8.1.1783/src/os_mswin.c 2019-06-06 12:22:38.266535367 +0200 --- src/os_mswin.c 2019-08-01 13:50:58.326414601 +0200 *************** *** 1703,1757 **** # include # endif ! typedef enum _FILE_INFO_BY_HANDLE_CLASS_ { ! FileBasicInfo_, ! FileStandardInfo_, ! FileNameInfo_, ! FileRenameInfo_, ! FileDispositionInfo_, ! FileAllocationInfo_, ! FileEndOfFileInfo_, ! FileStreamInfo_, ! FileCompressionInfo_, ! FileAttributeTagInfo_, ! FileIdBothDirectoryInfo_, ! FileIdBothDirectoryRestartInfo_, ! FileIoPriorityHintInfo_, ! FileRemoteProtocolInfo_, ! FileFullDirectoryInfo_, ! FileFullDirectoryRestartInfo_, ! FileStorageInfo_, ! FileAlignmentInfo_, ! FileIdInfo_, ! FileIdExtdDirectoryInfo_, ! FileIdExtdDirectoryRestartInfo_, ! FileDispositionInfoEx_, ! FileRenameInfoEx_, ! MaximumFileInfoByHandleClass_ ! } FILE_INFO_BY_HANDLE_CLASS_; ! ! typedef struct _FILE_NAME_INFO_ { ! DWORD FileNameLength; ! WCHAR FileName[1]; ! } FILE_NAME_INFO_; ! ! typedef BOOL (WINAPI *pfnGetFileInformationByHandleEx)( ! HANDLE hFile, ! FILE_INFO_BY_HANDLE_CLASS_ FileInformationClass, ! LPVOID lpFileInformation, ! DWORD dwBufferSize); ! static pfnGetFileInformationByHandleEx pGetFileInformationByHandleEx = NULL; ! ! typedef BOOL (WINAPI *pfnGetVolumeInformationByHandleW)( HANDLE hFile, ! LPWSTR lpVolumeNameBuffer, ! DWORD nVolumeNameSize, ! LPDWORD lpVolumeSerialNumber, ! LPDWORD lpMaximumComponentLength, ! LPDWORD lpFileSystemFlags, ! LPWSTR lpFileSystemNameBuffer, ! DWORD nFileSystemNameSize); ! static pfnGetVolumeInformationByHandleW pGetVolumeInformationByHandleW = NULL; # define is_path_sep(c) ((c) == L'\\' || (c) == L'/') --- 1703,1714 ---- # include # endif ! typedef BOOL (WINAPI *pfnGetFinalPathNameByHandleW)( HANDLE hFile, ! LPWSTR lpszFilePath, ! DWORD cchFilePath, ! DWORD dwFlags); ! static pfnGetFinalPathNameByHandleW pGetFinalPathNameByHandleW = NULL; # define is_path_sep(c) ((c) == L'\\' || (c) == L'/') *************** *** 1791,1818 **** { HANDLE h = INVALID_HANDLE_VALUE; DWORD size; ! WCHAR *p; char_u *rfname = NULL; ! FILE_NAME_INFO_ *nameinfo = NULL; ! WCHAR buff[MAX_PATH], *volnames = NULL; ! HANDLE hv; ! DWORD snfile, snfind; static BOOL loaded = FALSE; ! if (pGetFileInformationByHandleEx == NULL || ! pGetVolumeInformationByHandleW == NULL) { HMODULE hmod = GetModuleHandle("kernel32.dll"); if (loaded == TRUE) return NULL; ! pGetFileInformationByHandleEx = (pfnGetFileInformationByHandleEx) ! GetProcAddress(hmod, "GetFileInformationByHandleEx"); ! pGetVolumeInformationByHandleW = (pfnGetVolumeInformationByHandleW) ! GetProcAddress(hmod, "GetVolumeInformationByHandleW"); loaded = TRUE; ! if (pGetFileInformationByHandleEx == NULL || ! pGetVolumeInformationByHandleW == NULL) return NULL; } --- 1748,1768 ---- { HANDLE h = INVALID_HANDLE_VALUE; DWORD size; ! WCHAR *p, *wp; char_u *rfname = NULL; ! WCHAR *buff = NULL; static BOOL loaded = FALSE; ! if (pGetFinalPathNameByHandleW == NULL) { HMODULE hmod = GetModuleHandle("kernel32.dll"); if (loaded == TRUE) return NULL; ! pGetFinalPathNameByHandleW = (pfnGetFinalPathNameByHandleW) ! GetProcAddress(hmod, "GetFinalPathNameByHandleW"); loaded = TRUE; ! if (pGetFinalPathNameByHandleW == NULL) return NULL; } *************** *** 1833,1892 **** if (h == INVALID_HANDLE_VALUE) goto fail; ! size = sizeof(FILE_NAME_INFO_) + sizeof(WCHAR) * (MAX_PATH - 1); ! nameinfo = alloc(size + sizeof(WCHAR)); ! if (nameinfo == NULL) goto fail; ! ! if (!pGetFileInformationByHandleEx(h, FileNameInfo_, nameinfo, size)) goto fail; ! ! nameinfo->FileName[nameinfo->FileNameLength / sizeof(WCHAR)] = 0; ! ! if (!pGetVolumeInformationByHandleW( ! h, NULL, 0, &snfile, NULL, NULL, NULL, 0)) goto fail; ! hv = FindFirstVolumeW(buff, MAX_PATH); ! if (hv == INVALID_HANDLE_VALUE) ! goto fail; ! ! do { ! GetVolumeInformationW( ! buff, NULL, 0, &snfind, NULL, NULL, NULL, 0); ! if (snfind == snfile) ! break; ! } while (FindNextVolumeW(hv, buff, MAX_PATH)); ! ! FindVolumeClose(hv); ! ! if (snfind != snfile) ! goto fail; ! ! size = 0; ! if (!GetVolumePathNamesForVolumeNameW(buff, NULL, 0, &size) && ! GetLastError() != ERROR_MORE_DATA) ! goto fail; ! ! volnames = ALLOC_MULT(WCHAR, size); ! if (!GetVolumePathNamesForVolumeNameW(buff, volnames, size, ! &size)) ! goto fail; ! ! wcscpy(buff, volnames); ! if (nameinfo->FileName[0] == '\\') ! wcscat(buff, nameinfo->FileName + 1); else ! wcscat(buff, nameinfo->FileName); ! rfname = utf16_to_enc(buff, NULL); fail: if (h != INVALID_HANDLE_VALUE) CloseHandle(h); ! if (nameinfo != NULL) ! vim_free(nameinfo); ! if (volnames != NULL) ! vim_free(volnames); return rfname; } --- 1783,1814 ---- if (h == INVALID_HANDLE_VALUE) goto fail; ! size = pGetFinalPathNameByHandleW(h, NULL, 0, 0); ! if (size == 0) goto fail; ! buff = ALLOC_MULT(WCHAR, size); ! if (buff == NULL) goto fail; ! if (pGetFinalPathNameByHandleW(h, buff, size, 0) == 0) goto fail; ! if (wcsncmp(buff, L"\\\\?\\UNC\\", 8) == 0) ! { ! buff[6] = L'\\'; ! wp = buff + 6; ! } ! else if (wcsncmp(buff, L"\\\\?\\", 4) == 0) ! wp = buff + 4; else ! wp = buff; ! ! rfname = utf16_to_enc(wp, NULL); fail: if (h != INVALID_HANDLE_VALUE) CloseHandle(h); ! if (buff != NULL) ! vim_free(buff); return rfname; } *** ../vim-8.1.1783/src/version.c 2019-07-31 22:18:19.335852519 +0200 --- src/version.c 2019-08-01 13:54:10.645206251 +0200 *************** *** 779,780 **** --- 779,782 ---- { /* Add new patch number below this line */ + /**/ + 1784, /**/ -- Never enter the boss's office unless it's absolutely necessary. Every boss saves one corner of the desk for useless assignments that are doled out like Halloween candy to each visitor. (Scott Adams - The Dilbert principle) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///