Skip to content

fix(tempfile): avoid hdiutil deprecation warning on macOS 27 - #3610

Merged
dominikschulz merged 1 commit into
gopasspw:masterfrom
1995parham:fix/macos-27-hdiutil-deprecation
Sep 22, 2026
Merged

dominikschulz merged 1 commit into
gopasspw:masterfrom
1995parham:fix/macos-27-hdiutil-deprecation

Conversation

@1995parham

Copy link
Copy Markdown
Contributor

Summary

On macOS 27, every gopass command that needs a secure tempdir prints a deprecation warning to stderr:

hdiutil: WARNING: 'hdiutil attach -nomount ...' is deprecated. Please use 'diskutil image attach --noMount ...' instead.

pkg/tempfile creates its ramdisk with hdid -drivekey system-image=yes -nomount ram://32768. hdid(8) is a thin wrapper around the hdiutil disk image interface, which macOS 27 deprecated. The attach still succeeds, but mount sets cmd.Stderr = os.Stderr, so the warning goes straight to the user's terminal on every gopass edit, gopass env, and anything else that goes through tempfile.New.

Fix

Prefer diskutil image attach --noMount --nobrowse ram://32768, and keep hdid as a fallback for releases that predate the image verb. The probe's stderr is captured rather than passed through, so users on older macOS see no output from an attempt that did not end up mattering, and the outcome is memoized so the failed exec happens at most once per process.

The two commands format their output differently, so the device-node parsing had to change. hdid pads the node with spaces and tabs (/dev/disk4 \t \t\n) while diskutil emits it bare (/dev/disk4\n). The existing strings.Split(out, " ")[0] happens to work for hdid but would have kept the trailing newline on diskutil output and produced an invalid device node; strings.Fields handles both. parseDev is covered by a new table test using the real output of both commands.

Everything after the attach is unchanged — newfs_hfs and the diskutil mount / unmountDisk / eject calls are not deprecated and work as before.

Also corrects the ramdisk size comment: 32768 sectors of 512 bytes is 16 MiB, not the 32 MB the comment claimed. newfs_hfs confirms it — Initialized /dev/rdisk4 as a 16 MB case-insensitive HFS Plus volume.

Testing

Verified on macOS 27.0 (build 26A428, arm64) with a small program calling tempfile.New and capturing stderr.

Before, on master:

TMPFILE: /var/folders/.../gopass-check-442827772/secret
OK
--- stderr: ---
hdiutil: WARNING: 'hdiutil attach -nomount ...' is deprecated. Please use 'diskutil image attach --noMount ...' instead.

After, with this change — stderr is empty:

TMPFILE: /var/folders/.../gopass-check-776066011/secret
OK
--- stderr: ---

go test ./pkg/tempfile/... and golangci-lint run pkg/tempfile/... both pass, and the full mount/write/unmount cycle was exercised end to end.

I could not test the hdid fallback path on a pre-27 machine — I do not have one to hand. The fallback is the previous code path, reached whenever the diskutil attempt returns an error, so a reviewer on an older release confirming that gopass edit still works there would be worth having.

🤖 Generated with Claude Code

https://claude.ai/code/session_011xDya1SH2B8fmV7Mx8nDkd

macOS 27 deprecated the hdiutil disk image interface that hdid(8) wraps.
Attaching the ramdisk for a secure tempdir still works, but hdid now
prints

  hdiutil: WARNING: 'hdiutil attach -nomount ...' is deprecated.
  Please use 'diskutil image attach --noMount ...' instead.

to stderr on every call. tempfile passes that stderr straight through, so
the warning surfaces in every gopass command that needs a secure tempdir,
notably `gopass edit` and `gopass env`.

Prefer `diskutil image attach --noMount --nobrowse` and fall back to hdid
on releases without the `image` verb. The fallback's stderr is captured
rather than passed through, so probing costs no output on older systems,
and the outcome is memoized to avoid repeating the failed exec.

The two commands format their output differently: hdid pads the device
node with spaces and tabs, diskutil emits it bare. Parse with
strings.Fields instead of cutting at the first space, which would have
kept the trailing newline on diskutil's output.

Also correct the ramdisk size comment: 32768 * 512 byte sectors is 16 MiB,
not 32 MB.

Signed-off-by: Parham Alvani <parham.alvani@gmail.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011xDya1SH2B8fmV7Mx8nDkd
@dominikschulz
dominikschulz self-requested a review September 15, 2026 20:04
@dominikschulz

Copy link
Copy Markdown
Member

Thanks. Code looks reasonable, but I want to test this before merging.

@dominikschulz dominikschulz 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.

Works for me. Thanks!

@dominikschulz
dominikschulz merged commit 0b8f4ad into gopasspw:master Sep 22, 2026
10 checks passed
@1995parham
1995parham deleted the fix/macos-27-hdiutil-deprecation branch September 22, 2026 15:10
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

⌂ 换网址