Skip to content

Fix .vorta-init.json import for Flatpak environments#2465

Open
Nishani-B wants to merge 3 commits intoborgbase:masterfrom
Nishani-B:fix-flatpak-bootstrap-v2
Open

Fix .vorta-init.json import for Flatpak environments#2465
Nishani-B wants to merge 3 commits intoborgbase:masterfrom
Nishani-B:fix-flatpak-bootstrap-v2

Conversation

@Nishani-B
Copy link
Copy Markdown

@Nishani-B Nishani-B commented Mar 21, 2026

Fixes #2464

Description

Vorta looks for .vorta-init.json using Path.home(), which in a Flatpak
sandbox resolves to the sandboxed directory because Flatpak overrides the
HOME environment variable. Both Path.home() and os.path.expanduser("~")
read HOME, so the previous fallback was a no-op.

Solution

Use pwd.getpwuid(os.getuid()).pw_dir to query the password database directly,
bypassing any HOME override. This correctly resolves the real home directory
even inside a Flatpak sandbox.

Changes addressing review feedback

  • Fix: replaced os.path.expanduser("~") with pwd.getpwuid(os.getuid()).pw_dir
    to actually bypass the Flatpak HOME override (previous fallback was a no-op)
  • Fix: restored docstring to correct position in bootstrap_profile()
    (was placed after an executable line, making it a dead string expression)
  • Fix: reverted unrelated indentation change in notifier.deliver()
  • Fix: removed redundant .is_file() check after the for-loop
  • Add: tests/unit/test_bootstrap_profile.py — 11 tests covering
    Flatpak HOME bypass, path resolution, default profile creation,
    file lifecycle, and docstring placement

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read the CONTRIBUTING guide
  • My code follows the code style of this project
  • I have added tests to cover my changes
  • All new and existing tests passed

Copy link
Copy Markdown
Contributor

@m3nu m3nu left a comment

Choose a reason for hiding this comment

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

Thanks for working on this. The issue is real, but I don't think this PR correctly addresses it.

Core issue: os.path.expanduser("~") and Path.home() are identical

Path.home() is implemented by calling os.path.expanduser("~"). Both check the HOME env var first. In a Flatpak sandbox where HOME is overridden to the sandboxed directory, both return the same sandboxed path. The "fallback" added here is always a no-op.

To actually bypass a Flatpak HOME override, you'd need to query the password database directly:

import pwd
real_home = Path(pwd.getpwuid(os.getuid()).pw_dir)

Other issues

  1. Broken docstring — The docstring was moved below the first executable line (bootstrap_file = bootstrap_file or ...), turning it from a method docstring into a dead string expression.

  2. Unrelated indentation change — The closing paren of notifier.deliver() was re-indented without reason.

  3. Redundant .is_file() check — After the for-loop already confirmed the file exists and set bootstrap_file, the original if bootstrap_file.is_file(): check runs again redundantly.

  4. No tests for a path-resolution change that's difficult to verify manually across environments.

@Nishani-B
Copy link
Copy Markdown
Author

I've addressed all the review feedback in the latest commit

Here's a summary of what was fixed:

  • Replaced os.path.expanduser("~") with pwd.getpwuid(os.getuid()).pw_dir
    to correctly bypass the Flatpak HOME override

  • Restored the docstring to the correct position in bootstrap_profile()

  • Reverted the unrelated indentation change in notifier.deliver()

  • Removed the redundant .is_file() check after the for-loop

  • Added tests/unit/test_bootstrap_profile.py with 11 tests covering
    path resolution, Flatpak HOME bypass, file lifecycle, and docstring placement

    Please let me know if anything else should be adjusted.

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.

Vorta will not import .vorta-init.json at startup

2 participants