Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions cmd/server/main-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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] ")
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/wsh/cmd/wshcmd-file-util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions cmd/wsh/cmd/wshcmd-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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,
}

Expand All @@ -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,
}

Expand All @@ -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,
}

Expand All @@ -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,
}

Expand All @@ -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,
}

Expand All @@ -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,
}

Expand Down
11 changes: 11 additions & 0 deletions cmd/wsh/cmd/wshcmd-root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
2 changes: 2 additions & 0 deletions frontend/types/gotypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ declare global {
numsshconn?: number;
numwslconn?: number;
nummagnify?: number;
numpanics?: number;
startup?: number;
shutdown?: number;
settabtheme?: number;
Expand Down Expand Up @@ -83,6 +84,7 @@ declare global {
tosagreed?: number;
hasoldhistory?: boolean;
nexttabid?: number;
tempoid?: string;
};

// windowservice.CloseTabRtnType
Expand Down
3 changes: 3 additions & 0 deletions pkg/waveobj/wtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
OType_Tab = "tab"
OType_LayoutState = "layout"
OType_Block = "block"
OType_Temp = "temp"
)

var ValidOTypes = map[string]bool{
Expand All @@ -37,6 +38,7 @@ var ValidOTypes = map[string]bool{
OType_Tab: true,
OType_LayoutState: true,
OType_Block: true,
OType_Temp: true,
}

type WaveObjUpdate struct {
Expand Down Expand Up @@ -128,6 +130,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 {
Expand Down
7 changes: 7 additions & 0 deletions pkg/wcore/wcore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
11 changes: 10 additions & 1 deletion pkg/wshrpc/wshserver/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
SimpleId_Workspace = "workspace"
SimpleId_Client = "client"
SimpleId_Global = "global"
SimpleId_Temp = "temp"
)

var (
Expand All @@ -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
}

Expand Down Expand Up @@ -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)
}

Expand Down