Skip to content

Commit

Permalink
snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Apr 10, 2020
1 parent bffd6d2 commit 2a048f0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
26 changes: 13 additions & 13 deletions v2/chezmoi/fsfilesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@ import (
vfs "github.com/twpayne/go-vfs"
)

// An FSDestDir is a DestDir on an vfs.FS.
type FSDestDir struct {
// An FSFileSystem is a FileSystem on an vfs.FS.
type FSFileSystem struct {
vfs.FS
devCache map[string]uint // devCache maps directories to device numbers.
tempDirCache map[uint]string // tempDir maps device numbers to renameio temporary directories.
}

// NewFSDestDir returns a DestDir that acts on fs.
func NewFSDestDir(fs vfs.FS) *FSDestDir {
return &FSDestDir{
// NewFSFileSystem returns a FileSystem that acts on fs.
func NewFSFileSystem(fs vfs.FS) *FSFileSystem {
return &FSFileSystem{
FS: fs,
devCache: make(map[string]uint),
tempDirCache: make(map[uint]string),
}
}

// IdempotentCmdOutput implements DestDir.IdempotentCmdOutput.
func (d *FSDestDir) IdempotentCmdOutput(cmd *exec.Cmd) ([]byte, error) {
// IdempotentCmdOutput implements FileSystem.IdempotentCmdOutput.
func (d *FSFileSystem) IdempotentCmdOutput(cmd *exec.Cmd) ([]byte, error) {
return cmd.Output()
}

// RunCmd implements DestDir.RunCmd.
func (d *FSDestDir) RunCmd(cmd *exec.Cmd) error {
// RunCmd implements FileSystem.RunCmd.
func (d *FSFileSystem) RunCmd(cmd *exec.Cmd) error {
return cmd.Run()
}

// WriteSymlink implements DestDir.WriteSymlink.
func (d *FSDestDir) WriteSymlink(oldname, newname string) error {
// WriteSymlink implements FileSystem.WriteSymlink.
func (d *FSFileSystem) WriteSymlink(oldname, newname string) error {
// Special case: if writing to the real filesystem, use
// github.com/google/renameio.
if d.FS == vfs.OSFS {
Expand All @@ -51,8 +51,8 @@ func (d *FSDestDir) WriteSymlink(oldname, newname string) error {
return d.FS.Symlink(oldname, newname)
}

// WriteFile implements DestDir.WriteFile.
func (d *FSDestDir) WriteFile(name string, data []byte, perm os.FileMode, currData []byte) error {
// WriteFile implements FileSystem.WriteFile.
func (d *FSFileSystem) WriteFile(name string, data []byte, perm os.FileMode, currData []byte) error {
// Special case: if writing to the real filesystem on a non-Windows system,
// use github.com/google/renameio.
if d.FS == vfs.OSFS && runtime.GOOS != "windows" {
Expand Down
2 changes: 1 addition & 1 deletion v2/chezmoi/fsfilesystem_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package chezmoi

var _ FileSystem = &FSDestDir{}
var _ FileSystem = &FSFileSystem{}
12 changes: 6 additions & 6 deletions v2/chezmoi/sourcestate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ func TestSourceStateApplyAll(t *testing.T) {
defer cleanup()

s := NewSourceState(
WithFileSystem(NewFSDestDir(fs)),
WithFileSystem(NewFSFileSystem(fs)),
WithSourcePath("/home/user/.local/share/chezmoi"),
)
require.NoError(t, s.Read())
require.NoError(t, s.Evaluate())
require.NoError(t, s.ApplyAll(NewFSDestDir(fs), vfst.DefaultUmask, "/home/user"))
require.NoError(t, s.ApplyAll(NewFSFileSystem(fs), vfst.DefaultUmask, "/home/user"))

vfst.RunTests(t, fs, "", tc.tests...)
})
Expand All @@ -139,7 +139,7 @@ func TestSourceStateArchive(t *testing.T) {
defer cleanup()

s := NewSourceState(
WithFileSystem(NewFSDestDir(fs)),
WithFileSystem(NewFSFileSystem(fs)),
WithSourcePath("/home/user/.local/share/chezmoi"),
)
require.NoError(t, s.Read())
Expand Down Expand Up @@ -522,7 +522,7 @@ func TestSourceStateRead(t *testing.T) {
defer cleanup()

sourceStateOptions := []SourceStateOption{
WithFileSystem(NewFSDestDir(fs)),
WithFileSystem(NewFSFileSystem(fs)),
WithSourcePath("/home/user/.local/share/chezmoi"),
}
sourceStateOptions = append(sourceStateOptions, tc.sourceStateOptions...)
Expand Down Expand Up @@ -657,13 +657,13 @@ func TestSourceStateRemove(t *testing.T) {
defer cleanup()

s := NewSourceState(
WithFileSystem(NewFSDestDir(fs)),
WithFileSystem(NewFSFileSystem(fs)),
WithSourcePath("/home/user/.local/share/chezmoi"),
)
require.NoError(t, s.Read())
require.NoError(t, s.Evaluate())

require.NoError(t, s.Remove(NewFSDestDir(fs), "/home/user"))
require.NoError(t, s.Remove(NewFSFileSystem(fs), "/home/user"))

vfst.RunTests(t, fs, "", tc.tests)
})
Expand Down
2 changes: 1 addition & 1 deletion v2/chezmoi/targetstatentry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestTargetStateEntryApplyAndEqual(t *testing.T) {
require.NoError(t, err)

// Apply the target state entry.
require.NoError(t, tc1.targetStateEntry.Apply(NewFSDestDir(fs), destStateEntry))
require.NoError(t, tc1.targetStateEntry.Apply(NewFSFileSystem(fs), destStateEntry))

// Verify that the destination state entry matches the
// desired state.
Expand Down

0 comments on commit 2a048f0

Please sign in to comment.