mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-25 17:53:24 +01:00
Tweak ImportHistory so that all entries are guaranteed to have sequential timestamps that are monotonically increasing
This commit is contained in:
parent
1593caa90f
commit
f5264b6eff
@ -2489,7 +2489,8 @@ func TestImportHistory(t *testing.T) {
|
||||
require.Equal(t, "305", out)
|
||||
out = tester.RunInteractiveShell(t, ` hishtory export -pipefail`)
|
||||
require.Contains(t, out, "echo command-305")
|
||||
|
||||
out = tester.RunInteractiveShell(t, ` hishtory export -pipefail`)
|
||||
testutils.CompareGoldens(t, out, "TestImportHistory-export")
|
||||
// TODO: There is a bug here that will be evident if you check that the export is in the correct order on the remote device, because timestamps don't have sufficient granularity
|
||||
}
|
||||
|
||||
|
@ -290,6 +290,7 @@ func ImportHistory(ctx context.Context, shouldReadStdin, force bool) (int, error
|
||||
numEntriesImported := 0
|
||||
var iteratorError error = nil
|
||||
var batch []data.HistoryEntry
|
||||
importTimestamp := time.Now().UTC()
|
||||
batchSize := 100
|
||||
entriesIter(func(cmd string, err error) bool {
|
||||
if err != nil {
|
||||
@ -300,6 +301,8 @@ func ImportHistory(ctx context.Context, shouldReadStdin, force bool) (int, error
|
||||
if isBashWeirdness(cmd) || strings.HasPrefix(cmd, " ") {
|
||||
return true
|
||||
}
|
||||
startTime := importTimestamp.Add(time.Millisecond * time.Duration(numEntriesImported*2))
|
||||
endTime := startTime.Add(time.Millisecond)
|
||||
entry := normalizeEntryTimezone(data.HistoryEntry{
|
||||
LocalUsername: currentUser.Name,
|
||||
Hostname: hostname,
|
||||
@ -307,8 +310,8 @@ func ImportHistory(ctx context.Context, shouldReadStdin, force bool) (int, error
|
||||
CurrentWorkingDirectory: "Unknown",
|
||||
HomeDirectory: homedir,
|
||||
ExitCode: 0,
|
||||
StartTime: time.Now().UTC(),
|
||||
EndTime: time.Now().UTC(),
|
||||
StartTime: startTime,
|
||||
EndTime: endTime,
|
||||
DeviceId: config.DeviceId,
|
||||
EntryId: uuid.Must(uuid.NewRandom()).String(),
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user