Skip to content

Commit e58bb27

Browse files
committed
fix: correct macOS pref domain splitting and consolidate pref types
- Use LastIndex instead of Index when splitting domain.key input, so compound domains like com.apple.dock.tilesize correctly produce domain=com.apple.dock, key=tilesize - Remove omitempty from snapshot.MacOSPref.Type to prevent silent type loss during JSON round-trips; empty type continues to trigger InferPreferenceType at execution time - Remove redundant SnapshotMacOSPref struct; Config.SnapshotMacOS now uses RemoteMacOSPref directly, eliminating two field-by-field copy loops
1 parent c3e0d7b commit e58bb27

6 files changed

Lines changed: 34 additions & 23 deletions

File tree

internal/cli/snapshot.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,9 +717,9 @@ func buildImportConfig(edited *snapshot.Snapshot, dryRun bool) *config.Config {
717717
cfg.DotfilesURL = edited.Dotfiles.RepoURL
718718
}
719719

720-
cfg.SnapshotMacOS = make([]config.SnapshotMacOSPref, len(edited.MacOSPrefs))
720+
cfg.SnapshotMacOS = make([]config.RemoteMacOSPref, len(edited.MacOSPrefs))
721721
for i, p := range edited.MacOSPrefs {
722-
cfg.SnapshotMacOS[i] = config.SnapshotMacOSPref{
722+
cfg.SnapshotMacOS[i] = config.RemoteMacOSPref{
723723
Domain: p.Domain,
724724
Key: p.Key,
725725
Type: p.Type,

internal/config/config.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type Config struct {
5050

5151
SnapshotShell *SnapshotShellConfig
5252
SnapshotGit *SnapshotGitConfig
53-
SnapshotMacOS []SnapshotMacOSPref
53+
SnapshotMacOS []RemoteMacOSPref
5454
SnapshotDotfiles string
5555
DotfilesURL string
5656
PostInstall string
@@ -68,14 +68,6 @@ type SnapshotGitConfig struct {
6868
UserEmail string
6969
}
7070

71-
type SnapshotMacOSPref struct {
72-
Domain string
73-
Key string
74-
Type string
75-
Value string
76-
Desc string
77-
}
78-
7971
type RemoteConfig struct {
8072
Username string `json:"username"`
8173
Slug string `json:"slug"`

internal/installer/installer.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,7 @@ func runCustomInstall(cfg *config.Config) error {
167167
}
168168

169169
if len(cfg.RemoteConfig.MacOSPrefs) > 0 {
170-
cfg.SnapshotMacOS = make([]config.SnapshotMacOSPref, len(cfg.RemoteConfig.MacOSPrefs))
171-
for i, p := range cfg.RemoteConfig.MacOSPrefs {
172-
cfg.SnapshotMacOS[i] = config.SnapshotMacOSPref{
173-
Domain: p.Domain,
174-
Key: p.Key,
175-
Type: p.Type,
176-
Value: p.Value,
177-
Desc: p.Desc,
178-
}
179-
}
170+
cfg.SnapshotMacOS = cfg.RemoteConfig.MacOSPrefs
180171
if err := stepRestoreMacOS(cfg); err != nil {
181172
ui.Error(fmt.Sprintf("macOS configuration failed: %v", err))
182173
softErrs = append(softErrs, fmt.Errorf("macos: %w", err))

internal/snapshot/snapshot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type PackageSnapshot struct {
3636
type MacOSPref struct {
3737
Domain string `json:"domain"`
3838
Key string `json:"key"`
39-
Type string `json:"type,omitempty"`
39+
Type string `json:"type"`
4040
Value string `json:"value"`
4141
Desc string `json:"desc"`
4242
}

internal/ui/snapshot_editor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ func buildEditedSnapshot(original *snapshot.Snapshot, m *SnapshotEditorModel) *s
791791
if pref, ok := originalPrefs[item.name]; ok {
792792
edited.MacOSPrefs = append(edited.MacOSPrefs, pref)
793793
} else if item.isAdded {
794-
dotIdx := strings.Index(item.name, ".")
794+
dotIdx := strings.LastIndex(item.name, ".")
795795
if dotIdx > 0 {
796796
edited.MacOSPrefs = append(edited.MacOSPrefs, snapshot.MacOSPref{
797797
Domain: item.name[:dotIdx],

internal/ui/snapshot_editor_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,34 @@ func TestSnapshotEditorAddMacOSPrefInvalidFormat(t *testing.T) {
749749
assert.NotNil(t, cmd)
750750
}
751751

752+
func TestBuildEditedSnapshotAddedMacOSPrefSplitsOnLastDot(t *testing.T) {
753+
snap := makeTestSnapshot()
754+
m := NewSnapshotEditor(snap)
755+
756+
// Simulate user adding com.apple.dock.tilesize=48 — domain contains multiple dots
757+
m.tabs[4].items = append(m.tabs[4].items, editorItem{
758+
name: "com.apple.dock.tilesize",
759+
value: "48",
760+
selected: true,
761+
itemType: editorItemMacOSPref,
762+
isAdded: true,
763+
})
764+
765+
edited := buildEditedSnapshot(snap, &m)
766+
767+
var added *snapshot.MacOSPref
768+
for i := range edited.MacOSPrefs {
769+
if edited.MacOSPrefs[i].Key == "tilesize" {
770+
added = &edited.MacOSPrefs[i]
771+
break
772+
}
773+
}
774+
require.NotNil(t, added, "added pref should appear in result")
775+
assert.Equal(t, "com.apple.dock", added.Domain, "domain should be everything before the last dot")
776+
assert.Equal(t, "tilesize", added.Key, "key should be the segment after the last dot")
777+
assert.Equal(t, "48", added.Value)
778+
}
779+
752780
func TestSnapshotEditorAddedItemVisualBadge(t *testing.T) {
753781
m := NewSnapshotEditor(makeTestSnapshot())
754782
m.width = 80

0 commit comments

Comments
 (0)