1
- import fs from 'fs'
2
1
import path from 'path'
3
2
import { FileSystemError , Uri , workspace } from 'vscode'
4
3
import { Post } from '@/model/post'
@@ -10,6 +9,7 @@ import { PostCatService } from '@/service/post/post-cat'
10
9
import sanitizeFileName from 'sanitize-filename'
11
10
import { WorkspaceCfg } from '@/ctx/cfg/workspace'
12
11
import { PostCatCfg } from '@/ctx/cfg/post-cat'
12
+ import { fsUtil } from '@/infra/fs/fsUtil'
13
13
14
14
export async function buildLocalPostFileUri ( post : Post , includePostId = false ) : Promise < Uri > {
15
15
const workspaceUri = WorkspaceCfg . getWorkspaceUri ( )
@@ -39,7 +39,7 @@ export async function buildLocalPostFileUri(post: Post, includePostId = false):
39
39
export async function openPostInVscode ( postId : number , forceUpdateLocalPostFile = false ) : Promise < Uri | false > {
40
40
let mappedPostFilePath = PostFileMapManager . getFilePath ( postId )
41
41
42
- const isFileExist = mappedPostFilePath !== undefined && fs . existsSync ( mappedPostFilePath )
42
+ const isFileExist = mappedPostFilePath !== undefined && ( await fsUtil . exists ( mappedPostFilePath ) )
43
43
if ( mappedPostFilePath !== undefined && isFileExist && ! forceUpdateLocalPostFile ) {
44
44
await openPostFile ( mappedPostFilePath )
45
45
return Uri . file ( mappedPostFilePath )
@@ -58,7 +58,7 @@ export async function openPostInVscode(postId: number, forceUpdateLocalPostFile
58
58
59
59
// 博文尚未关联到本地文件的情况
60
60
// 本地存在和博文同名的文件, 询问用户是要覆盖还是同时保留两者
61
- if ( mappedPostFilePath === undefined && fs . existsSync ( fileUri . fsPath ) ) {
61
+ if ( mappedPostFilePath === undefined && ( await fsUtil . exists ( fileUri . fsPath ) ) ) {
62
62
const opt = [ '保留本地文件并以博文 ID 为文件名新建另一个文件' , '覆盖本地文件' ]
63
63
const selected = await Alert . info (
64
64
`无法建立博文与本地文件的关联, 文件名冲突` ,
0 commit comments