Skip to content

Flash via udisks2 on Linux instead of requiring root#14

Open
justanotherariel wants to merge 5 commits into
mainfrom
justanotherariel-udisks2
Open

Flash via udisks2 on Linux instead of requiring root#14
justanotherariel wants to merge 5 commits into
mainfrom
justanotherariel-udisks2

Conversation

@justanotherariel

@justanotherariel justanotherariel commented Jun 22, 2026

Copy link
Copy Markdown
Member

Description

Flashes drives on Linux through the udisks2 D-Bus API instead of requiring the whole app to run as root. The device is resolved, unmounted, and opened via udisks2, so a single polkit prompt grants access for everything. Adds a DiskServiceUnavailable error for when udisks2 isn't installed/running.

Beyond the cleaner UX, this fixes UI rendering glitches when flashing: writing previously needed the whole Tauri app to run as root, and WebKitGTK's web/network process can't initialize its bubblewrap sandbox as uid 0, so subresources served over Tauri's asset protocol (CSS/JS/images) failed to load and the UI rendered unstyled/broken.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • CI/CD changes

Related Issues

Testing

  • Unit tests added/updated
  • E2E tests added/updated
  • Manually tested on macOS
  • Manually tested on Windows
  • Manually tested on Linux

Screenshots

Checklist

  • My code follows the project's code style
  • I have run cargo fmt and npm run lint
  • I have added tests for my changes
  • All new and existing tests pass
  • I have updated documentation if needed
  • My commits follow conventional commit format

@codecov-commenter

codecov-commenter commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.54086% with 68 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.76%. Comparing base (020a1dc) to head (1c1572c).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
crates/hai-core/src/disk_writer.rs 74.49% 63 Missing ⚠️
crates/hai-desktop/src/commands.rs 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #14      +/-   ##
==========================================
+ Coverage   89.52%   89.76%   +0.24%     
==========================================
  Files          28       28              
  Lines       10887    11055     +168     
  Branches       82       82              
==========================================
+ Hits         9747     9924     +177     
+ Misses       1140     1131       -9     
Flag Coverage Δ
backend 92.32% <73.54%> (+0.30%) ⬆️
frontend 84.80% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI review requested due to automatic review settings July 6, 2026 10:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes Linux drive flashing to go through the udisks2 D-Bus API (via zbus) instead of requiring the entire Tauri app to run as root. Resolving, unmounting, and opening the target device now happen through udisks2, so a single polkit prompt authorizes the operation. This also fixes a WebKitGTK rendering bug where running the whole app as root broke the asset-protocol sandbox and left the UI unstyled.

Changes:

  • Replace root-based OpenOptions device access on Linux with udisks2 D-Bus proxies (Manager.ResolveDevice, Block.OpenDevice, Filesystem.Unmount), opening the fd with O_SYNC and dropping the page cache before verify.
  • Add a DiskServiceUnavailable error variant plus a map_udisks_error helper that classifies D-Bus faults into unavailable/permission/busy/not-found errors, and surface these in flash_image.
  • Merge write and verify into a single blocking task reusing one device handle, and update dependencies (zbus, libc) and tests accordingly.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/hai-core/src/disk_writer.rs Core rewrite of the Linux flashing path to use udisks2/zbus; adds proxies, error mapping, partition-name helper, and updated tests
crates/hai-core/src/error.rs Adds DiskServiceUnavailable variant and its display test
crates/hai-desktop/src/commands.rs Maps VerificationFailed/DiskServiceUnavailable to user-facing messages in flash_image
crates/hai-core/Cargo.toml Adds Linux-only zbus/libc dependencies
Cargo.toml Declares workspace zbus (v5, tokio) and libc versions
Cargo.lock Records resolved dependency graph changes

@edenhaus edenhaus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI is failing. Can you please give it a look and fix it?

Please also add some tests for your changes

@home-assistant
home-assistant Bot marked this pull request as draft July 6, 2026 15:31
@home-assistant

home-assistant Bot commented Jul 6, 2026

Copy link
Copy Markdown

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

Copilot AI review requested due to automatic review settings July 7, 2026 08:47
@justanotherariel

Copy link
Copy Markdown
Member Author

MacOS CI job seems to be flaky. Rerunning it fixed it. Added some tests.

@justanotherariel
justanotherariel marked this pull request as ready for review July 7, 2026 08:52
@home-assistant
home-assistant Bot requested a review from edenhaus July 7, 2026 08:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 6 changed files in this pull request and generated no new comments.

@edenhaus

edenhaus commented Jul 7, 2026

Copy link
Copy Markdown
Member

MacOS CI job seems to be flaky. Rerunning it fixed it. Added some tests.

Until now it was stable. So not sure if your changes introduced these flakiness but I will hold this PR back until we have the artefacts and co so we are sure everything is working as expected

@balloob balloob mentioned this pull request Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants