Skip to content

Commit 5744075

Browse files
fix: cleanup all resources used by lockService
`lockService` creates a file to be locked and next to it - directory with the same name and `.lock` extension. Both should be cleaned when CLI process is dies, so handle both of them.
1 parent 531bfda commit 5744075

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/common/services/lock-service.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ export class LockService implements ILockService {
4343

4444
public async lock(lockFilePath?: string, lockOpts?: ILockOptions): Promise<() => void> {
4545
const { filePath, fileOpts } = this.getLockFileSettings(lockFilePath, lockOpts);
46-
await this.$cleanupService.addCleanupDeleteAction(filePath);
46+
47+
for (const pathToClean of this.getPathsForCleanupAction(filePath)) {
48+
await this.$cleanupService.addCleanupDeleteAction(pathToClean);
49+
}
50+
4751
this.$fs.writeFile(filePath, "");
4852

4953
try {
@@ -65,7 +69,18 @@ export class LockService implements ILockService {
6569

6670
private async cleanLock(lockPath: string): Promise<void> {
6771
this.$fs.deleteFile(lockPath);
68-
await this.$cleanupService.removeCleanupDeleteAction(lockPath);
72+
for (const filePath of this.getPathsForCleanupAction(lockPath)) {
73+
await this.$cleanupService.removeCleanupDeleteAction(filePath);
74+
}
75+
}
76+
77+
private getPathsForCleanupAction(lockPath: string): string[] {
78+
// The proper-lockfile creates directory with the passed name and `.lock` at the end.
79+
// Ensure we will take care of it as well.
80+
return [
81+
lockPath,
82+
`${lockPath}.lock`
83+
];
6984
}
7085

7186
private getLockFileSettings(filePath?: string, fileOpts?: ILockOptions): { filePath: string, fileOpts: ILockOptions } {

0 commit comments

Comments
 (0)