From 48d4742725f986009d05bfc72f9dd2c45e445bb4 Mon Sep 17 00:00:00 2001 From: sawka Date: Wed, 20 Nov 2024 18:16:13 -0800 Subject: [PATCH 1/4] create tempoid in client, and then clear temp files on startup/shutdown --- cmd/server/main-server.go | 17 +++++++++++++++++ frontend/types/gotypes.d.ts | 2 ++ pkg/waveobj/wtype.go | 1 + pkg/wcore/wcore.go | 7 +++++++ 4 files changed, 27 insertions(+) diff --git a/cmd/server/main-server.go b/cmd/server/main-server.go index c916ea6a84..25b9f4038c 100644 --- a/cmd/server/main-server.go +++ b/cmd/server/main-server.go @@ -58,6 +58,7 @@ func doShutdown(reason string) { shutdownActivityUpdate() sendTelemetryWrapper() // TODO deal with flush in progress + clearTempFiles() filestore.WFS.FlushCache(ctx) watcher := wconfig.GetWatcher() if watcher != nil { @@ -193,6 +194,17 @@ func grabAndRemoveEnvVars() error { return nil } +func clearTempFiles() error { + ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second) + defer cancelFn() + client, err := wstore.DBGetSingleton[*waveobj.Client](ctx) + if err != nil { + return fmt.Errorf("error getting client: %v", err) + } + filestore.WFS.DeleteZone(ctx, client.TempOID) + return nil +} + func main() { log.SetFlags(log.LstdFlags | log.Lmicroseconds) log.SetPrefix("[wavesrv] ") @@ -268,6 +280,11 @@ func main() { log.Printf("error ensuring initial data: %v\n", err) return } + err = clearTempFiles() + if err != nil { + log.Printf("error clearing temp files: %v\n", err) + return + } if firstRun { migrateErr := wstore.TryMigrateOldHistory() if migrateErr != nil { diff --git a/frontend/types/gotypes.d.ts b/frontend/types/gotypes.d.ts index b01a7d1bbd..daf4076807 100644 --- a/frontend/types/gotypes.d.ts +++ b/frontend/types/gotypes.d.ts @@ -25,6 +25,7 @@ declare global { numsshconn?: number; numwslconn?: number; nummagnify?: number; + numpanics?: number; startup?: number; shutdown?: number; settabtheme?: number; @@ -83,6 +84,7 @@ declare global { tosagreed?: number; hasoldhistory?: boolean; nexttabid?: number; + tempoid?: string; }; // windowservice.CloseTabRtnType diff --git a/pkg/waveobj/wtype.go b/pkg/waveobj/wtype.go index 0293319b19..1ef6b2e849 100644 --- a/pkg/waveobj/wtype.go +++ b/pkg/waveobj/wtype.go @@ -128,6 +128,7 @@ type Client struct { TosAgreed int64 `json:"tosagreed,omitempty"` HasOldHistory bool `json:"hasoldhistory,omitempty"` NextTabId int `json:"nexttabid,omitempty"` + TempOID string `json:"tempoid,omitempty"` } func (*Client) GetOType() string { diff --git a/pkg/wcore/wcore.go b/pkg/wcore/wcore.go index 0e699f5a5c..2e90e37d36 100644 --- a/pkg/wcore/wcore.go +++ b/pkg/wcore/wcore.go @@ -215,6 +215,13 @@ func EnsureInitialData() (*waveobj.Window, bool, error) { return nil, false, fmt.Errorf("error updating client: %w", err) } } + if client.TempOID == "" { + client.TempOID = uuid.NewString() + err = wstore.DBUpdate(ctx, client) + if err != nil { + return nil, false, fmt.Errorf("error updating client: %w", err) + } + } log.Printf("clientid: %s\n", client.OID) if len(client.WindowIds) == 1 { checkAndFixWindow(ctx, client.WindowIds[0]) From 139ac936959fa9cae00fe10ad7b86207fd3f1abb Mon Sep 17 00:00:00 2001 From: sawka Date: Wed, 20 Nov 2024 18:32:03 -0800 Subject: [PATCH 2/4] don't show error for empty roots --- cmd/wsh/cmd/wshcmd-file-util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/wsh/cmd/wshcmd-file-util.go b/cmd/wsh/cmd/wshcmd-file-util.go index 4979c15fdf..73578ef8b9 100644 --- a/cmd/wsh/cmd/wshcmd-file-util.go +++ b/cmd/wsh/cmd/wshcmd-file-util.go @@ -184,7 +184,7 @@ func streamFileList(zoneId string, path string, recursive bool, filesOnly bool) } if len(files) == 0 { - if !foundAny { + if !foundAny && prefix != "" { resultChan <- fileListResult{err: fmt.Errorf("%s: No such file or directory", path)} } return From b108d2c92a5399bdf6f591ae8a9052b9ce85cf9f Mon Sep 17 00:00:00 2001 From: sawka Date: Wed, 20 Nov 2024 18:32:30 -0800 Subject: [PATCH 3/4] resolve 'temp' as a blockid --- pkg/waveobj/wtype.go | 2 ++ pkg/wshrpc/wshserver/resolvers.go | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/waveobj/wtype.go b/pkg/waveobj/wtype.go index 1ef6b2e849..228bc596d1 100644 --- a/pkg/waveobj/wtype.go +++ b/pkg/waveobj/wtype.go @@ -28,6 +28,7 @@ const ( OType_Tab = "tab" OType_LayoutState = "layout" OType_Block = "block" + OType_Temp = "temp" ) var ValidOTypes = map[string]bool{ @@ -37,6 +38,7 @@ var ValidOTypes = map[string]bool{ OType_Tab: true, OType_LayoutState: true, OType_Block: true, + OType_Temp: true, } type WaveObjUpdate struct { diff --git a/pkg/wshrpc/wshserver/resolvers.go b/pkg/wshrpc/wshserver/resolvers.go index 4de74bcdb0..434fba6ef1 100644 --- a/pkg/wshrpc/wshserver/resolvers.go +++ b/pkg/wshrpc/wshserver/resolvers.go @@ -24,6 +24,7 @@ const ( SimpleId_Workspace = "workspace" SimpleId_Client = "client" SimpleId_Global = "global" + SimpleId_Temp = "temp" ) var ( @@ -41,7 +42,8 @@ func parseSimpleId(simpleId string) (discriminator string, value string, err err // Handle special keywords if simpleId == SimpleId_This || simpleId == SimpleId_Block || simpleId == SimpleId_Tab || - simpleId == SimpleId_Ws || simpleId == SimpleId_Workspace || simpleId == SimpleId_Client || simpleId == SimpleId_Global { + simpleId == SimpleId_Ws || simpleId == SimpleId_Workspace || + simpleId == SimpleId_Client || simpleId == SimpleId_Global || simpleId == SimpleId_Temp { return "this", simpleId, nil } @@ -110,6 +112,13 @@ func resolveThis(ctx context.Context, data wshrpc.CommandResolveIdsData, value s } return &waveobj.ORef{OType: waveobj.OType_Client, OID: client.OID}, nil } + if value == SimpleId_Temp { + client, err := wstore.DBGetSingleton[*waveobj.Client](ctx) + if err != nil { + return nil, fmt.Errorf("error getting client: %v", err) + } + return &waveobj.ORef{OType: "temp", OID: client.TempOID}, nil + } return nil, fmt.Errorf("invalid value for 'this' resolver: %s", value) } From 12620a9271e674c9fe1e60750f09213610ff5445 Mon Sep 17 00:00:00 2001 From: sawka Date: Wed, 20 Nov 2024 18:43:11 -0800 Subject: [PATCH 4/4] activity for file cmds --- cmd/wsh/cmd/wshcmd-file.go | 14 +++++++------- cmd/wsh/cmd/wshcmd-root.go | 11 +++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cmd/wsh/cmd/wshcmd-file.go b/cmd/wsh/cmd/wshcmd-file.go index 1e74b462bc..6d2fbc4856 100644 --- a/cmd/wsh/cmd/wshcmd-file.go +++ b/cmd/wsh/cmd/wshcmd-file.go @@ -104,7 +104,7 @@ var fileListCmd = &cobra.Command{ Use: "ls [wavefile://zone[/path]]", Short: "list wave files", Example: " wsh file ls wavefile://block/\n wsh file ls wavefile://client/configs/", - RunE: fileListRun, + RunE: activityWrap("file", fileListRun), PreRunE: preRunSetupRpcClient, } @@ -113,7 +113,7 @@ var fileCatCmd = &cobra.Command{ Short: "display contents of a wave file", Example: " wsh file cat wavefile://block/config.txt\n wsh file cat wavefile://client/settings.json", Args: cobra.ExactArgs(1), - RunE: fileCatRun, + RunE: activityWrap("file", fileCatRun), PreRunE: preRunSetupRpcClient, } @@ -122,7 +122,7 @@ var fileInfoCmd = &cobra.Command{ Short: "show wave file information", Example: " wsh file info wavefile://block/config.txt", Args: cobra.ExactArgs(1), - RunE: fileInfoRun, + RunE: activityWrap("file", fileInfoRun), PreRunE: preRunSetupRpcClient, } @@ -131,7 +131,7 @@ var fileRmCmd = &cobra.Command{ Short: "remove a wave file", Example: " wsh file rm wavefile://block/config.txt", Args: cobra.ExactArgs(1), - RunE: fileRmRun, + RunE: activityWrap("file", fileRmRun), PreRunE: preRunSetupRpcClient, } @@ -140,7 +140,7 @@ var fileWriteCmd = &cobra.Command{ Short: "write stdin into a wave file (up to 10MB)", Example: " echo 'hello' | wsh file write wavefile://block/greeting.txt", Args: cobra.ExactArgs(1), - RunE: fileWriteRun, + RunE: activityWrap("file", fileWriteRun), PreRunE: preRunSetupRpcClient, } @@ -150,7 +150,7 @@ var fileAppendCmd = &cobra.Command{ Long: "append stdin to a wave file, buffering input and respecting 10MB total file size limit", Example: " tail -f log.txt | wsh file append wavefile://block/app.log", Args: cobra.ExactArgs(1), - RunE: fileAppendRun, + RunE: activityWrap("file", fileAppendRun), PreRunE: preRunSetupRpcClient, } @@ -161,7 +161,7 @@ var fileCpCmd = &cobra.Command{ Exactly one of source or destination must be a wavefile:// URL.`, Example: " wsh file cp wavefile://block/config.txt ./local-config.txt\n wsh file cp ./local-config.txt wavefile://block/config.txt", Args: cobra.ExactArgs(2), - RunE: fileCpRun, + RunE: activityWrap("file", fileCpRun), PreRunE: preRunSetupRpcClient, } diff --git a/cmd/wsh/cmd/wshcmd-root.go b/cmd/wsh/cmd/wshcmd-root.go index f7bf2bb3b8..8ba14b556c 100644 --- a/cmd/wsh/cmd/wshcmd-root.go +++ b/cmd/wsh/cmd/wshcmd-root.go @@ -57,6 +57,17 @@ func preRunSetupRpcClient(cmd *cobra.Command, args []string) error { return nil } +type RunEFnType = func(*cobra.Command, []string) error + +func activityWrap(activityStr string, origRunE RunEFnType) RunEFnType { + return func(cmd *cobra.Command, args []string) (rtnErr error) { + defer func() { + sendActivity(activityStr, rtnErr == nil) + }() + return origRunE(cmd, args) + } +} + func resolveBlockArg() (*waveobj.ORef, error) { oref := blockArg if oref == "" {