Skip to content

Commit

Permalink
Even simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
rix0rrr committed Dec 11, 2024
1 parent 423d260 commit 41ddaed
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions packages/aws-cdk/lib/api/util/rwlock.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* istanbul ignore file */
import { promises as fs } from 'fs';
import * as path from 'path';

Expand All @@ -11,7 +12,6 @@ import * as path from 'path';
* This class is not 100% race safe, but in practice it should be a lot
* better than the 0 protection we have today.
*/
/* istanbul ignore next */
export class RWLock {
private readonly pidString: string;
private readonly writerFile: string;
Expand Down Expand Up @@ -159,7 +159,6 @@ export interface IWriterLock extends ILock {
convertToReaderLock(): Promise<ILock>;
}

/* istanbul ignore next */
async function readFileIfExists(filename: string): Promise<string | undefined> {
try {
return await fs.readFile(filename, { encoding: 'utf-8' });
Expand All @@ -170,15 +169,13 @@ async function readFileIfExists(filename: string): Promise<string | undefined> {
}

let tmpCounter = 0;
/* istanbul ignore next */
async function writeFileAtomic(filename: string, contents: string): Promise<void> {
await fs.mkdir(path.dirname(filename), { recursive: true });
const tmpFile = `${filename}.${process.pid}_${++tmpCounter}`;
await fs.writeFile(tmpFile, contents, { encoding: 'utf-8' });
await fs.rename(tmpFile, filename);
}

/* istanbul ignore next */
async function deleteFile(filename: string) {
try {
await fs.unlink(filename);
Expand All @@ -190,7 +187,6 @@ async function deleteFile(filename: string) {
}
}

/* istanbul ignore next */
function processExists(pid: number) {
try {
process.kill(pid, 0);
Expand Down

0 comments on commit 41ddaed

Please sign in to comment.