Skip to content

Pruned dead code, bumped version, fixed typos#16

Merged
csd113 merged 3 commits intomainfrom
indev
Mar 9, 2026
Merged

Pruned dead code, bumped version, fixed typos#16
csd113 merged 3 commits intomainfrom
indev

Conversation

@csd113
Copy link
Owner

@csd113 csd113 commented Mar 9, 2026

No description provided.

csd113 added 3 commits March 8, 2026 21:34
Performed lots of basic bug fixes and removed dead code
@csd113 csd113 merged commit 8f2719f into main Mar 9, 2026
9 checks passed
csd113 added a commit that referenced this pull request Mar 18, 2026
## Fix: backup validation, logging rotation, and DB consistency improvements

This PR completes updates to `backup.rs` and `logging.rs`, along with several fixes across the database layer.

---

### Summary of Changes

#### `db/posts.rs`

- **#13 – Constant-time comparison**
  - Replaced custom `constant_time_eq` with `subtle::ConstantTimeEq`
  - Use: `a.ct_eq(b).into()`
  - Added import: `use subtle::ConstantTimeEq as _`
  - Removed hand-rolled implementation

- **#16 – Poll vote race condition**
  - Updated `cast_vote` query:
    - JOINs `polls` table
    - Adds expiry guard:
      ```sql
      AND (p.expires_at IS NULL OR p.expires_at > unixepoch())
      ```
  - Prevents race between handler validation and INSERT

- **#25 – `edit_window_secs` semantics**
  - `0` → no time limit (skips check via `Option`)
  - Negative → fallback to 300s
  - Positive → used as-is

---

#### `handlers/admin/backup.rs`

- **#19 – SQLite validation**
  - Added magic byte check (`b"SQLite format 3\0"`) after extracting `chan.db`
  - Applied to:
    - `admin_restore`
    - `restore_saved_board_backup`
  - Invalid DB now returns `400 Bad Request` before `rusqlite` usage

- **#30 – Duplicate encoding logic removed**
  - Removed inner `encode_q` / `nibble` definitions
  - Introduced single module-level `encode_q`
  - Shared across:
    - `admin_restore`
    - `restore_saved_board_backup`
    - `board_restore`

---

#### `db/logging.rs` (moved from `logging.rs`)

- **#33 – Log rotation**
  - Replaced `rolling::never` with `rolling::daily`
  - Logs now rotate automatically:
    ```
    rustchan.log.YYYY-MM-DD
    ```

- **Location + API updates**
  - Moved file to: `db/logging.rs`
  - Renamed `log_dir` → `db_dir`
  - Logs now stored alongside `chan.db`
  - Updated documentation accordingly

---

### Required Follow-ups

- Update module declaration:

  ```rust
  // db/mod.rs
  pub mod logging;
@csd113 csd113 mentioned this pull request Mar 18, 2026
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.

1 participant