From e6c76eb22297d76e82e7b02231fe84b27b65bbf4 Mon Sep 17 00:00:00 2001 From: David Dworken Date: Sun, 17 Sep 2023 14:38:48 -0700 Subject: [PATCH] Make WHERE query for deleting presaved entries stricter and re-add in the error check that was removed in 713ee96a966a597d08f4367658b77860451a79cd --- client/cmd/saveHistoryEntry.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/cmd/saveHistoryEntry.go b/client/cmd/saveHistoryEntry.go index 9178787..4b59f3e 100644 --- a/client/cmd/saveHistoryEntry.go +++ b/client/cmd/saveHistoryEntry.go @@ -139,14 +139,21 @@ func saveHistoryEntry(ctx context.Context) { // Drop any entries from pre-saving since they're no longer needed if config.BetaMode { deletePresavedEntryFunc := func() error { - tx, err := lib.MakeWhereQueryFromSearch(ctx, db, "cwd:"+entry.CurrentWorkingDirectory+" start_time:"+strconv.FormatInt(entry.StartTime.Unix(), 10)+" end_time:1970/01/01_00:00:00_+00:00") + query := "cwd:" + entry.CurrentWorkingDirectory + query += " start_time:" + strconv.FormatInt(entry.StartTime.Unix(), 10) + query += " end_time:1970/01/01_00:00:00_+00:00" + tx, err := lib.MakeWhereQueryFromSearch(ctx, db, query) if err != nil { return fmt.Errorf("failed to query for pre-saved history entry: %w", err) } + tx.Where("command = ?", entry.Command) res := tx.Delete(&data.HistoryEntry{}) if res.Error != nil { return fmt.Errorf("failed to delete pre-saved history entry (expected command=%#v): %w", entry.Command, res.Error) } + if res.RowsAffected > 1 { + return fmt.Errorf("attempted to delete pre-saved entry, but something went wrong since we deleted %d rows", res.RowsAffected) + } return nil } lib.CheckFatalError(lib.RetryingDbFunction(deletePresavedEntryFunc))