speccrew 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -129,6 +129,21 @@ function acquireLock(filePath) {
|
|
|
129
129
|
fs.closeSync(fd);
|
|
130
130
|
return lockPath;
|
|
131
131
|
} catch (error) {
|
|
132
|
+
// 检查是否为锁文件已存在的错误
|
|
133
|
+
if (error.code === 'EEXIST') {
|
|
134
|
+
try {
|
|
135
|
+
const lockStat = fs.statSync(lockPath);
|
|
136
|
+
const ageSeconds = (Date.now() - lockStat.mtimeMs) / 1000;
|
|
137
|
+
if (ageSeconds > 60) {
|
|
138
|
+
console.error(`Warning: Stale lock file detected (age: ${Math.round(ageSeconds)}s), removing: ${lockPath}`);
|
|
139
|
+
fs.unlinkSync(lockPath);
|
|
140
|
+
// 不消耗重试次数,继续下一次循环尝试获取锁
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
} catch (statErr) {
|
|
144
|
+
// 锁文件在 stat 时已被删除,继续重试即可
|
|
145
|
+
}
|
|
146
|
+
}
|
|
132
147
|
retryCount++;
|
|
133
148
|
if (retryCount >= maxRetries) {
|
|
134
149
|
throw new Error(`Failed to acquire file lock for '${filePath}' after ${maxRetries} attempts`);
|