[llvm] [FileSystem] Allow exclusive file lock (PR #114098)

Paul Kirth via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 15 09:13:22 PDT 2025


================
@@ -583,10 +583,14 @@ TEST_F(ProgramEnvTest, TestLockFileExclusive) {
     int FD2;
     ASSERT_NO_ERROR(fs::openFileForReadWrite(LockedFile, FD2,
                                              fs::CD_OpenExisting, fs::OF_None));
+    // File should be non-exclusive locked. Try acquire exclusive lock will fail
+    // but non-exclusive will succeed.
+    EXPECT_TRUE(
+        fs::tryLockFile(FD2, std::chrono::seconds(0), /*Exclusive=*/true));
+
+    EXPECT_FALSE(
+        fs::tryLockFile(FD2, std::chrono::seconds(0), /*Exclusive=*/false));
----------------
ilovepi wrote:

OMG. It returns an Error. 🤦   I've inverted the logic when I made the comment, thinking the exclusive lock succeeded. Sorry for the noise. You're right that this seems correct.

https://github.com/llvm/llvm-project/pull/114098


More information about the llvm-commits mailing list