Documentation ¶
Overview ¶
Package remotefs provides fs.FS implementations for remote filesystems.
Index ¶
- Constants
- Variables
- func PathError(op, path string, err error) *fs.PathError
- func PathErrorf(op, path string, template string, args ...any) *fs.PathError
- func Upload(fs FS, src, dst string) error
- type Copier
- type FS
- type File
- type FileInfo
- func (f *FileInfo) FullPath() string
- func (f *FileInfo) Info() (fs.FileInfo, error)
- func (f *FileInfo) IsDir() bool
- func (f *FileInfo) ModTime() time.Time
- func (f *FileInfo) Mode() fs.FileMode
- func (f *FileInfo) Name() string
- func (f *FileInfo) Size() int64
- func (f *FileInfo) Sys() any
- func (f *FileInfo) Type() fs.FileMode
- func (f *FileInfo) UnmarshalJSON(b []byte) error
- type OS
- type Opener
- type PosixDir
- type PosixFS
- func (s *PosixFS) Chmod(name string, mode fs.FileMode) error
- func (s *PosixFS) Chown(name string, uid, gid int) error
- func (s *PosixFS) Chtimes(name string, atime, mtime int64) error
- func (s *PosixFS) FileExist(name string) bool
- func (s *PosixFS) Getenv(key string) string
- func (s *PosixFS) Hostname() (string, error)
- func (s *PosixFS) Join(elem ...string) string
- func (s *PosixFS) LongHostname() (string, error)
- func (s *PosixFS) LookPath(name string) (string, error)
- func (s *PosixFS) Mkdir(name string, perm fs.FileMode) error
- func (s *PosixFS) MkdirAll(name string, perm fs.FileMode) error
- func (s *PosixFS) MkdirTemp(dir, prefix string) (string, error)
- func (s *PosixFS) Open(name string) (fs.File, error)
- func (s *PosixFS) OpenFile(name string, flags int, perm fs.FileMode) (File, error)
- func (s *PosixFS) ReadDir(name string) ([]fs.DirEntry, error)
- func (s *PosixFS) ReadFile(filename string) ([]byte, error)
- func (s *PosixFS) Remove(name string) error
- func (s *PosixFS) RemoveAll(name string) error
- func (s *PosixFS) Rename(oldpath, newpath string) error
- func (s *PosixFS) Sha256(name string) (string, error)
- func (s *PosixFS) Stat(name string) (fs.FileInfo, error)
- func (s *PosixFS) TempDir() string
- func (s *PosixFS) Touch(name string) error
- func (s *PosixFS) Truncate(name string, size int64) error
- func (s *PosixFS) UserCacheDir() string
- func (s *PosixFS) UserConfigDir() string
- func (s *PosixFS) UserHomeDir() string
- func (s *PosixFS) WriteFile(filename string, data []byte, perm fs.FileMode) error
- type PosixFile
- func (f *PosixFile) Close() error
- func (f *PosixFile) CopyFrom(src io.Reader) (int64, error)
- func (f *PosixFile) CopyTo(dst io.Writer) (int64, error)
- func (w *PosixFile) Name() string
- func (f *PosixFile) Read(p []byte) (int, error)
- func (f *PosixFile) Seek(offset int64, whence int) (int64, error)
- func (f *PosixFile) Stat() (fs.FileInfo, error)
- func (f *PosixFile) Write(p []byte) (int, error)
- type Provider
- type RemoteFSProvider
- type Service
- type Sha256summer
- type WinFS
- func (s *WinFS) Chmod(name string, mode fs.FileMode) error
- func (s *WinFS) Chown(name string, _, _ int) error
- func (s *WinFS) Chtimes(name string, atime, mtime int64) error
- func (s *WinFS) FileExist(name string) bool
- func (s *WinFS) Getenv(key string) string
- func (s *WinFS) Hostname() (string, error)
- func (s *WinFS) Join(elem ...string) string
- func (s *WinFS) LongHostname() (string, error)
- func (s *WinFS) LookPath(name string) (string, error)
- func (s *WinFS) Mkdir(name string, _ fs.FileMode) error
- func (s *WinFS) MkdirAll(name string, _ fs.FileMode) error
- func (s *WinFS) MkdirTemp(dir, prefix string) (string, error)
- func (s *WinFS) Open(name string) (fs.File, error)
- func (s *WinFS) OpenFile(name string, flags int, _ fs.FileMode) (File, error)
- func (s *WinFS) ReadDir(name string) ([]fs.DirEntry, error)
- func (s *WinFS) ReadFile(name string) ([]byte, error)
- func (s *WinFS) Remove(name string) error
- func (s *WinFS) RemoveAll(name string) error
- func (s *WinFS) Rename(oldpath, newpath string) error
- func (s *WinFS) Sha256(name string) (string, error)
- func (s *WinFS) Stat(name string) (fs.FileInfo, error)
- func (s *WinFS) TempDir() string
- func (s *WinFS) Touch(name string) error
- func (s *WinFS) Truncate(name string, size int64) error
- func (s *WinFS) UserCacheDir() string
- func (s *WinFS) UserConfigDir() string
- func (s *WinFS) UserHomeDir() string
- func (s *WinFS) WriteFile(name string, data []byte, mode fs.FileMode) error
Constants ¶
const ( OpClose = "close" // OpClose Close operation OpOpen = "open" // OpOpen Open operation OpRead = "read" // OpRead Read operation OpSeek = "seek" // OpSeek Seek operation OpStat = "stat" // OpStat Stat operation OpWrite = "write" // OpWrite Write operation OpCopyTo = "copy-to" // OpCopyTo CopyTo operation OpCopyFrom = "copy-from" // OpCopyFrom CopyFrom operation )
Variables ¶
var DefaultProvider = sync.OnceValue(NewProvider)
DefaultProvider is the default Repository for remote filesystem implementations.
var ErrChecksumMismatch = errors.New("checksum mismatch")
ErrChecksumMismatch is returned when the checksum of the uploaded file does not match the local checksum.
var ( // ErrNotSupported is returned when a function is not supported on Windows. ErrNotSupported = errors.New("not supported on windows") )
Functions ¶
func PathErrorf ¶
PathErrorf returns a fs.PathError with the given operation, path and error created using a sprintf style format string and arguments.
Types ¶
type Copier ¶
type Copier interface { CopyFrom(src io.Reader) (int64, error) CopyTo(dst io.Writer) (int64, error) }
Copier is a file-like struct that can copy data to and from io.Reader and io.Writer.
type File ¶
File is a file in the remote filesystem.
func CreateTemp ¶
CreateTemp creates a new temporary file in the directory dir with a name built using the pattern, opens the file for reading and writing, and returns the resulting File. If dir is the empty string, CreateTemp uses the default directory for temporary files.
type FileInfo ¶
type FileInfo struct { FName string `json:"name"` FSize int64 `json:"size"` FMode fs.FileMode `json:"mode"` FUnix fs.FileMode `json:"unixMode"` FModTime time.Time `json:"-"` FIsDir bool `json:"isDir"` ModtimeS int64 `json:"modTime"` // contains filtered or unexported fields }
FileInfo implements fs.FileInfo for stat on remote files.
func (*FileInfo) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type OS ¶
type OS interface { Remove(path string) error RemoveAll(path string) error Mkdir(path string, perm fs.FileMode) error MkdirAll(path string, perm fs.FileMode) error MkdirTemp(dir, prefix string) (string, error) WriteFile(path string, data []byte, perm fs.FileMode) error FileExist(path string) bool LookPath(cmd string) (string, error) Join(elem ...string) string Chmod(path string, mode fs.FileMode) error Chown(path string, uid, gid int) error Chtimes(path string, atime, mtime int64) error Touch(path string) error Truncate(path string, size int64) error Getenv(key string) string Rename(oldpath, newpath string) error Hostname() (string, error) LongHostname() (string, error) TempDir() string UserCacheDir() string UserConfigDir() string UserHomeDir() string }
OS is a os/filesystem utility interface, these operations are modeled after stdlib's OS package.
type PosixDir ¶
type PosixDir struct { PosixFile // contains filtered or unexported fields }
PosixDir implements fs.ReadDirFile for a remote directory.
type PosixFS ¶
type PosixFS struct { cmd.Runner log.LoggerInjectable // contains filtered or unexported fields }
PosixFS implements fs.FS for a remote filesystem that uses POSIX commands for access.
func NewPosixFS ¶
NewPosixFS returns a fs.FS implementation for a remote filesystem that uses POSIX commands for access.
func (*PosixFS) Join ¶
Join joins any number of path elements into a single path, adding a separating slash if necessary.
func (*PosixFS) LongHostname ¶
LongHostname returns the FQDN of the host.
func (*PosixFS) MkdirAll ¶
MkdirAll creates a new directory structure with the specified name and permission bits. If the directory already exists, MkDirAll does nothing and returns nil.
func (*PosixFS) MkdirTemp ¶
MkdirTemp creates a new temporary directory in the directory dir with a name beginning with prefix and returns the path of the new directory.
func (*PosixFS) OpenFile ¶
OpenFile is used to open a file with access/creation flags for reading or writing. For info on flags, see https://pkg.go.dev/os#pkg-constants
func (*PosixFS) ReadDir ¶
ReadDir reads the directory named by dirname and returns a list of directory entries.
func (*PosixFS) Touch ¶
Touch creates a new empty file at path or updates the timestamp of an existing file to the current time.
func (*PosixFS) Truncate ¶
Truncate changes the size of the named file or creates a new file if it doesn't exist.
func (*PosixFS) UserCacheDir ¶
UserCacheDir returns the default root directory to use for user-specific cached data.
func (*PosixFS) UserConfigDir ¶
UserConfigDir returns the default root directory to use for user-specific configuration data.
func (*PosixFS) UserHomeDir ¶
UserHomeDir returns the current user's home directory.
type PosixFile ¶
type PosixFile struct {
// contains filtered or unexported fields
}
PosixFile implements fs.File for a remote file.
func (*PosixFile) Close ¶
Close closes the file, rendering it unusable for I/O. It returns an error, if any.
func (*PosixFile) Read ¶
Read reads up to len(p) bytes into p. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered.
func (*PosixFile) Seek ¶
Seek sets the offset for the next Read or Write to offset, interpreted according to whence: io.SeekStart means relative to the origin of the file, io.SeekCurrent means relative to the current offset, and io.SeekEnd means relative to the end. Seek returns the new offset relative to the start of the file and an error, if any.
type RemoteFSProvider ¶
RemoteFSProvider is a factory for remote filesystem implementations.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides a unified interface to interact with the filesystem on a remote host. It ensures that a suitable remotefs.FS implementation is lazily initialized and made available for filesystem operations. It supports operations like opening files and implements io/fs.FS.
func NewRemoteFSService ¶
func NewRemoteFSService(provider RemoteFSProvider, runner cmd.Runner) *Service
NewRemoteFSService creates a new instance of Service with the provided remotefs Provider and runner.
type Sha256summer ¶
Sha256summer implementing struct can calculate sha256 checksum of a file.
type WinFS ¶
type WinFS struct { cmd.Runner log.LoggerInjectable }
WinFS is a fs.FS implemen{.
func NewWindowsFS ¶
NewWindowsFS returns a new fs.FS implementing filesystem for Windows targets.
func (*WinFS) Chmod ¶
Chmod changes the mode of the named file to mode. On Windows, only the 0200 bit (owner writable) of mode is used; it controls whether the file's read-only attribute is set or cleared.
func (*WinFS) Chown ¶
Chown changes the numeric uid and gid of the named file. On windows it returns an error.
func (*WinFS) Chtimes ¶
Chtimes changes the access and modification times of the named file, similar to the Unix utime() or utimes() functions.
func (*WinFS) FileExist ¶
FileExist checks if a file exists on the host. It is a more efficient shortcut for something like:
if _, err := fs.Stat(name); os.IsNotExist(err) { ... } if !fs.FileExist(name) { ... }
func (*WinFS) Join ¶
Join joins any number of path elements into a single path, adding a separating slash if necessary.
func (*WinFS) LongHostname ¶
LongHostname resolves the FQDN (long) hostname.
func (*WinFS) Mkdir ¶
Mkdir creates a new directory with the specified name and permission bits. The permission bits are ignored on Windows.
func (*WinFS) MkdirAll ¶
MkdirAll creates a directory named path, along with any necessary parents. The permission bits are ignored on Windows.
func (*WinFS) MkdirTemp ¶
MkdirTemp creates a new temporary directory in the directory dir with a name beginning with prefix and returns the path of the new directory.
func (*WinFS) Open ¶
Open opens the named file for reading and returns fs.File. Use OpenFile to get a file that can be written to or if you need any of the methods not available on fs.File interface without type assertion.
func (*WinFS) OpenFile ¶
OpenFile opens the named remote file with the specified flags. os.O_EXCL and permission bits are ignored on Windows. For a description of the flags, see https://pkg.go.dev/os#pkg-constants
func (*WinFS) ReadDir ¶
ReadDir reads the directory named by dirname and returns a list of directory entries.
func (*WinFS) Touch ¶
Touch creates a new file with the given name if it does not exist. If the file exists, the access and modification times are set to the current time.
func (*WinFS) UserCacheDir ¶
UserCacheDir returns the default root directory to use for user-specific non-essential data files.
func (*WinFS) UserConfigDir ¶
UserConfigDir returns the default root directory to use for user-specific configuration data.
func (*WinFS) UserHomeDir ¶
UserHomeDir returns the current user's home directory.