Skip to content

tui/audit: give every export its own timestamped file - #386

Open
NopeCharon wants to merge 1 commit into
solongate:mainfrom
NopeCharon:fix/audit-export-unique-name
Open

NopeCharon wants to merge 1 commit into
solongate:mainfrom
NopeCharon:fix/audit-export-unique-name

Conversation

@NopeCharon

Copy link
Copy Markdown
Contributor

Fixes #358.

In the TUI's Audit panel, doExport wrote both the page export (e) and the all-rows export (E) to the same fixed path, ~/.solongate/audit-export.jsonl, using os.WriteFile. A second export silently replaced the first, and the success note gave no sign that an earlier file had just been destroyed. Exporting one filter's rows and then another's left only the last.

Change

In packages/tui/audit/audit_keys.go:

  • Each export now goes to a new file named after the local time it ran, for example audit-export-20260102-153000.jsonl.
  • A new createExportFile opens that file with O_CREATE|O_EXCL, so two exports in the same second cannot collide either. The second one becomes audit-export-20260102-153000-2.jsonl, and so on. After 100 taken names it returns an error instead of looping on a directory that refuses them all.
  • The success note already named the file it wrote, so it now names the unique one.
  • The file is always new and created with mode 0600, so the follow-up os.Chmod, which only mattered for a reused file, is gone.
  • If writing or closing the file fails, the partial file is removed before the error is shown.

In packages/tui/audit/audit_view.go, the help overlay now names the pattern, audit-export-*.jsonl.

The export contents are unchanged. Nothing on the decision path changes.

Tests

In packages/tui/audit/audit_keys_test.go:

  • The three existing export tests now find the single audit-export-*.jsonl file instead of reading the fixed path.
  • TestDoExportKeepsEarlierExports: two exports in a row leave two files, each holding its own rows, and each named by its note. This fails on main.
  • TestCreateExportFileNeverReusesAName: three files created for the same timestamp get the plain name, then -2, then -3, and none has group or other access.
  • TestCreateExportFileGivesUpWhenEveryNameIsTaken: once every candidate name is taken, the next call returns an error.

I ran go vet ./audit/ (also with GOOS=windows) and go test -count=1 ./audit/ in packages/tui locally on macOS.

packages/tui/live has the same fixed-name pattern for its own export (live-export.jsonl). I left it out to keep this to the one panel the issue covers.

doExport wrote both the page export (e) and the all-rows export (E) to
the same fixed path, ~/.solongate/audit-export.jsonl, with
os.WriteFile. A second export silently replaced the first, and the
success note gave no sign that an earlier file had just been destroyed.
Exporting one filter's rows and then another's left only the last.

Each export now goes to a new file named after the local time it ran,
audit-export-20260102-153000.jsonl. createExportFile opens it with
O_CREATE|O_EXCL, so two exports in the same second cannot collide
either: the second becomes audit-export-20260102-153000-2.jsonl, and so
on. The search gives up with an error after 100 names rather than
looping on a directory that refuses them all. The success note already
names the file it wrote, so it now names the unique one.

Because the file is always new and created with mode 0600, the
follow-up os.Chmod that tightened the mode of a reused file is no
longer needed. If writing or closing the file fails, the partial file
is removed before the error is shown.

The help overlay now names the pattern, audit-export-*.jsonl.

Fixes solongate#358.

Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

audit: doExport always writes to the same fixed filename, silently overwriting the previous export

1 participant