mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-23 00:34:27 +01:00
Make WHERE query for deleting presaved entries stricter and re-add in the error check that was removed in 713ee96a96
This commit is contained in:
parent
4c912cfaed
commit
e6c76eb222
@ -139,14 +139,21 @@ func saveHistoryEntry(ctx context.Context) {
|
|||||||
// Drop any entries from pre-saving since they're no longer needed
|
// Drop any entries from pre-saving since they're no longer needed
|
||||||
if config.BetaMode {
|
if config.BetaMode {
|
||||||
deletePresavedEntryFunc := func() error {
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to query for pre-saved history entry: %w", err)
|
return fmt.Errorf("failed to query for pre-saved history entry: %w", err)
|
||||||
}
|
}
|
||||||
|
tx.Where("command = ?", entry.Command)
|
||||||
res := tx.Delete(&data.HistoryEntry{})
|
res := tx.Delete(&data.HistoryEntry{})
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
return fmt.Errorf("failed to delete pre-saved history entry (expected command=%#v): %w", entry.Command, res.Error)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
lib.CheckFatalError(lib.RetryingDbFunction(deletePresavedEntryFunc))
|
lib.CheckFatalError(lib.RetryingDbFunction(deletePresavedEntryFunc))
|
||||||
|
Loading…
Reference in New Issue
Block a user