From 987c0b14c695ff41285d6111be9eca281f51fdd3 Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Tue, 18 Feb 2025 12:35:00 -0800 Subject: [PATCH 1/4] save --- frontend/app/view/preview/preview.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/frontend/app/view/preview/preview.tsx b/frontend/app/view/preview/preview.tsx index 09b961fae9..36f19b2a89 100644 --- a/frontend/app/view/preview/preview.tsx +++ b/frontend/app/view/preview/preview.tsx @@ -14,7 +14,6 @@ import { BlockHeaderSuggestionControl } from "@/app/suggestion/suggestion"; import { CodeEditor } from "@/app/view/codeeditor/codeeditor"; import { Markdown } from "@/element/markdown"; import { - atoms, createBlock, getApi, getConnStatusAtom, @@ -204,14 +203,14 @@ export class PreviewModel implements ViewModel { this.errorMsgAtom = atom(null) as PrimitiveAtom; this.viewIcon = atom((get) => { const blockData = get(this.blockAtom); + const connStatus = get(this.connStatus); + const mimeTypeLoadable = get(this.fileMimeTypeLoadable); if (blockData?.meta?.icon) { return blockData.meta.icon; } - const connStatus = get(this.connStatus); if (connStatus?.status != "connected") { return null; } - const mimeTypeLoadable = get(this.fileMimeTypeLoadable); const mimeType = jotaiLoadableValue(mimeTypeLoadable, ""); if (mimeType == "directory") { return { @@ -349,7 +348,6 @@ export class PreviewModel implements ViewModel { const isCeView = loadableSV.state == "hasData" && loadableSV.data.specializedView == "codeedit"; if (mimeType == "directory") { const showHiddenFiles = get(this.showHiddenFiles); - const settings = get(atoms.settingsAtom); return [ { elemtype: "iconbutton", @@ -448,14 +446,15 @@ export class PreviewModel implements ViewModel { const fileContentAtom = atom( async (get) => { const newContent = get(this.newFileContent); + const savedContent = get(this.fileContentSaved); + const fullFile = await get(fullFileAtom); + console.log("full file", fullFile); if (newContent != null) { return newContent; } - const savedContent = get(this.fileContentSaved); if (savedContent != null) { return savedContent; } - const fullFile = await get(fullFileAtom); return base64ToString(fullFile?.data64); }, (_, set, update: string) => { From 49a3558eee61236b0667bf6ed253672e57bb4116 Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Tue, 18 Feb 2025 14:24:10 -0800 Subject: [PATCH 2/4] Clean up atom usage, remove some redundant logs --- frontend/app/view/preview/directorypreview.tsx | 4 ++-- frontend/app/view/preview/preview.tsx | 18 +++--------------- pkg/remote/awsconn/awsconn.go | 1 - pkg/remote/fileshare/fileshare.go | 13 +++++++++++++ pkg/remote/fileshare/s3fs/s3fs.go | 3 --- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/frontend/app/view/preview/directorypreview.tsx b/frontend/app/view/preview/directorypreview.tsx index 70f8dd9bdf..8069827536 100644 --- a/frontend/app/view/preview/directorypreview.tsx +++ b/frontend/app/view/preview/directorypreview.tsx @@ -720,7 +720,7 @@ const TableRow = React.forwardRef(function ({ idx, handleFileContextMenu, }: TableRowProps) { - const dirPath = useAtomValue(model.normFilePath); + const dirPath = useAtomValue(model.statFilePath); const connection = useAtomValue(model.connection); const dragItem: DraggedFile = { @@ -782,7 +782,7 @@ function DirectoryPreview({ model }: DirectoryPreviewProps) { const [refreshVersion, setRefreshVersion] = useAtom(model.refreshVersion); const conn = useAtomValue(model.connection); const blockData = useAtomValue(model.blockAtom); - const dirPath = useAtomValue(model.normFilePath); + const dirPath = useAtomValue(model.statFilePath); const [copyStatus, setCopyStatus] = useState(null); useEffect(() => { diff --git a/frontend/app/view/preview/preview.tsx b/frontend/app/view/preview/preview.tsx index 36f19b2a89..de1555e6ea 100644 --- a/frontend/app/view/preview/preview.tsx +++ b/frontend/app/view/preview/preview.tsx @@ -150,8 +150,6 @@ export class PreviewModel implements ViewModel { metaFilePath: Atom; statFilePath: Atom>; - normFilePath: Atom>; - loadableStatFilePath: Atom>; loadableFileInfo: Atom>; connection: Atom>; connectionImmediate: Atom; @@ -385,11 +383,6 @@ export class PreviewModel implements ViewModel { const fileInfo = await get(this.statFile); return fileInfo?.path; }); - this.normFilePath = atom>(async (get) => { - const fileInfo = await get(this.statFile); - return fileInfo?.path; - }); - this.loadableStatFilePath = loadable(this.statFilePath); this.connection = atom>(async (get) => { const connName = get(this.blockAtom)?.meta?.connection; try { @@ -405,7 +398,6 @@ export class PreviewModel implements ViewModel { }); this.statFile = atom>(async (get) => { const fileName = get(this.metaFilePath); - console.log("stat file", fileName); const path = await this.formatRemoteUri(fileName, get); if (fileName == null) { return null; @@ -492,17 +484,13 @@ export class PreviewModel implements ViewModel { async getSpecializedView(getFn: Getter): Promise<{ specializedView?: string; errorStr?: string }> { const mimeType = await getFn(this.fileMimeType); const fileInfo = await getFn(this.statFile); - const fileName = await getFn(this.statFilePath); + const fileName = fileInfo?.name; const connErr = getFn(this.connectionError); const editMode = getFn(this.editMode); - const parentFileInfo = await this.getParentInfo(fileInfo); if (connErr != "") { return { errorStr: `Connection Error: ${connErr}` }; } - if (parentFileInfo?.notfound ?? false) { - return { errorStr: `Parent Directory Not Found: ${fileInfo.path}` }; - } if (fileInfo?.notfound) { return { specializedView: "codeedit" }; } @@ -716,7 +704,7 @@ export class PreviewModel implements ViewModel { label: "Copy Full Path", click: () => fireAndForget(async () => { - const filePath = await globalStore.get(this.normFilePath); + const filePath = await globalStore.get(this.statFilePath); if (filePath == null) { return; } @@ -979,8 +967,8 @@ function StreamingPreview({ model }: SpecializedViewProps) { function CodeEditPreview({ model }: SpecializedViewProps) { const fileContent = useAtomValue(model.fileContent); const setNewFileContent = useSetAtom(model.newFileContent); - const fileName = useAtomValue(model.statFilePath); const fileInfo = useAtomValue(model.statFile); + const fileName = fileInfo?.name; const blockMeta = useAtomValue(model.blockAtom)?.meta; function codeEditKeyDownHandler(e: WaveKeyboardEvent): boolean { diff --git a/pkg/remote/awsconn/awsconn.go b/pkg/remote/awsconn/awsconn.go index 5c84532b7f..e0fb2b3a87 100644 --- a/pkg/remote/awsconn/awsconn.go +++ b/pkg/remote/awsconn/awsconn.go @@ -43,7 +43,6 @@ func GetConfig(ctx context.Context, profile string) (*aws.Config, error) { return nil, fmt.Errorf("invalid connection string: %s)", profile) } profile = connMatch[1] - log.Printf("GetConfig: profile=%s", profile) // TODO: Reimplement generic profile support // profiles, cerrs := wconfig.ReadWaveHomeConfigFile(wconfig.ProfilesFile) diff --git a/pkg/remote/fileshare/fileshare.go b/pkg/remote/fileshare/fileshare.go index 558da7e551..9d1eed196a 100644 --- a/pkg/remote/fileshare/fileshare.go +++ b/pkg/remote/fileshare/fileshare.go @@ -56,6 +56,7 @@ func Read(ctx context.Context, data wshrpc.FileData) (*wshrpc.FileData, error) { } func ReadStream(ctx context.Context, data wshrpc.FileData) <-chan wshrpc.RespOrErrorUnion[wshrpc.FileData] { + log.Printf("ReadStream: %v", data.Info.Path) client, conn := CreateFileShareClient(ctx, data.Info.Path) if conn == nil || client == nil { return wshutil.SendErrCh[wshrpc.FileData](fmt.Errorf(ErrorParsingConnection, data.Info.Path)) @@ -64,6 +65,7 @@ func ReadStream(ctx context.Context, data wshrpc.FileData) <-chan wshrpc.RespOrE } func ReadTarStream(ctx context.Context, data wshrpc.CommandRemoteStreamTarData) <-chan wshrpc.RespOrErrorUnion[iochantypes.Packet] { + log.Printf("ReadTarStream: %v", data.Path) client, conn := CreateFileShareClient(ctx, data.Path) if conn == nil || client == nil { return wshutil.SendErrCh[iochantypes.Packet](fmt.Errorf(ErrorParsingConnection, data.Path)) @@ -72,6 +74,7 @@ func ReadTarStream(ctx context.Context, data wshrpc.CommandRemoteStreamTarData) } func ListEntries(ctx context.Context, path string, opts *wshrpc.FileListOpts) ([]*wshrpc.FileInfo, error) { + log.Printf("ListEntries: %v", path) client, conn := CreateFileShareClient(ctx, path) if conn == nil || client == nil { return nil, fmt.Errorf(ErrorParsingConnection, path) @@ -80,6 +83,7 @@ func ListEntries(ctx context.Context, path string, opts *wshrpc.FileListOpts) ([ } func ListEntriesStream(ctx context.Context, path string, opts *wshrpc.FileListOpts) <-chan wshrpc.RespOrErrorUnion[wshrpc.CommandRemoteListEntriesRtnData] { + log.Printf("ListEntriesStream: %v", path) client, conn := CreateFileShareClient(ctx, path) if conn == nil || client == nil { return wshutil.SendErrCh[wshrpc.CommandRemoteListEntriesRtnData](fmt.Errorf(ErrorParsingConnection, path)) @@ -88,6 +92,7 @@ func ListEntriesStream(ctx context.Context, path string, opts *wshrpc.FileListOp } func Stat(ctx context.Context, path string) (*wshrpc.FileInfo, error) { + log.Printf("Stat: %v", path) client, conn := CreateFileShareClient(ctx, path) if conn == nil || client == nil { return nil, fmt.Errorf(ErrorParsingConnection, path) @@ -96,6 +101,7 @@ func Stat(ctx context.Context, path string) (*wshrpc.FileInfo, error) { } func PutFile(ctx context.Context, data wshrpc.FileData) error { + log.Printf("PutFile: %v", data.Info.Path) client, conn := CreateFileShareClient(ctx, data.Info.Path) if conn == nil || client == nil { return fmt.Errorf(ErrorParsingConnection, data.Info.Path) @@ -104,6 +110,7 @@ func PutFile(ctx context.Context, data wshrpc.FileData) error { } func Mkdir(ctx context.Context, path string) error { + log.Printf("Mkdir: %v", path) client, conn := CreateFileShareClient(ctx, path) if conn == nil || client == nil { return fmt.Errorf(ErrorParsingConnection, path) @@ -112,6 +119,7 @@ func Mkdir(ctx context.Context, path string) error { } func Move(ctx context.Context, data wshrpc.CommandFileCopyData) error { + log.Printf("Move: %v", data) srcClient, srcConn := CreateFileShareClient(ctx, data.SrcUri) if srcConn == nil || srcClient == nil { return fmt.Errorf("error creating fileshare client, could not parse source connection %s", data.SrcUri) @@ -140,6 +148,7 @@ func Move(ctx context.Context, data wshrpc.CommandFileCopyData) error { } func Copy(ctx context.Context, data wshrpc.CommandFileCopyData) error { + log.Printf("Copy: %v", data) srcClient, srcConn := CreateFileShareClient(ctx, data.SrcUri) if srcConn == nil || srcClient == nil { return fmt.Errorf("error creating fileshare client, could not parse source connection %s", data.SrcUri) @@ -156,6 +165,7 @@ func Copy(ctx context.Context, data wshrpc.CommandFileCopyData) error { } func Delete(ctx context.Context, data wshrpc.CommandDeleteFileData) error { + log.Printf("Delete: %v", data) client, conn := CreateFileShareClient(ctx, data.Path) if conn == nil || client == nil { return fmt.Errorf(ErrorParsingConnection, data.Path) @@ -164,6 +174,7 @@ func Delete(ctx context.Context, data wshrpc.CommandDeleteFileData) error { } func Join(ctx context.Context, path string, parts ...string) (*wshrpc.FileInfo, error) { + log.Printf("Join: %v", path) client, conn := CreateFileShareClient(ctx, path) if conn == nil || client == nil { return nil, fmt.Errorf(ErrorParsingConnection, path) @@ -172,6 +183,7 @@ func Join(ctx context.Context, path string, parts ...string) (*wshrpc.FileInfo, } func Append(ctx context.Context, data wshrpc.FileData) error { + log.Printf("Append: %v", data.Info.Path) client, conn := CreateFileShareClient(ctx, data.Info.Path) if conn == nil || client == nil { return fmt.Errorf(ErrorParsingConnection, data.Info.Path) @@ -180,6 +192,7 @@ func Append(ctx context.Context, data wshrpc.FileData) error { } func GetCapability(ctx context.Context, path string) (wshrpc.FileShareCapability, error) { + log.Printf("GetCapability: %v", path) client, conn := CreateFileShareClient(ctx, path) if conn == nil || client == nil { return wshrpc.FileShareCapability{}, fmt.Errorf(ErrorParsingConnection, path) diff --git a/pkg/remote/fileshare/s3fs/s3fs.go b/pkg/remote/fileshare/s3fs/s3fs.go index 2130906246..f61e30e3ad 100644 --- a/pkg/remote/fileshare/s3fs/s3fs.go +++ b/pkg/remote/fileshare/s3fs/s3fs.go @@ -53,7 +53,6 @@ func (c S3Client) Read(ctx context.Context, conn *connparse.Connection, data wsh func (c S3Client) ReadStream(ctx context.Context, conn *connparse.Connection, data wshrpc.FileData) <-chan wshrpc.RespOrErrorUnion[wshrpc.FileData] { bucket := conn.Host objectKey := conn.Path - log.Printf("s3fs.ReadStream: %v", conn.GetFullURI()) rtn := make(chan wshrpc.RespOrErrorUnion[wshrpc.FileData], 16) go func() { defer close(rtn) @@ -488,7 +487,6 @@ func (c S3Client) ListEntriesStream(ctx context.Context, conn *connparse.Connect } func (c S3Client) Stat(ctx context.Context, conn *connparse.Connection) (*wshrpc.FileInfo, error) { - log.Printf("Stat: %v", conn.GetFullURI()) bucketName := conn.Host objectKey := conn.Path if bucketName == "" || bucketName == fspath.Separator { @@ -604,7 +602,6 @@ func (c S3Client) Stat(ctx context.Context, conn *connparse.Connection) (*wshrpc } func (c S3Client) PutFile(ctx context.Context, conn *connparse.Connection, data wshrpc.FileData) error { - log.Printf("PutFile: %v", conn.GetFullURI()) if data.At != nil { log.Printf("PutFile: offset %d and size %d", data.At.Offset, data.At.Size) return errors.Join(errors.ErrUnsupported, fmt.Errorf("file data offset and size not supported")) From 721082574196b51b9d507d6250f50cb721999962 Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Tue, 18 Feb 2025 14:25:52 -0800 Subject: [PATCH 3/4] undo some atom changes --- frontend/app/view/preview/preview.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/frontend/app/view/preview/preview.tsx b/frontend/app/view/preview/preview.tsx index de1555e6ea..1f4783c6a2 100644 --- a/frontend/app/view/preview/preview.tsx +++ b/frontend/app/view/preview/preview.tsx @@ -201,14 +201,14 @@ export class PreviewModel implements ViewModel { this.errorMsgAtom = atom(null) as PrimitiveAtom; this.viewIcon = atom((get) => { const blockData = get(this.blockAtom); - const connStatus = get(this.connStatus); - const mimeTypeLoadable = get(this.fileMimeTypeLoadable); if (blockData?.meta?.icon) { return blockData.meta.icon; } + const connStatus = get(this.connStatus); if (connStatus?.status != "connected") { return null; } + const mimeTypeLoadable = get(this.fileMimeTypeLoadable); const mimeType = jotaiLoadableValue(mimeTypeLoadable, ""); if (mimeType == "directory") { return { @@ -438,15 +438,14 @@ export class PreviewModel implements ViewModel { const fileContentAtom = atom( async (get) => { const newContent = get(this.newFileContent); - const savedContent = get(this.fileContentSaved); - const fullFile = await get(fullFileAtom); - console.log("full file", fullFile); if (newContent != null) { return newContent; } + const savedContent = get(this.fileContentSaved); if (savedContent != null) { return savedContent; } + const fullFile = await get(fullFileAtom); return base64ToString(fullFile?.data64); }, (_, set, update: string) => { From 1062596f7b5dbb2924ee9486e339855e87900ca6 Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Tue, 18 Feb 2025 14:57:05 -0800 Subject: [PATCH 4/4] save --- frontend/app/view/preview/preview.tsx | 26 +------------------------- pkg/remote/fileshare/s3fs/s3fs.go | 5 ----- pkg/wshrpc/wshremote/wshremote.go | 10 ---------- 3 files changed, 1 insertion(+), 40 deletions(-) diff --git a/frontend/app/view/preview/preview.tsx b/frontend/app/view/preview/preview.tsx index 1f4783c6a2..79165dc73b 100644 --- a/frontend/app/view/preview/preview.tsx +++ b/frontend/app/view/preview/preview.tsx @@ -572,20 +572,6 @@ export class PreviewModel implements ViewModel { globalStore.set(this.newFileContent, null); } - async getParentInfo(fileInfo: FileInfo): Promise { - try { - const parentFileInfo = await RpcApi.FileInfoCommand(TabRpcClient, { - info: { - path: await this.formatRemoteUri(fileInfo.dir, globalStore.get), - }, - }); - console.log("parent file info", parentFileInfo); - return parentFileInfo; - } catch { - return undefined; - } - } - async goParentDirectory({ fileInfo = null }: { fileInfo?: FileInfo | null }) { // optional parameter needed for recursive case const defaultFileInfo = await globalStore.get(this.statFile); @@ -597,18 +583,8 @@ export class PreviewModel implements ViewModel { return true; } try { - const newFileInfo = await RpcApi.FileInfoCommand(TabRpcClient, { - info: { - path: await this.formatRemoteUri(fileInfo.dir, globalStore.get), - }, - }); - if (newFileInfo.path != "" && newFileInfo.notfound) { - console.log("parent does not exist, ", newFileInfo.path); - this.goParentDirectory({ fileInfo: newFileInfo }); - return; - } this.updateOpenFileModalAndError(false); - await this.goHistory(newFileInfo.path); + await this.goHistory(fileInfo.dir); refocusNode(this.blockId); } catch (e) { globalStore.set(this.openFileError, e.message); diff --git a/pkg/remote/fileshare/s3fs/s3fs.go b/pkg/remote/fileshare/s3fs/s3fs.go index f61e30e3ad..aef9404196 100644 --- a/pkg/remote/fileshare/s3fs/s3fs.go +++ b/pkg/remote/fileshare/s3fs/s3fs.go @@ -88,7 +88,6 @@ func (c S3Client) ReadStream(ctx context.Context, conn *connparse.Connection, da Range: aws.String(fmt.Sprintf("bytes=%d-%d", data.At.Offset, data.At.Offset+int64(data.At.Size)-1)), }) } else { - log.Printf("reading %v", conn.GetFullURI()) result, err = c.client.GetObject(ctx, &s3.GetObjectInput{ Bucket: aws.String(bucket), Key: aws.String(objectKey), @@ -116,7 +115,6 @@ func (c S3Client) ReadStream(ctx context.Context, conn *connparse.Connection, da Dir: fsutil.GetParentPath(conn), } fileutil.AddMimeTypeToFileInfo(finfo.Path, finfo) - log.Printf("file info: %v", finfo) rtn <- wshrpc.RespOrErrorUnion[wshrpc.FileData]{Response: wshrpc.FileData{Info: finfo}} if size == 0 { log.Printf("no data to read") @@ -125,10 +123,8 @@ func (c S3Client) ReadStream(ctx context.Context, conn *connparse.Connection, da defer utilfn.GracefulClose(result.Body, "s3fs", conn.GetFullURI()) bytesRemaining := size for { - log.Printf("bytes remaining: %d", bytesRemaining) select { case <-ctx.Done(): - log.Printf("context done") rtn <- wshutil.RespErr[wshrpc.FileData](context.Cause(ctx)) return default: @@ -138,7 +134,6 @@ func (c S3Client) ReadStream(ctx context.Context, conn *connparse.Connection, da rtn <- wshutil.RespErr[wshrpc.FileData](err) return } - log.Printf("read %d bytes", n) if n == 0 { break } diff --git a/pkg/wshrpc/wshremote/wshremote.go b/pkg/wshrpc/wshremote/wshremote.go index 9d0e0a7188..3cc15a58a0 100644 --- a/pkg/wshrpc/wshremote/wshremote.go +++ b/pkg/wshrpc/wshremote/wshremote.go @@ -126,13 +126,11 @@ func (impl *ServerImpl) remoteStreamFileDir(ctx context.Context, path string, by innerFileInfo := statToFileInfo(filepath.Join(path, innerFileInfoInt.Name()), innerFileInfoInt, false) fileInfoArr = append(fileInfoArr, innerFileInfo) if len(fileInfoArr) >= wshrpc.DirChunkSize { - logPrintfDev("sending %d entries\n", len(fileInfoArr)) dataCallback(fileInfoArr, nil, byteRange) fileInfoArr = nil } } if len(fileInfoArr) > 0 { - logPrintfDev("sending %d entries\n", len(fileInfoArr)) dataCallback(fileInfoArr, nil, byteRange) } return nil @@ -701,7 +699,6 @@ func (impl *ServerImpl) RemoteFileTouchCommand(ctx context.Context, path string) } func (impl *ServerImpl) RemoteFileMoveCommand(ctx context.Context, data wshrpc.CommandFileCopyData) error { - logPrintfDev("RemoteFileCopyCommand: src=%s, dest=%s\n", data.SrcUri, data.DestUri) opts := data.Opts destUri := data.DestUri srcUri := data.SrcUri @@ -827,7 +824,6 @@ func (*ServerImpl) RemoteWriteFileCommand(ctx context.Context, data wshrpc.FileD if err != nil { return fmt.Errorf("cannot write to file %q: %w", path, err) } - logPrintfDev("wrote %d bytes to file %q at offset %d\n", n, path, atOffset) return nil } @@ -867,9 +863,3 @@ func (*ServerImpl) RemoteInstallRcFilesCommand(ctx context.Context) error { func (*ServerImpl) FetchSuggestionsCommand(ctx context.Context, data wshrpc.FetchSuggestionsData) (*wshrpc.FetchSuggestionsResponse, error) { return suggestion.FetchSuggestions(ctx, data) } - -func logPrintfDev(format string, args ...interface{}) { - if wavebase.IsDevMode() { - log.Printf(format, args...) - } -}