diff --git a/cmd/wsh/cmd/wshcmd-view.go b/cmd/wsh/cmd/wshcmd-view.go index 08b57957c..52f50fd8b 100644 --- a/cmd/wsh/cmd/wshcmd-view.go +++ b/cmd/wsh/cmd/wshcmd-view.go @@ -4,6 +4,8 @@ package cmd import ( + "io/fs" + "os" "path/filepath" "strings" @@ -56,6 +58,20 @@ func viewRun(cmd *cobra.Command, args []string) { WriteStderr("[error] getting absolute path: %v\n", err) return } + absParent, err := filepath.Abs(filepath.Dir(fileArg)) + if err != nil { + WriteStderr("[error] getting absolute path of parent dir: %v\n", err) + return + } + _, err = os.Stat(absParent) + if err == fs.ErrNotExist { + WriteStderr("[error] parent directory does not exist: %q\n", absParent) + return + } + if err != nil { + WriteStderr("[error] getting file info: %v\n", err) + return + } wshCmd = &wshrpc.CommandCreateBlockData{ BlockDef: &waveobj.BlockDef{ Meta: map[string]interface{}{ diff --git a/frontend/app/view/preview/preview.tsx b/frontend/app/view/preview/preview.tsx index 6039aaf41..4829cdfc2 100644 --- a/frontend/app/view/preview/preview.tsx +++ b/frontend/app/view/preview/preview.tsx @@ -432,7 +432,12 @@ export class PreviewModel implements ViewModel { const fileInfo = await getFn(this.statFile); const fileName = await getFn(this.statFilePath); const editMode = getFn(this.editMode); + const parentFileInfo = await this.getParentInfo(fileInfo); + console.log(parentFileInfo); + if (parentFileInfo?.notfound ?? false) { + return { errorStr: `Parent Directory Not Found: ${fileInfo.path}` }; + } if (fileInfo?.notfound) { return { specializedView: "codeedit" }; } @@ -492,6 +497,18 @@ export class PreviewModel implements ViewModel { services.ObjectService.UpdateObjectMeta(blockOref, updateMeta); } + async getParentInfo(fileInfo: FileInfo): Promise { + const conn = globalStore.get(this.connection); + try { + const parentFileInfo = await RpcApi.RemoteFileJoinCommand(WindowRpcClient, [fileInfo.path, ".."], { + route: makeConnRoute(conn), + }); + return parentFileInfo; + } catch { + return undefined; + } + } + async goParentDirectory() { const fileInfo = await globalStore.get(this.statFile); if (fileInfo == null) { @@ -500,7 +517,7 @@ export class PreviewModel implements ViewModel { } const conn = globalStore.get(this.connection); try { - const newFileInfo = await RpcApi.RemoteFileJoinCommand(WindowRpcClient, [fileInfo.dir, ".."], { + const newFileInfo = await RpcApi.RemoteFileJoinCommand(WindowRpcClient, [fileInfo.path, ".."], { route: makeConnRoute(conn), }); console.log(newFileInfo.path);