Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zxdong262 committed Oct 5, 2023
1 parent 5654dfd commit 6ba5bcd
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/nodefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ promisify(
]
);

function fsExists (fp: string) {
function fsExistsAsync (fp: string) {
return fs.accessAsync(fp)
.then(() => true)
.catch(() => false)
Expand All @@ -59,7 +59,7 @@ export async function checkPathWritable(filePath: string) {
return false;
}

if (!await fsExists(filePath)) {
if (!await fsExistsAsync(filePath)) {
throw new TrzszError(`No such directory: ${filePath}`);
}
const stats = await fs.statAsync(filePath);
Expand Down Expand Up @@ -177,7 +177,7 @@ export async function checkPathsReadable(
const entries = filePaths.entries()
for (const [idx, filePath] of entries) {
const absPath = path.resolve(filePath);
if (!await fsExists(absPath)) {
if (!await fsExistsAsync(absPath)) {
throw new TrzszError(`No such file: ${absPath}`);
}
const stats = await fs.statAsync(absPath);
Expand Down Expand Up @@ -232,19 +232,19 @@ class NodefsFileWriter implements TrzszFileWriter {
}

async function getNewName(savePath: string, fileName: string) {
if (!fsExists(path.join(savePath, fileName))) {
if (!fsExistsAsync(path.join(savePath, fileName))) {
return fileName;
}
for (let i = 0; i < 1000; i++) {
const saveName = `${fileName}.${i}`;
if (!await fsExists(path.join(savePath, saveName))) {
if (!await fsExistsAsync(path.join(savePath, saveName))) {
return saveName;
}
}
throw new TrzszError("Fail to assign new file name");
}

async function doCreateFile(absPath: string) {
function doCreateFile(absPath: string) {
try {
return fs.openAsync(absPath, "w");
} catch (err) {
Expand All @@ -258,7 +258,7 @@ async function doCreateFile(absPath: string) {
}

async function doCreateDirectory(absPath: string) {
if (!await fsExists(absPath)) {
if (!await fsExistsAsync(absPath)) {
await fs.mkdirAsync(absPath, { recursive: true, mode: 0o755 });
}
const stats = await fs.statAsync(absPath);
Expand Down

0 comments on commit 6ba5bcd

Please sign in to comment.