Skip to content

Commit

Permalink
Check if a file was added when resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed Jul 16, 2018
1 parent 0bb7eaa commit 2abeb59
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
14 changes: 12 additions & 2 deletions resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type SourceFile struct {
type Dotfile struct {
Path string
Removed bool
Added bool
Sources []*SourceFile
InstallFiles []string
}
Expand Down Expand Up @@ -96,7 +97,7 @@ func (d dotfileMap) asList() Dotfiles {
// resolveSources inserts or updates a dotfiles map from a list of
// dotfile sources relative to the source root. Sources not belonging to the
// specified group will be ignored.
func resolveSources(dotfiles dotfileMap, sources []string, group string) {
func resolveSources(dotfiles dotfileMap, sources, oldDotfiles []string, group string) {
for _, source := range sources {
if !strings.HasPrefix(source, group) {
continue
Expand All @@ -115,9 +116,18 @@ func resolveSources(dotfiles dotfileMap, sources []string, group string) {
continue
}

added := true
for _, oldDotfilePath := range oldDotfiles {
if oldDotfilePath == destPath {
added = false
break
}
}

dotfiles[destPath] = &Dotfile{
Path: destPath,
Sources: []*SourceFile{sourceFile},
Added: added,
}
}
}
Expand Down Expand Up @@ -252,7 +262,7 @@ func ResolveDotfiles(conf config.SourceConfig, lockfile config.SourceLockfile) D
groups := lockfile.ResolveGroups(conf)

for _, group := range groups {
resolveSources(dotfiles, sources, group)
resolveSources(dotfiles, sources, lockfile.InstalledFiles, group)
resolveOverrides(dotfiles, "."+conf.OverrideSuffix)
}

Expand Down
39 changes: 26 additions & 13 deletions resolver/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ func TestResolveDotfiles(t *testing.T) {
"machines/server/blank.ovrd",
"machines/desktop/multi-composed",
},
ExistingFiles: []string{},
ExistingFiles: []string{"bash/conf", "environment"},
Groups: []string{"base", "machines/desktop", "machines/server"},
OverrideSuffix: "ovrd",
InstallSuffix: "inst",
Expected: Dotfiles{
{
Path: "bash/conf",
Path: "bash/conf",
Added: false,
Sources: []*SourceFile{
{
Group: "base",
Expand All @@ -68,7 +69,8 @@ func TestResolveDotfiles(t *testing.T) {
InstallFiles: []string{"base/bash.inst"},
},
{
Path: "bash/conf2",
Path: "bash/conf2",
Added: true,
Sources: []*SourceFile{
{
Group: "base",
Expand All @@ -78,7 +80,8 @@ func TestResolveDotfiles(t *testing.T) {
InstallFiles: []string{"base/bash.inst"},
},
{
Path: "blank",
Path: "blank",
Added: true,
Sources: []*SourceFile{
{
Group: "machines/server",
Expand All @@ -88,7 +91,8 @@ func TestResolveDotfiles(t *testing.T) {
},
},
{
Path: "environment",
Path: "environment",
Added: false,
Sources: []*SourceFile{
{
Group: "base",
Expand All @@ -101,7 +105,8 @@ func TestResolveDotfiles(t *testing.T) {
},
},
{
Path: "generic-config",
Path: "generic-config",
Added: true,
Sources: []*SourceFile{
{
Group: "base",
Expand All @@ -116,7 +121,8 @@ func TestResolveDotfiles(t *testing.T) {
InstallFiles: []string{"base/generic-config.inst"},
},
{
Path: "multi-composed",
Path: "multi-composed",
Added: true,
Sources: []*SourceFile{
{
Group: "base",
Expand All @@ -133,7 +139,8 @@ func TestResolveDotfiles(t *testing.T) {
},
},
{
Path: "vimrc",
Path: "vimrc",
Added: true,
Sources: []*SourceFile{
{
Group: "machines/desktop",
Expand All @@ -152,9 +159,11 @@ func TestResolveDotfiles(t *testing.T) {
{
Path: "bashrc",
Removed: true,
Added: false,
},
{
Path: "vimrc",
Path: "vimrc",
Added: false,
Sources: []*SourceFile{
{
Group: "base",
Expand Down Expand Up @@ -187,7 +196,8 @@ func TestResolveDotfiles(t *testing.T) {
Groups: []string{"base", "machines/desktop", "machines/server"},
Expected: Dotfiles{
{
Path: "bash/file1",
Path: "bash/file1",
Added: true,
Sources: []*SourceFile{
{
Group: "base",
Expand All @@ -205,7 +215,8 @@ func TestResolveDotfiles(t *testing.T) {
},
},
{
Path: "bash/file2",
Path: "bash/file2",
Added: true,
Sources: []*SourceFile{
{
Group: "base",
Expand All @@ -219,7 +230,8 @@ func TestResolveDotfiles(t *testing.T) {
},
},
{
Path: "bash/file3",
Path: "bash/file3",
Added: true,
Sources: []*SourceFile{
{
Group: "base",
Expand All @@ -229,7 +241,8 @@ func TestResolveDotfiles(t *testing.T) {
},
},
{
Path: "bash/file4",
Path: "bash/file4",
Added: true,
Sources: []*SourceFile{
{
Group: "base",
Expand Down

0 comments on commit 2abeb59

Please sign in to comment.