[PATCH] D146490: [Support] On Windows, ensure that UniqueID is really stable

Alexandre Ganea via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 20 19:17:38 PDT 2023


aganea created this revision.
aganea added reviewers: mstorsjo, hans, kbobyrev, dexonsmith, zero9178.
Herald added subscribers: kadircet, arphaman, hiraditya.
Herald added a project: All.
aganea requested review of this revision.
Herald added projects: clang, LLVM, clang-tools-extra.
Herald added subscribers: cfe-commits, llvm-commits.

Before this patch, `UniqueID` was thought to store stable file IDs. However a recently reported issue <https://github.com/llvm/llvm-project/issues/61401> shows that the file IDs are not always stable, at least on Windows. The documentation for the underlying Windows API <https://learn.microsoft.com/en-us/windows/win32/api/fileapi/ns-fileapi-by_handle_file_information> states: //(note the emphasis)//

> To determine whether two **open handles** represent the same file, combine the identifier and the volume serial number for each file and compare them.

Currently, `UniqueID` does not keep the file handles open. The fact that file IDs were stable until now is only due to a NTFS implementation detail <https://github.com/llvm/llvm-project/issues/61401#issuecomment-1473072118>. In some cases, such as drives mounted on network locations, the underlying Windows drivers might or might not generate stable file IDs.

To fix the issue, we keep the file handles open during the lifetime of their corresponding `UniqueID` instances. Since handles will live longer now, this requires particular attention when performing some file actions, such as file deletions.

Should fix #61401 <https://github.com/llvm/llvm-project/issues/61401> and #22079 <https://github.com/llvm/llvm-project/issues/22079>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146490

Files:
  clang-tools-extra/clangd/unittests/FSTests.cpp
  clang/include/clang/Basic/FileEntry.h
  clang/lib/Basic/FileEntry.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
  clang/tools/libclang/Indexing.cpp
  clang/unittests/Basic/FileManagerTest.cpp
  llvm/include/llvm/Support/FileSystem.h
  llvm/include/llvm/Support/FileSystem/UniqueID.h
  llvm/include/llvm/Support/Windows/ScopedHandle.h
  llvm/include/llvm/Support/Windows/WindowsSupport.h
  llvm/lib/Support/VirtualFileSystem.cpp
  llvm/lib/Support/Windows/Path.inc
  llvm/unittests/Support/FSUniqueIDTest.cpp
  llvm/unittests/Support/Path.cpp
  llvm/unittests/Support/VirtualFileSystemTest.cpp
  llvm/utils/split-file/split-file.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146490.506806.patch
Type: text/x-patch
Size: 27817 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230321/169c604a/attachment-0001.bin>


More information about the cfe-commits mailing list