godoctor: github.com/godoctor/godoctor/filesystem Index | Files

package filesystem

import "github.com/godoctor/godoctor/filesystem"

Package filesystem provides a file system abstraction and types describing potential changes to a file system.

Index

Package Files

filesystem.go

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.

func ApplyEdits Uses

func ApplyEdits(es *text.EditSet, fs FileSystem, filename string) ([]byte, error)

ApplyEdits reads bytes from a file, applying the edits in an EditSet and returning the result as a slice of bytes.

func CreatePatch Uses

func CreatePatch(es *text.EditSet, fs FileSystem, filename string) (*text.Patch, error)

CreatePatch reads bytes from a file, applying the edits in an EditSet and returning a Patch.

func FakeStdinPath Uses

func FakeStdinPath() (string, error)

FakeStdinPath returns the absolute path of a (likely nonexistent) file in the current directory whose name is given by FakeStdinFilename.

type EditedFileSystem Uses

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 Uses

func NewEditedFileSystem(base FileSystem, edits map[string]*text.EditSet) *EditedFileSystem

func NewSingleEditedFileSystem Uses

func NewSingleEditedFileSystem(filename, contents string) (*EditedFileSystem, error)

func (*EditedFileSystem) CreateDirectory Uses

func (fs *EditedFileSystem) CreateDirectory(path string) error

func (*EditedFileSystem) CreateFile Uses

func (fs *EditedFileSystem) CreateFile(path, contents string) error

func (*EditedFileSystem) OpenFile Uses

func (fs *EditedFileSystem) OpenFile(path string) (io.ReadCloser, error)

func (*EditedFileSystem) OverwriteFile Uses

func (fs *EditedFileSystem) OverwriteFile(path string) (io.WriteCloser, error)

func (*EditedFileSystem) ReadDir Uses

func (fs *EditedFileSystem) ReadDir(dirPath string) ([]os.FileInfo, error)

func (*EditedFileSystem) Remove Uses

func (fs *EditedFileSystem) Remove(path string) error

func (*EditedFileSystem) Rename Uses

func (fs *EditedFileSystem) Rename(path, newName string) error

type FileSystem Uses

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 Uses

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 Uses

func NewLocalFileSystem() *LocalFileSystem

func (*LocalFileSystem) CreateFile Uses

func (fs *LocalFileSystem) CreateFile(path, contents string) error

func (*LocalFileSystem) OpenFile Uses

func (fs *LocalFileSystem) OpenFile(path string) (io.ReadCloser, error)

func (*LocalFileSystem) OverwriteFile Uses

func (fs *LocalFileSystem) OverwriteFile(path string) (io.WriteCloser, error)

func (*LocalFileSystem) ReadDir Uses

func (fs *LocalFileSystem) ReadDir(path string) ([]os.FileInfo, error)

func (*LocalFileSystem) Remove Uses

func (fs *LocalFileSystem) Remove(path string) error

func (*LocalFileSystem) Rename Uses

func (fs *LocalFileSystem) Rename(oldPath, newName string) error

Package filesystem imports 9 packages (graph) and is imported by 4 packages. Updated 2016-07-30. Refresh now. Tools for package owners.