Skip to content

Commit cdcd2d5

Browse files
authored
Merge pull request #186 from cnblogs/fix-failed-to-create-directory
fix: failed to create directory
2 parents ee4ad1d + c73d1d0 commit cdcd2d5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/cmd/post-list/open-post-in-vscode.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs'
22
import path from 'path'
3-
import { Uri, workspace } from 'vscode'
3+
import { FileSystemError, Uri, workspace } from 'vscode'
44
import { Post } from '@/model/post'
55
import { Alert } from '@/infra/alert'
66
import { PostService } from '@/service/post/post'
@@ -79,9 +79,13 @@ export async function openPostInVscode(postId: number, forceUpdateLocalPostFile
7979

8080
async function mkDirIfNotExist(uri: Uri) {
8181
try {
82-
await workspace.fs.readDirectory(uri)
83-
} catch (e) {
84-
void Alert.err(`创建目录失败: ${<string>e}`)
85-
throw e
82+
await workspace.fs.stat(uri)
83+
} catch (err) {
84+
try {
85+
if (err instanceof FileSystemError) await workspace.fs.createDirectory(uri)
86+
} catch (e) {
87+
void Alert.err(`创建目录失败: ${<string>e}`)
88+
throw e
89+
}
8690
}
8791
}

0 commit comments

Comments
 (0)