Files
nfpm/internal/macos/paths.go
Dj GilcreaseandClaude Fable 5.2 410234f7ef feat(macos): add app, dmg and pkg packagers
Three packagers for macOS, built in pure Go on any platform:

- pkg: an installer package (.pkg) from contents and the preinstall and
  postinstall scripts, as a product archive that declares its
  architecture.
- app: an application bundle delivered as a zip (.app.zip), with a
  generated Info.plist.
- dmg: the same bundle in a disk image (.dmg) next to a link to the
  Applications folder.

app and dmg share the new "app" settings; pkg has its own. All three
take name, version, arch and contents from the shared fields, can be
signed with a PKCS#12 identity, and report the shared settings macOS has
no place for instead of dropping them silently.

Refs #535, #536.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-20 11:35:17 -08:00

48 lines
1.2 KiB
Go

package macos
import (
"fmt"
"path"
"golang.org/x/text/cases"
"golang.org/x/text/unicode/norm"
)
// PathKey returns the key two paths share when they name the same file on a
// default macOS volume, which ignores both letter case and Unicode
// normalization.
func PathKey(p string) string {
return norm.NFD.String(cases.Fold().String(p))
}
// PathIndex detects distinct paths that macOS would store as one.
type PathIndex struct {
spellings map[string]string
}
// NewPathIndex returns an empty PathIndex.
func NewPathIndex() *PathIndex {
return &PathIndex{spellings: map[string]string{}}
}
// Add records a clean, absolute path and every one of its parent
// directories. It fails when a path was already recorded with a different
// spelling.
func (i *PathIndex) Add(p string) error {
for current := p; current != "/" && current != "."; current = path.Dir(current) {
key := PathKey(current)
previous, seen := i.spellings[key]
if !seen {
i.spellings[key] = current
continue
}
if previous != current {
return fmt.Errorf(
"package contents %q and %q differ only by letter case or Unicode normalization; "+
"macOS stores them as the same path",
previous, current)
}
}
return nil
}