Skip to content

Commit

Permalink
Add Mutator.Stat
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Feb 1, 2019
1 parent 19947c8 commit c827046
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/chezmoi/any_mutator.go
Expand Up @@ -2,8 +2,8 @@ package chezmoi

import "os"

// An AnyMutator wraps another Mutator and records if any of its methods are
// called.
// An AnyMutator wraps another Mutator and records if any of its mutating
// methods are called.
type AnyMutator struct {
m Mutator
mutated bool
Expand Down Expand Up @@ -46,6 +46,11 @@ func (m *AnyMutator) Rename(oldpath, newpath string) error {
return m.m.Rename(oldpath, newpath)
}

// Stat implements Mutator.Stat.
func (m *AnyMutator) Stat(path string) (os.FileInfo, error) {
return m.m.Stat(path)
}

// WriteFile implements Mutator.WriteFile.
func (m *AnyMutator) WriteFile(name string, data []byte, perm os.FileMode, currData []byte) error {
m.mutated = true
Expand Down
5 changes: 5 additions & 0 deletions lib/chezmoi/logging_mutator.go
Expand Up @@ -71,6 +71,11 @@ func (m *LoggingMutator) Rename(oldpath, newpath string) error {
return err
}

// Stat implements Mutator.Stat.
func (m *LoggingMutator) Stat(name string) (os.FileInfo, error) {
return m.m.Stat(name)
}

// WriteFile implements Mutator.WriteFile.
func (m *LoggingMutator) WriteFile(name string, data []byte, perm os.FileMode, currData []byte) error {
action := fmt.Sprintf("install -m %o /dev/null %s", perm, name)
Expand Down
1 change: 1 addition & 0 deletions lib/chezmoi/mutator.go
Expand Up @@ -8,6 +8,7 @@ type Mutator interface {
Mkdir(name string, perm os.FileMode) error
RemoveAll(name string) error
Rename(oldpath, newpath string) error
Stat(name string) (os.FileInfo, error)
WriteFile(filename string, data []byte, perm os.FileMode, currData []byte) error
WriteSymlink(oldname, newname string) error
}
5 changes: 5 additions & 0 deletions lib/chezmoi/null_mutator.go
Expand Up @@ -27,6 +27,11 @@ func (nullMutator) Rename(string, string) error {
return nil
}

// Stat implements Mutator.Stat.
func (nullMutator) Stat(string) (os.FileInfo, error) {
return nil, nil
}

// WriteFile implements Mutator.WriteFile.
func (nullMutator) WriteFile(string, []byte, os.FileMode, []byte) error {
return nil
Expand Down

0 comments on commit c827046

Please sign in to comment.