mirror of
https://github.com/whyour/qinglong.git
synced 2026-02-12 14:05:38 +08:00
Improve type safety for fileHandle and release variables
- Add explicit FileHandle type annotation for fileHandle variable - Change fileHandle check from truthy to explicit undefined check - Change release type from null to undefined for better type safety Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
This commit is contained in:
parent
d30eb2008c
commit
855f591992
|
|
@ -1,7 +1,7 @@
|
|||
import { lock } from 'proper-lockfile';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import { writeFile, open, chmod } from 'fs/promises';
|
||||
import { writeFile, open, chmod, FileHandle } from 'fs/promises';
|
||||
import { fileExist } from '../config/util';
|
||||
import Logger from '../loaders/logger';
|
||||
|
||||
|
|
@ -23,14 +23,14 @@ export async function writeFileWithLock(
|
|||
|
||||
// Ensure file exists before locking
|
||||
if (!(await fileExist(filePath))) {
|
||||
let fileHandle;
|
||||
let fileHandle: FileHandle | undefined;
|
||||
try {
|
||||
fileHandle = await open(filePath, 'w');
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
throw new Error(`Failed to create file ${filePath}: ${errorMessage}`);
|
||||
} finally {
|
||||
if (fileHandle) {
|
||||
if (fileHandle !== undefined) {
|
||||
try {
|
||||
await fileHandle.close();
|
||||
} catch (closeError) {
|
||||
|
|
@ -42,7 +42,7 @@ export async function writeFileWithLock(
|
|||
}
|
||||
|
||||
const lockfilePath = getUniqueLockPath(filePath);
|
||||
let release: (() => Promise<void>) | null = null;
|
||||
let release: (() => Promise<void>) | undefined;
|
||||
|
||||
try {
|
||||
release = await lock(filePath, {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user