Renaming to better name

This commit is contained in:
Francesc Campoy
2021-06-10 09:52:14 -07:00
parent 6b9e8eb891
commit 6a82437bc9
2 changed files with 22 additions and 16 deletions

View File

@@ -50,68 +50,71 @@ type FileSystem interface {
Walk(path string, walkFn filepath.WalkFunc) error
}
// FileSystemWithOnDiskDefault satisfies the FileSystem interface by forwarding
// FileSystemOrOnDisk satisfies the FileSystem interface by forwarding
// all of its method calls to the given FileSystem whenever it's not nil.
// If it's nil, the call is forwarded to the OS's underlying file system.
type FileSystemWithOnDiskDefault struct {
type FileSystemOrOnDisk struct {
FileSystem FileSystem
}
func (fs FileSystemWithOnDiskDefault) fs() FileSystem {
// Set sets the given FileSystem as the target for all the FileSystem method calls.
func (fs *FileSystemOrOnDisk) Set(f FileSystem) { fs.FileSystem = f }
func (fs FileSystemOrOnDisk) fs() FileSystem {
if fs.FileSystem != nil {
return fs.FileSystem
}
return MakeFsOnDisk()
}
func (fs FileSystemWithOnDiskDefault) Create(path string) (File, error) {
func (fs FileSystemOrOnDisk) Create(path string) (File, error) {
return fs.fs().Create(path)
}
func (fs FileSystemWithOnDiskDefault) Mkdir(path string) error {
func (fs FileSystemOrOnDisk) Mkdir(path string) error {
return fs.fs().Mkdir(path)
}
func (fs FileSystemWithOnDiskDefault) MkdirAll(path string) error {
func (fs FileSystemOrOnDisk) MkdirAll(path string) error {
return fs.fs().MkdirAll(path)
}
func (fs FileSystemWithOnDiskDefault) RemoveAll(path string) error {
func (fs FileSystemOrOnDisk) RemoveAll(path string) error {
return fs.fs().RemoveAll(path)
}
func (fs FileSystemWithOnDiskDefault) Open(path string) (File, error) {
func (fs FileSystemOrOnDisk) Open(path string) (File, error) {
return fs.fs().Open(path)
}
func (fs FileSystemWithOnDiskDefault) IsDir(path string) bool {
func (fs FileSystemOrOnDisk) IsDir(path string) bool {
return fs.fs().IsDir(path)
}
func (fs FileSystemWithOnDiskDefault) ReadDir(path string) ([]string, error) {
func (fs FileSystemOrOnDisk) ReadDir(path string) ([]string, error) {
return fs.fs().ReadDir(path)
}
func (fs FileSystemWithOnDiskDefault) CleanedAbs(path string) (ConfirmedDir, string, error) {
func (fs FileSystemOrOnDisk) CleanedAbs(path string) (ConfirmedDir, string, error) {
return fs.fs().CleanedAbs(path)
}
func (fs FileSystemWithOnDiskDefault) Exists(path string) bool {
func (fs FileSystemOrOnDisk) Exists(path string) bool {
return fs.fs().Exists(path)
}
func (fs FileSystemWithOnDiskDefault) Glob(pattern string) ([]string, error) {
func (fs FileSystemOrOnDisk) Glob(pattern string) ([]string, error) {
return fs.fs().Glob(pattern)
}
func (fs FileSystemWithOnDiskDefault) ReadFile(path string) ([]byte, error) {
func (fs FileSystemOrOnDisk) ReadFile(path string) ([]byte, error) {
return fs.fs().ReadFile(path)
}
func (fs FileSystemWithOnDiskDefault) WriteFile(path string, data []byte) error {
func (fs FileSystemOrOnDisk) WriteFile(path string, data []byte) error {
return fs.fs().WriteFile(path, data)
}
func (fs FileSystemWithOnDiskDefault) Walk(path string, walkFn filepath.WalkFunc) error {
func (fs FileSystemOrOnDisk) Walk(path string, walkFn filepath.WalkFunc) error {
return fs.fs().Walk(path, walkFn)
}