Skip to content

Commit 21febcd

Browse files
committed
fix: persist work mode config and resolve packages from local path
WorkOn/WorkOff modified config in memory but never saved to disk, so WorkStatusList always reported empty. Add SaveConfigFile and ConfigService.Save to persist changes. Also fix package resolution in work mode: readManifest and packageDir now check WorkMode config and use the local path when a tap is in work mode, so install/remove/upgrade/info/search all work correctly against the local checkout.
1 parent 435a68f commit 21febcd

8 files changed

Lines changed: 58 additions & 5 deletions

File tree

pkg/dots/config.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dots
33
import (
44
"fmt"
55
"os"
6+
"path/filepath"
67

78
"gopkg.in/yaml.v3"
89
)
@@ -77,6 +78,18 @@ func LoadConfigFile(path string) (*Config, error) {
7778
return ParseConfig(data)
7879
}
7980

81+
// SaveConfigFile writes a Config to disk as YAML.
82+
func SaveConfigFile(path string, cfg *Config) error {
83+
data, err := yaml.Marshal(cfg)
84+
if err != nil {
85+
return fmt.Errorf("marshal config: %w", err)
86+
}
87+
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
88+
return err
89+
}
90+
return os.WriteFile(path, data, 0o644)
91+
}
92+
8093
// MergeConfig merges override into base. Non-zero override fields win.
8194
func MergeConfig(base, override *Config) *Config {
8295
result := *base

pkg/dotsctl/config_service.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ func (s *ConfigService) Config(cache bool) (*dots.Config, error) {
3939
return cfg, nil
4040
}
4141

42+
// Save writes the current config to disk and updates the cache.
43+
func (s *ConfigService) Save(cfg *dots.Config) error {
44+
if err := dots.SaveConfigFile(s.ConfigPath, cfg); err != nil {
45+
return err
46+
}
47+
s.cached = cfg
48+
return nil
49+
}
50+
4251
// InvalidateCache clears the cached config.
4352
func (s *ConfigService) InvalidateCache() {
4453
s.cached = nil

pkg/dotsctl/dots_info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (d *Dots) Info(ctx context.Context, pkgRef string) (*InfoResult, error) {
3131
}
3232

3333
// Read manifest if available
34-
manifestData, err := d.Repo.ReadManifest(ctx, tap, pkg)
34+
manifestData, err := d.readManifest(ctx, tap, pkg)
3535
if err == nil {
3636
manifest, err := dots.ParseManifest(manifestData)
3737
if err == nil {

pkg/dotsctl/dots_install.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dotsctl
33
import (
44
"context"
55
"fmt"
6+
"os"
67
"strings"
78
"time"
89

@@ -34,7 +35,7 @@ func (d *Dots) Install(ctx context.Context, opts InstallOptions) (*InstallResult
3435
}
3536

3637
// Read and parse manifest
37-
manifestData, err := d.Repo.ReadManifest(ctx, tap, pkg)
38+
manifestData, err := d.readManifest(ctx, tap, pkg)
3839
if err != nil {
3940
return nil, fmt.Errorf("read manifest: %w", err)
4041
}
@@ -193,7 +194,29 @@ func (d *Dots) resolveStrategy(override, pkgStrategy dots.LinkStrategy) dots.Lin
193194
return dots.LinkSymlink
194195
}
195196

197+
// readManifest reads a package manifest, checking work mode paths first.
198+
func (d *Dots) readManifest(ctx context.Context, tap, pkg string) ([]byte, error) {
199+
cfg, _ := d.ConfigService.Config(true)
200+
if cfg != nil {
201+
if localPath, ok := cfg.WorkMode[tap]; ok {
202+
manifestPath := localPath + "/" + pkg + "/Dotfile.yaml"
203+
data, err := os.ReadFile(manifestPath)
204+
if err != nil {
205+
return nil, &dots.PackageNotFoundError{Tap: tap, Package: pkg}
206+
}
207+
return data, nil
208+
}
209+
}
210+
return d.Repo.ReadManifest(ctx, tap, pkg)
211+
}
212+
196213
func (d *Dots) packageDir(tap, pkg string) string {
214+
cfg, _ := d.ConfigService.Config(true)
215+
if cfg != nil {
216+
if localPath, ok := cfg.WorkMode[tap]; ok {
217+
return localPath + "/" + pkg
218+
}
219+
}
197220
return d.PathService.TapsDir() + "/" + tap + "/" + pkg
198221
}
199222

pkg/dotsctl/dots_remove.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (d *Dots) Remove(ctx context.Context, opts RemoveOptions) error {
4141

4242
// Run pre_remove hook if manifest is available
4343
pkgDir := d.packageDir(tap, pkg)
44-
manifestData, _ := d.Repo.ReadManifest(ctx, tap, pkg)
44+
manifestData, _ := d.readManifest(ctx, tap, pkg)
4545
if manifestData != nil {
4646
manifest, err := dots.ParseManifest(manifestData)
4747
if err == nil {

pkg/dotsctl/dots_search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (d *Dots) Search(ctx context.Context, query string) ([]SearchResult, error)
7373
}
7474

7575
func (d *Dots) readAndParseManifest(ctx context.Context, tap, pkg string) (*dots.Manifest, error) {
76-
data, err := d.Repo.ReadManifest(ctx, tap, pkg)
76+
data, err := d.readManifest(ctx, tap, pkg)
7777
if err != nil {
7878
return nil, err
7979
}

pkg/dotsctl/dots_upgrade.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (d *Dots) Upgrade(ctx context.Context, opts UpgradeOptions) error {
3838

3939
// Run pre_upgrade hook
4040
pkgDir := d.packageDir(tap, pkg)
41-
manifestData, err := d.Repo.ReadManifest(ctx, tap, pkg)
41+
manifestData, err := d.readManifest(ctx, tap, pkg)
4242
if err != nil {
4343
return fmt.Errorf("read manifest: %w", err)
4444
}

pkg/dotsctl/dots_work.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ func (d *Dots) WorkOn(ctx context.Context, opts WorkOnOptions) error {
2929
}
3030
cfg.WorkMode[opts.Tap] = opts.LocalPath
3131

32+
if err := d.ConfigService.Save(cfg); err != nil {
33+
return fmt.Errorf("save config: %w", err)
34+
}
35+
3236
// Re-link all installed packages from this tap using local path
3337
lockfile, err := d.Repo.ReadLockfile(ctx)
3438
if err == nil {
@@ -54,6 +58,10 @@ func (d *Dots) WorkOff(ctx context.Context, tap string) error {
5458
}
5559
delete(cfg.WorkMode, tap)
5660

61+
if err := d.ConfigService.Save(cfg); err != nil {
62+
return fmt.Errorf("save config: %w", err)
63+
}
64+
5765
// Re-link packages from internal clone
5866
lockfile, err := d.Repo.ReadLockfile(ctx)
5967
if err == nil {

0 commit comments

Comments
 (0)