Skip to content

Commit 625ec66

Browse files
authored
Merge pull request #243 from cnblogs/check-workspace-path-when-get-file-path
fix: check workspace path when get file path
2 parents e102f3e + acc03d1 commit 625ec66

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

src/cmd/post-list/post-pull.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { revealPostListItem } from '@/service/post/post-list-view'
99
import { PostTreeItem } from '@/tree-view/model/post-tree-item'
1010
import { MarkdownCfg } from '@/ctx/cfg/markdown'
1111
import { fsUtil } from '@/infra/fs/fsUtil'
12-
import { WorkspaceCfg } from '@/ctx/cfg/workspace'
1312

1413
export async function postPull(input: Post | PostTreeItem | Uri | undefined | null, showConfirm = true, mute = false) {
1514
const ctxList: CmdCtx[] = []
@@ -18,11 +17,7 @@ export async function postPull(input: Post | PostTreeItem | Uri | undefined | nu
1817
if (parsePostInput(input) && input.id > 0) {
1918
const post = input
2019
const path = PostFileMapManager.getFilePath(post.id)
21-
if (
22-
path === undefined ||
23-
!(await fsUtil.exists(path)) ||
24-
path.indexOf(WorkspaceCfg.getWorkspaceUri().fsPath) < 0
25-
) {
20+
if (path === undefined || !(await fsUtil.exists(path))) {
2621
isFreshPull = true
2722
const uri = buildLocalPostFileUri(post, false)
2823
await workspace.fs.writeFile(uri, Buffer.from(post.postBody))

src/service/post/post-file-map.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { postCategoryDataProvider } from '@/tree-view/provider/post-category-tre
22
import { postDataProvider } from '@/tree-view/provider/post-data-provider'
33
import { LocalState } from '@/ctx/local-state'
44
import { Uri } from 'vscode'
5+
import { WorkspaceCfg } from '@/ctx/cfg/workspace'
56

67
const validatePostFileMap = (map: PostFileMap) => map[0] >= 0 && map[1] !== ''
78

@@ -69,6 +70,7 @@ export namespace PostFileMapManager {
6970
if (map === undefined) return
7071
const path = map[1]
7172
if (path === '') return
73+
if (path.indexOf(WorkspaceCfg.getWorkspaceUri().path) < 0) return
7274
return path.startsWith('/') ? Uri.parse(path).fsPath : path
7375
}
7476

0 commit comments

Comments
 (0)