Documentation ¶
Overview ¶
Package filesystem provides a file system abstraction and types describing potential changes to a file system.
Index ¶
- Constants
- func ApplyEdits(es *text.EditSet, fs FileSystem, filename string) ([]byte, error)
- func CreatePatch(es *text.EditSet, fs FileSystem, filename string) (*text.Patch, error)
- func FakeStdinPath() (string, error)
- type EditedFileSystem
- func (fs *EditedFileSystem) CreateDirectory(path string) error
- func (fs *EditedFileSystem) CreateFile(path, contents string) error
- func (fs *EditedFileSystem) OpenFile(path string) (io.ReadCloser, error)
- func (fs *EditedFileSystem) OverwriteFile(path string) (io.WriteCloser, error)
- func (fs *EditedFileSystem) ReadDir(dirPath string) ([]os.FileInfo, error)
- func (fs *EditedFileSystem) Remove(path string) error
- func (fs *EditedFileSystem) Rename(path, newName string) error
- type FileSystem
- type LocalFileSystem
- func (fs *LocalFileSystem) CreateFile(path, contents string) error
- func (fs *LocalFileSystem) OpenFile(path string) (io.ReadCloser, error)
- func (fs *LocalFileSystem) OverwriteFile(path string) (io.WriteCloser, error)
- func (fs *LocalFileSystem) ReadDir(path string) ([]os.FileInfo, error)
- func (fs *LocalFileSystem) Remove(path string) error
- func (fs *LocalFileSystem) Rename(oldPath, newName string) error
Constants ¶
const FakeStdinFilename = "-.go"
The filename assigned to Go source code supplied on standard input. It is assumed that a file with this name does not actually exist.
This peculiar choice of names is due to the fact that go/loader requires source files to have a .go filename extension, so using a more obvious name like "-" or even os.DevNull or os.Stdin.Name does not currently work.
An EditedFileSystem can "pretend" that a file with this name exists in the current directory; the absolute path to this file is returned by FakeStdinPath.
Variables ¶
This section is empty.
Functions ¶
func ApplyEdits ¶
ApplyEdits reads bytes from a file, applying the edits in an EditSet and returning the result as a slice of bytes.
func CreatePatch ¶
CreatePatch reads bytes from a file, applying the edits in an EditSet and returning a Patch.
func FakeStdinPath ¶
FakeStdinPath returns the absolute path of a (likely nonexistent) file in the current directory whose name is given by FakeStdinFilename.
Types ¶
type EditedFileSystem ¶
type EditedFileSystem struct { BaseFS FileSystem Edits map[string]*text.EditSet }
EditedFileSystem implements the FileSystem interface and provides access to a hypothetical version of the local file system after a refactoring's changes have been applied. This can be supplied to go/loader to analyze a program after refactoring, without actually changing the program on disk. File/directory creation, renaming, and deletion are not currently supported.
func NewEditedFileSystem ¶
func NewEditedFileSystem(base FileSystem, edits map[string]*text.EditSet) *EditedFileSystem
func NewSingleEditedFileSystem ¶
func NewSingleEditedFileSystem(filename, contents string) (*EditedFileSystem, error)
func (*EditedFileSystem) CreateDirectory ¶
func (fs *EditedFileSystem) CreateDirectory(path string) error
func (*EditedFileSystem) CreateFile ¶
func (fs *EditedFileSystem) CreateFile(path, contents string) error
func (*EditedFileSystem) OpenFile ¶
func (fs *EditedFileSystem) OpenFile(path string) (io.ReadCloser, error)
func (*EditedFileSystem) OverwriteFile ¶
func (fs *EditedFileSystem) OverwriteFile(path string) (io.WriteCloser, error)
func (*EditedFileSystem) ReadDir ¶
func (fs *EditedFileSystem) ReadDir(dirPath string) ([]os.FileInfo, error)
func (*EditedFileSystem) Remove ¶
func (fs *EditedFileSystem) Remove(path string) error
func (*EditedFileSystem) Rename ¶
func (fs *EditedFileSystem) Rename(path, newName string) error
type FileSystem ¶
type FileSystem interface { // ReadDir returns a slice of os.FileInfo, sorted by Name, // describing the content of the named directory. ReadDir(dir string) ([]os.FileInfo, error) // OpenFile opens a file (not a directory) for reading. OpenFile(path string) (io.ReadCloser, error) // OverwriteFile opens a file for writing. It is an error if the // file does not already exist. OverwriteFile(path string) (io.WriteCloser, error) // CreateFile creates a text file with the given contents and default // permissions. CreateFile(path, contents string) error // Rename changes the name of a file or directory. newName should be a // bare name, not including a directory prefix; the existing file will // be renamed within its existing parent directory. Rename(path, newName string) error // Remove deletes a file or an empty directory. Remove(path string) error }
A FileSystem provides the ability to read directories and files, as well as to create, rename, and remove files (if the file system is not read-only).
type LocalFileSystem ¶
type LocalFileSystem struct{}
LocalFileSystem implements the FileSystem interface and provides access to the local file system by delegating to the os and io/ioutil packages.
func NewLocalFileSystem ¶
func NewLocalFileSystem() *LocalFileSystem
func (*LocalFileSystem) CreateFile ¶
func (fs *LocalFileSystem) CreateFile(path, contents string) error
func (*LocalFileSystem) OpenFile ¶
func (fs *LocalFileSystem) OpenFile(path string) (io.ReadCloser, error)
func (*LocalFileSystem) OverwriteFile ¶
func (fs *LocalFileSystem) OverwriteFile(path string) (io.WriteCloser, error)
func (*LocalFileSystem) ReadDir ¶
func (fs *LocalFileSystem) ReadDir(path string) ([]os.FileInfo, error)
func (*LocalFileSystem) Remove ¶
func (fs *LocalFileSystem) Remove(path string) error
func (*LocalFileSystem) Rename ¶
func (fs *LocalFileSystem) Rename(oldPath, newName string) error