From c8270461097c012be3398154fdd6588307d92097 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Thu, 31 Jan 2019 20:02:25 -0800 Subject: [PATCH] Add Mutator.Stat --- lib/chezmoi/any_mutator.go | 9 +++++++-- lib/chezmoi/logging_mutator.go | 5 +++++ lib/chezmoi/mutator.go | 1 + lib/chezmoi/null_mutator.go | 5 +++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/chezmoi/any_mutator.go b/lib/chezmoi/any_mutator.go index 182840a0447..cc7eb120f3e 100644 --- a/lib/chezmoi/any_mutator.go +++ b/lib/chezmoi/any_mutator.go @@ -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 @@ -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 diff --git a/lib/chezmoi/logging_mutator.go b/lib/chezmoi/logging_mutator.go index 844d36628cc..4c47fda02f4 100644 --- a/lib/chezmoi/logging_mutator.go +++ b/lib/chezmoi/logging_mutator.go @@ -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) diff --git a/lib/chezmoi/mutator.go b/lib/chezmoi/mutator.go index e2bd29213e9..45bd67385f5 100644 --- a/lib/chezmoi/mutator.go +++ b/lib/chezmoi/mutator.go @@ -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 } diff --git a/lib/chezmoi/null_mutator.go b/lib/chezmoi/null_mutator.go index 4f8d231cf96..c2d58b90277 100644 --- a/lib/chezmoi/null_mutator.go +++ b/lib/chezmoi/null_mutator.go @@ -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