Skip to content

fix(tag-db): import fs so SG tag database uploads persist - #40

Merged
bobfogg merged 1 commit into
lts_26_07.isofrom
fix/tag-db-upload-fs-import-lts26
Jul 22, 2026
Merged

fix(tag-db): import fs so SG tag database uploads persist#40
bobfogg merged 1 commit into
lts_26_07.isofrom
fix/tag-db-upload-fs-import-lts26

Conversation

@meelyn-pandit

Copy link
Copy Markdown
Contributor

Problem

Uploading a SensorGnome tag database through the web interface silently destroyed the existing database and stored nothing. The SensorGnome interface then failed with:

Error reading file: {"code":1,...,"cmd":"/usr/bin/sqlite3 /data/sg_files/SG_tag_database.sqlite 'select ... from tags ...'"}

i.e. Error: no such table: tags, because /data/sg_files/SG_tag_database.sqlite was left empty (0 bytes).

Root cause

src/station-interface/routes/sensorgnome/upload-sg-tag-file.js calls fs.writeFileSync(uri, req.body) but only imported RunCommandfs was never imported. The handler runs in order:

  1. rm /data/sg_files/SG_tag_database* — deletes the current tag DB (succeeds)
  2. fs.writeFileSync(...) — throws ReferenceError: fs is not defined

So every upload wiped the old database and wrote nothing. Confirmed on-station in the station-web-interface logs:

tag database upload
about to delete sg tag db files
executing command rm /data/sg_files/SG_tag_database*
writing tag database file
something went wrong handling new SG tag database file
ReferenceError: fs is not defined
    at .../upload-sg-tag-file.js:14:7

Fix

Add the missing import fs from 'fs'.

Follow-up (not in this PR)

The handler still rms the existing DB before writing the new one, so an aborted/invalid upload can still destroy a working database. A safer pattern would write to a temp file and rename into place only on success. Left out here to keep this a focused, minimal fix for the reported bug.

Related

Same fix for the lts_24-06.iso branch: #39

🤖 Generated with Claude Code

The /upload-sg-tag-file handler calls fs.writeFileSync() but never
imported fs, so every upload threw `ReferenceError: fs is not defined`
after the handler had already run `rm /data/sg_files/SG_tag_database*`.
Net effect: uploading a tag database deleted the existing one and wrote
nothing, leaving an empty/missing SG_tag_database.sqlite and causing the
SensorGnome interface to fail with `no such table: tags`.

Add the missing `import fs from 'fs'`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@bobfogg
bobfogg merged commit 0a70f36 into lts_26_07.iso Jul 22, 2026
@bobfogg
bobfogg deleted the fix/tag-db-upload-fs-import-lts26 branch July 22, 2026 16:27
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.

2 participants