Skip to content

Commit 834eac8

Browse files
committed
[Support] Do not remove lock file on failure
1 parent dafb566 commit 834eac8

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,8 +1491,6 @@ static bool compileModuleAndReadASTBehindLock(
14911491
// related errors.
14921492
Diags.Report(ModuleNameLoc, diag::remark_module_lock_failure)
14931493
<< Module->Name << toString(std::move(Err));
1494-
// Clear out any potential leftover.
1495-
Lock.unsafeRemoveLockFile();
14961494
return compileModuleAndReadASTImpl(ImportingInstance, ImportLoc,
14971495
ModuleNameLoc, Module, ModuleFileName);
14981496
}

llvm/lib/Support/LockFileManager.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Expected<bool> LockFileManager::tryLock() {
169169
SmallString<128> AbsoluteFileName(FileName);
170170
if (std::error_code EC = sys::fs::make_absolute(AbsoluteFileName))
171171
return createStringError(EC, "failed to obtain absolute path for " +
172-
AbsoluteFileName);
172+
AbsoluteFileName); // We don't even know the LockFileName yet.
173173
LockFileName = AbsoluteFileName;
174174
LockFileName += ".lock";
175175

@@ -180,20 +180,22 @@ Expected<bool> LockFileManager::tryLock() {
180180
return false;
181181
}
182182

183+
// LockFileName either does not exist or we could not read it and removed it in readLockFile().
184+
183185
// Create a lock file that is unique to this instance.
184186
UniqueLockFileName = LockFileName;
185187
UniqueLockFileName += "-%%%%%%%%";
186188
int UniqueLockFileID;
187189
if (std::error_code EC = sys::fs::createUniqueFile(
188190
UniqueLockFileName, UniqueLockFileID, UniqueLockFileName))
189191
return createStringError(EC, "failed to create unique file " +
190-
UniqueLockFileName);
192+
UniqueLockFileName); // LockFileName still does not exist.
191193

192194
// Write our process ID to our unique lock file.
193195
{
194196
SmallString<256> HostID;
195197
if (auto EC = getHostID(HostID))
196-
return createStringError(EC, "failed to get host id");
198+
return createStringError(EC, "failed to get host id"); // LockFileName still does not exist. We may leave behind UniqueLockFileName though, this that in a follow-up.
197199

198200
raw_fd_ostream Out(UniqueLockFileID, /*shouldClose=*/true);
199201
Out << HostID << ' ' << sys::Process::getProcessId();
@@ -207,7 +209,7 @@ Expected<bool> LockFileManager::tryLock() {
207209
sys::fs::remove(UniqueLockFileName);
208210
// Don't call report_fatal_error.
209211
Out.clear_error();
210-
return std::move(Err);
212+
return std::move(Err); // LockFileName still does not exist.
211213
}
212214
}
213215

@@ -227,7 +229,7 @@ Expected<bool> LockFileManager::tryLock() {
227229

228230
if (EC != errc::file_exists)
229231
return createStringError(EC, "failed to create link " + LockFileName +
230-
" to " + UniqueLockFileName);
232+
" to " + UniqueLockFileName); // We failed to create LockFileName for a weird reason.
231233

232234
// Someone else managed to create the lock file first. Read the process ID
233235
// from the lock file.
@@ -248,7 +250,7 @@ Expected<bool> LockFileManager::tryLock() {
248250
// ownership.
249251
if ((EC = sys::fs::remove(LockFileName)))
250252
return createStringError(EC, "failed to remove lockfile " +
251-
UniqueLockFileName);
253+
UniqueLockFileName); // Failed to remove LockFileName. Why try to do it again?
252254
}
253255
}
254256

llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,6 @@ PreservedAnalyses AMDGPUSplitModulePass::run(Module &M,
15521552
LLVM_DEBUG(
15531553
dbgs() << "[amdgpu-split-module] unable to acquire lockfile, debug "
15541554
"output may be mangled by other processes\n");
1555-
Lock.unsafeRemoveLockFile();
15561555
} else if (!Owned) {
15571556
switch (Lock.waitForUnlock()) {
15581557
case LockFileManager::Res_Success:

0 commit comments

Comments
 (0)