Skip to content

Commit 2abeb59

Browse files
committed
Check if a file was added when resolving
1 parent 0bb7eaa commit 2abeb59

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

resolver/resolver.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type SourceFile struct {
2323
type Dotfile struct {
2424
Path string
2525
Removed bool
26+
Added bool
2627
Sources []*SourceFile
2728
InstallFiles []string
2829
}
@@ -96,7 +97,7 @@ func (d dotfileMap) asList() Dotfiles {
9697
// resolveSources inserts or updates a dotfiles map from a list of
9798
// dotfile sources relative to the source root. Sources not belonging to the
9899
// specified group will be ignored.
99-
func resolveSources(dotfiles dotfileMap, sources []string, group string) {
100+
func resolveSources(dotfiles dotfileMap, sources, oldDotfiles []string, group string) {
100101
for _, source := range sources {
101102
if !strings.HasPrefix(source, group) {
102103
continue
@@ -115,9 +116,18 @@ func resolveSources(dotfiles dotfileMap, sources []string, group string) {
115116
continue
116117
}
117118

119+
added := true
120+
for _, oldDotfilePath := range oldDotfiles {
121+
if oldDotfilePath == destPath {
122+
added = false
123+
break
124+
}
125+
}
126+
118127
dotfiles[destPath] = &Dotfile{
119128
Path: destPath,
120129
Sources: []*SourceFile{sourceFile},
130+
Added: added,
121131
}
122132
}
123133
}
@@ -252,7 +262,7 @@ func ResolveDotfiles(conf config.SourceConfig, lockfile config.SourceLockfile) D
252262
groups := lockfile.ResolveGroups(conf)
253263

254264
for _, group := range groups {
255-
resolveSources(dotfiles, sources, group)
265+
resolveSources(dotfiles, sources, lockfile.InstalledFiles, group)
256266
resolveOverrides(dotfiles, "."+conf.OverrideSuffix)
257267
}
258268

resolver/resolver_test.go

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@ func TestResolveDotfiles(t *testing.T) {
5252
"machines/server/blank.ovrd",
5353
"machines/desktop/multi-composed",
5454
},
55-
ExistingFiles: []string{},
55+
ExistingFiles: []string{"bash/conf", "environment"},
5656
Groups: []string{"base", "machines/desktop", "machines/server"},
5757
OverrideSuffix: "ovrd",
5858
InstallSuffix: "inst",
5959
Expected: Dotfiles{
6060
{
61-
Path: "bash/conf",
61+
Path: "bash/conf",
62+
Added: false,
6263
Sources: []*SourceFile{
6364
{
6465
Group: "base",
@@ -68,7 +69,8 @@ func TestResolveDotfiles(t *testing.T) {
6869
InstallFiles: []string{"base/bash.inst"},
6970
},
7071
{
71-
Path: "bash/conf2",
72+
Path: "bash/conf2",
73+
Added: true,
7274
Sources: []*SourceFile{
7375
{
7476
Group: "base",
@@ -78,7 +80,8 @@ func TestResolveDotfiles(t *testing.T) {
7880
InstallFiles: []string{"base/bash.inst"},
7981
},
8082
{
81-
Path: "blank",
83+
Path: "blank",
84+
Added: true,
8285
Sources: []*SourceFile{
8386
{
8487
Group: "machines/server",
@@ -88,7 +91,8 @@ func TestResolveDotfiles(t *testing.T) {
8891
},
8992
},
9093
{
91-
Path: "environment",
94+
Path: "environment",
95+
Added: false,
9296
Sources: []*SourceFile{
9397
{
9498
Group: "base",
@@ -101,7 +105,8 @@ func TestResolveDotfiles(t *testing.T) {
101105
},
102106
},
103107
{
104-
Path: "generic-config",
108+
Path: "generic-config",
109+
Added: true,
105110
Sources: []*SourceFile{
106111
{
107112
Group: "base",
@@ -116,7 +121,8 @@ func TestResolveDotfiles(t *testing.T) {
116121
InstallFiles: []string{"base/generic-config.inst"},
117122
},
118123
{
119-
Path: "multi-composed",
124+
Path: "multi-composed",
125+
Added: true,
120126
Sources: []*SourceFile{
121127
{
122128
Group: "base",
@@ -133,7 +139,8 @@ func TestResolveDotfiles(t *testing.T) {
133139
},
134140
},
135141
{
136-
Path: "vimrc",
142+
Path: "vimrc",
143+
Added: true,
137144
Sources: []*SourceFile{
138145
{
139146
Group: "machines/desktop",
@@ -152,9 +159,11 @@ func TestResolveDotfiles(t *testing.T) {
152159
{
153160
Path: "bashrc",
154161
Removed: true,
162+
Added: false,
155163
},
156164
{
157-
Path: "vimrc",
165+
Path: "vimrc",
166+
Added: false,
158167
Sources: []*SourceFile{
159168
{
160169
Group: "base",
@@ -187,7 +196,8 @@ func TestResolveDotfiles(t *testing.T) {
187196
Groups: []string{"base", "machines/desktop", "machines/server"},
188197
Expected: Dotfiles{
189198
{
190-
Path: "bash/file1",
199+
Path: "bash/file1",
200+
Added: true,
191201
Sources: []*SourceFile{
192202
{
193203
Group: "base",
@@ -205,7 +215,8 @@ func TestResolveDotfiles(t *testing.T) {
205215
},
206216
},
207217
{
208-
Path: "bash/file2",
218+
Path: "bash/file2",
219+
Added: true,
209220
Sources: []*SourceFile{
210221
{
211222
Group: "base",
@@ -219,7 +230,8 @@ func TestResolveDotfiles(t *testing.T) {
219230
},
220231
},
221232
{
222-
Path: "bash/file3",
233+
Path: "bash/file3",
234+
Added: true,
223235
Sources: []*SourceFile{
224236
{
225237
Group: "base",
@@ -229,7 +241,8 @@ func TestResolveDotfiles(t *testing.T) {
229241
},
230242
},
231243
{
232-
Path: "bash/file4",
244+
Path: "bash/file4",
245+
Added: true,
233246
Sources: []*SourceFile{
234247
{
235248
Group: "base",

0 commit comments

Comments
 (0)