1- import fs from 'fs'
21import path from 'path'
32import { FileSystemError , Uri , workspace } from 'vscode'
43import { Post } from '@/model/post'
@@ -10,6 +9,7 @@ import { PostCatService } from '@/service/post/post-cat'
109import sanitizeFileName from 'sanitize-filename'
1110import { WorkspaceCfg } from '@/ctx/cfg/workspace'
1211import { PostCatCfg } from '@/ctx/cfg/post-cat'
12+ import { fsUtil } from '@/infra/fs/fsUtil'
1313
1414export async function buildLocalPostFileUri ( post : Post , includePostId = false ) : Promise < Uri > {
1515 const workspaceUri = WorkspaceCfg . getWorkspaceUri ( )
@@ -39,7 +39,7 @@ export async function buildLocalPostFileUri(post: Post, includePostId = false):
3939export async function openPostInVscode ( postId : number , forceUpdateLocalPostFile = false ) : Promise < Uri | false > {
4040 let mappedPostFilePath = PostFileMapManager . getFilePath ( postId )
4141
42- const isFileExist = mappedPostFilePath !== undefined && fs . existsSync ( mappedPostFilePath )
42+ const isFileExist = mappedPostFilePath !== undefined && ( await fsUtil . exists ( mappedPostFilePath ) )
4343 if ( mappedPostFilePath !== undefined && isFileExist && ! forceUpdateLocalPostFile ) {
4444 await openPostFile ( mappedPostFilePath )
4545 return Uri . file ( mappedPostFilePath )
@@ -58,7 +58,7 @@ export async function openPostInVscode(postId: number, forceUpdateLocalPostFile
5858
5959 // 博文尚未关联到本地文件的情况
6060 // 本地存在和博文同名的文件, 询问用户是要覆盖还是同时保留两者
61- if ( mappedPostFilePath === undefined && fs . existsSync ( fileUri . fsPath ) ) {
61+ if ( mappedPostFilePath === undefined && ( await fsUtil . exists ( fileUri . fsPath ) ) ) {
6262 const opt = [ '保留本地文件并以博文 ID 为文件名新建另一个文件' , '覆盖本地文件' ]
6363 const selected = await Alert . info (
6464 `无法建立博文与本地文件的关联, 文件名冲突` ,
0 commit comments