Documentation
¶
Overview ¶
Package fs provides the filesystem interface for managing objects in directories.
Package fs provides the filesystem interface for managing objects in directories.
Index ¶
- func Backend() filer.Backend
- type CreateMode
- type FS
- func (self *FS) Actions() []filer.Action
- func (self *FS) Clone(_ context.Context, patch url.Values) (filer.Filer, error)
- func (self *FS) Close() error
- func (self *FS) CreateObject(ctx context.Context, req schema.CreateObjectRequest) (_ *schema.Object, err error)
- func (self *FS) DeleteObjects(ctx context.Context, req schema.DeleteObjectsRequest) (_ *schema.DeleteObjectsResponse, err error)
- func (self *FS) Description() string
- func (self *FS) GetObject(ctx context.Context, req schema.GetObjectRequest) (_ *schema.Object, err error)
- func (self *FS) ListObjects(ctx context.Context, req schema.ListObjectsRequest) (_ schema.ListObjectsIterator, err error)
- func (self *FS) ReadObject(ctx context.Context, req schema.GetObjectRequest) (_ filer.ReadObjectFunc, _ *schema.Object, err error)
- func (self *FS) Readonly() bool
- func (self *FS) URL() *url.URL
- func (self *FS) WatchObjects(ctx context.Context, ch chan<- schema.Event) error
- type WriterFS
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CreateMode ¶
type CreateMode int
CreateMode is whether a file is created, replaced, or either
const ( CreateOrReplace CreateMode = iota // a file is created, or replaces one which exists CreateOnly // a file which exists isn't replaced ReplaceOnly // a file which doesn't exist isn't created )
type FS ¶
func New ¶
Create a new writable filesystem backend for the named volume, rooted at the directory path, with the options (see opt.go), and the options of a backend, whose tracer traces the operations, when it's set. Files can't be read or written outside the directory.
func NewFS ¶
Create a new filesystem backend for the named volume, with the options (see opt.go), and the options of a backend, whose tracer traces the operations, when it's set. The backend takes ownership of fsys: when it implements io.Closer, it's closed when the backend is closed, so the caller shouldn't close or reuse it afterwards.
func (*FS) Clone ¶
Clone returns a new filesystem of the directory, which is opened again, so it's the directory which is at its path, with the options changed by the patch. Only a filesystem which New created can be cloned, as another owns the filesystem it's backed by, which can restrict what it has, or whether it can be written, even when it has a path.
func (*FS) Close ¶
Close the filesystem, and the filesystem it's backed by, when it can be closed. Requests, and reads in progress, then return fs.ErrClosed. It's safe to call more than once, and while requests are being made.
func (*FS) CreateObject ¶
func (self *FS) CreateObject(ctx context.Context, req schema.CreateObjectRequest) (_ *schema.Object, err error)
Create object in the filesystem, replacing any existing object at the same path. An object cannot be written over a directory, and when IfNotExists is set, cannot be written over an existing object, nor, when IfExists is set, created where there's none. A nil body creates an empty object. The object is replaced atomically, so if writing the body fails, or the context is cancelled, or the filesystem is closed, while it's written, any existing object is left unchanged. When ModTime is set, it is used as the modification time of the object. Metadata is not yet supported, and returns an error.
func (*FS) DeleteObjects ¶
func (self *FS) DeleteObjects(ctx context.Context, req schema.DeleteObjectsRequest) (_ *schema.DeleteObjectsResponse, err error)
Delete an object in the filesystem, and return the deleted objects. A directory is only deleted when the request is recursive, in which case every object beneath it, including hidden files, is deleted too, and a package is deleted as a file, with the files in it. Any parent directories left empty are removed. The root of the volume cannot be deleted.
func (*FS) Description ¶
Description returns what the folder is, such as "Folder /mnt/media"
func (*FS) GetObject ¶
func (self *FS) GetObject(ctx context.Context, req schema.GetObjectRequest) (_ *schema.Object, err error)
Get object metadata from the filesystem. Returns ErrNotModified when the request's conditions say the object hasn't changed: when its ETag is one of IfNoneMatch, or "*" is, or, when IfNoneMatch is empty, when it hasn't been modified since IfModifiedSince, to the second. A directory, which has no modification time, is always returned.
func (*FS) ListObjects ¶
func (self *FS) ListObjects(ctx context.Context, req schema.ListObjectsRequest) (_ schema.ListObjectsIterator, err error)
List objects in the filesystem
func (*FS) ReadObject ¶
func (self *FS) ReadObject(ctx context.Context, req schema.GetObjectRequest) (_ filer.ReadObjectFunc, _ *schema.Object, err error)
Read object content from the filesystem. Returns the object, and a function which reads its content, which opens the file when it's called, so the content is read within it. Directories, and packages, can't be read. The file is checked when it's opened, as it could have changed since the object was returned: when it isn't the same size, or wasn't modified at the same time, it isn't read, and ErrPreconditionFailed is returned.
func (*FS) Readonly ¶
Readonly returns true when objects can't be created or deleted, by the readonly option, or as the filesystem can't be written
func (*FS) URL ¶
URL returns the URL of the filesystem, which a filesystem can be created again from: file://<name>/<path> for a filesystem rooted at a directory, or fs://<name> for one which isn't, with the options which aren't the defaults as its query
func (*FS) WatchObjects ¶
WatchObjects sends each change to the objects in the filesystem to the channel, until the context is cancelled, or the filesystem is closed, when fs.ErrClosed is returned. Changes to files which aren't listed, such as hidden files, aren't sent, and a change within a package is an update to the package. Returns filer.ErrNotImplemented when the filesystem isn't a directory, or can't be watched on this platform.
The first change is a rescan of the root, once the directory is watched, so a change after it is sent. The calls share one watch of the directory, so a second call doesn't watch it again: one which joins a watch which is running is sent its rescan at once. Each is sent each change, and one which falls behind is sent a rescan of the directory, rather than holding up the others.
type WriterFS ¶
type WriterFS interface {
fs.StatFS
// Method to create a file in the filesystem from the body, which also
// creates any necessary parent directories. The file is replaced
// atomically: readers see either the previous file or the complete new
// one, and if writing fails the previous file is left unchanged. With
// CreateOnly, an existing file is not replaced, and an error wrapping
// fs.ErrExist is returned. With ReplaceOnly, a file which doesn't exist
// is not created, and an error wrapping fs.ErrNotExist is returned. When
// modtime is not zero, it is set as the modification time of the file.
// Returns the information for the new file.
Create(path string, body io.Reader, mode CreateMode, modtime time.Time) (fs.FileInfo, error)
// Method to delete a file, or a directory and everything beneath it,
// which also removes any empty parent directories. The root directory
// cannot be deleted.
Delete(path string) error
// Release resources held by the filesystem
io.Closer
}
WriterFS is a filesystem which also allows for creating and deleting files
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package fsevents watches a directory, and everything beneath it, for files and directories which are created, updated and deleted, using the efficient mechanism of each platform: FSEvents on macOS, ReadDirectoryChangesW on Windows, and inotify on Linux.
|
Package fsevents watches a directory, and everything beneath it, for files and directories which are created, updated and deleted, using the efficient mechanism of each platform: FSEvents on macOS, ReadDirectoryChangesW on Windows, and inotify on Linux. |