Documentation ¶
Index ¶
- Constants
- Variables
- func AfterOperationCB() cbFunc
- func BeforeOperationCB() cbCtxFunc
- func IsDir(ctx context.Context, fs FileSystem, name string) (bool, error)
- func RemoveEmptyDirs(ctx context.Context, fs FileSystem, logger logrus.FieldLogger, ...) (int, error)
- func SetAfterOperationCB(f cbFunc)
- func SetBeforeOperationCB(f cbCtxFunc)
- type DirEntry
- type EmptySubtreeCleaner
- type File
- type FileInfo
- type FileNameData
- type FileSystem
- type FilesInfo
- type Local
- func (l *Local) Base(name string) string
- func (l *Local) Create(ctx context.Context, name string) (f File, err error)
- func (l *Local) Dir(name string) string
- func (l *Local) Exists(ctx context.Context, name string) (e bool, err error)
- func (l *Local) Ext(name string) string
- func (l *Local) IsEmptyPath(ctx context.Context, name string) (e bool, err error)
- func (l *Local) IsNotExist(err error) bool
- func (l *Local) Join(names ...string) string
- func (l *Local) MakePathAll(ctx context.Context, name string) (err error)
- func (l *Local) Open(ctx context.Context, name string) (f File, err error)
- func (l *Local) OpenW(ctx context.Context, name string) (f File, err error)
- func (l *Local) PreparePath(ctx context.Context, name string) (absolutePath string, err error)
- func (l *Local) ReadDir(ctx context.Context, name string) (fi FilesInfo, err error)
- func (l *Local) ReadFile(ctx context.Context, name string) (b []byte, err error)
- func (l *Local) Reader(ctx context.Context, name string) (r io.ReadCloser, err error)
- func (l *Local) Remove(ctx context.Context, name string) (err error)
- func (l *Local) RemoveAll(ctx context.Context, name string) (err error)
- func (l *Local) RemoveFiles(ctx context.Context, names []string) (failed []string, err error)
- func (l *Local) Rename(ctx context.Context, from, to string) (err error)
- func (l *Local) Stat(ctx context.Context, name string) (fi FileInfo, err error)
- func (l *Local) WalkDir(ctx context.Context, root string, walkDirFunc WalkDirFunc) (err error)
- func (l *Local) WriteFile(ctx context.Context, name string, data []byte) (err error)
- func (l *Local) WriteFiles(ctx context.Context, f []FileNameData) (err error)
- type LocalDirEntry
- type LocalFileInfo
- func (s LocalFileInfo) FS() FileSystem
- func (s LocalFileInfo) FullName() string
- func (s LocalFileInfo) IsDir() bool
- func (s LocalFileInfo) ModTime() time.Time
- func (s LocalFileInfo) Mode() fs.FileMode
- func (s LocalFileInfo) Name() string
- func (s LocalFileInfo) Size() int64
- func (s LocalFileInfo) Sys() interface{}
- type Node
- type S3
- func (s *S3) Base(name string) string
- func (s *S3) Count(ctx context.Context, name string, recursive bool, ...) (c int64, err error)
- func (s *S3) Create(ctx context.Context, name string) (f File, err error)
- func (s *S3) Dir(name string) string
- func (s *S3) Exists(ctx context.Context, name string) (e bool, err error)
- func (s *S3) Ext(name string) string
- func (s *S3) IsEmptyPath(ctx context.Context, name string) (e bool, err error)
- func (s *S3) IsNotExist(err error) bool
- func (s *S3) Join(paths ...string) string
- func (s *S3) Logger() logrus.FieldLogger
- func (s *S3) MakePathAll(ctx context.Context, name string) (err error)
- func (s *S3) MinioClient() *minio.Client
- func (s *S3) Open(ctx context.Context, name string) (f File, err error)
- func (s *S3) OpenW(ctx context.Context, name string) (f File, err error)
- func (s *S3) OpenedFilesList() *S3OpenedFilesList
- func (s *S3) OpenedFilesListLock()
- func (s *S3) OpenedFilesListUnlock()
- func (s *S3) PreparePath(ctx context.Context, name string) (_ string, err error)
- func (s *S3) ReadDir(ctx context.Context, name string) (fi FilesInfo, err error)
- func (s *S3) ReadFile(ctx context.Context, name string) (b []byte, err error)
- func (s *S3) Reader(ctx context.Context, name string) (r io.ReadCloser, err error)
- func (s *S3) Remove(ctx context.Context, name string) (err error)
- func (s *S3) RemoveAll(ctx context.Context, name string) (err error)
- func (s *S3) RemoveFiles(ctx context.Context, names []string) (failed []string, err error)
- func (s *S3) Rename(ctx context.Context, from string, to string) (err error)
- func (s *S3) SetListDirectoryEntries(v bool)
- func (s *S3) Stat(ctx context.Context, name string) (fi FileInfo, err error)
- func (s *S3) TempFileName(name string) string
- func (s *S3) WalkDir(ctx context.Context, name string, walkDirFunc WalkDirFunc) (err error)
- func (s *S3) WriteFile(ctx context.Context, name string, b []byte) (err error)
- func (s *S3) WriteFiles(ctx context.Context, f []FileNameData) (err error)
- type S3DirEntry
- type S3FileInfo
- type S3OpenedFile
- func (of *S3OpenedFile) Close() error
- func (of *S3OpenedFile) LocalName() string
- func (of *S3OpenedFile) Name() string
- func (of *S3OpenedFile) Read(bytes []byte) (int, error)
- func (of *S3OpenedFile) ReadAt(p []byte, off int64) (n int, err error)
- func (of *S3OpenedFile) Seek(offset int64, whence int) (int64, error)
- func (of *S3OpenedFile) SetUnderlying(f File)
- func (of *S3OpenedFile) Stat() (fs.FileInfo, error)
- func (of *S3OpenedFile) Sync() error
- func (of *S3OpenedFile) Truncate(size int64) error
- func (of *S3OpenedFile) Underlying() File
- func (of *S3OpenedFile) Write(p []byte) (n int, err error)
- type S3OpenedFilesList
- type S3OpenedFilesListEntry
- type S3Params
- type WalkDirFunc
Constants ¶
const ( AlgoDFS = "DFS" AlgoBFS = "BFS" )
const ( DirStubFileName = ".dir" // name of stub file to imitate empty folder DirStubFileContent = "!" // content of stub file to imitate empty folder TempDir = "tmp" )
constants regarding stubs and directories
Variables ¶
var ( ErrCantOpenS3Directory = errors.New("can't open S3 directory") ErrDirectoryNotEmpty = errors.New("directory not empty") ErrDestinationPathIsNotDirectory = errors.New("destination path is not directory while source is") ErrCantUseRenameWithStubObject = errors.New("can't use rename with stub object") ErrRenamingNonExistentDirectory = errors.New("can't rename non-existent directory") ErrNotADirectory = errors.New("given path is not a directory") ErrDirectoryNotExists = errors.New("directory not exists") ErrUnknownFileMode = errors.New("unknown file mode") ErrFileAlreadyOpened = errors.New("file already opened") )
errors
var ErrSkipDir = fs.SkipDir
ErrSkipDir should be returned from WalkDirFunc to skip walking inside directory
Functions ¶
func AfterOperationCB ¶ added in v1.1.0
func AfterOperationCB() cbFunc
AfterOperationCB returns callback that will be invoked after each operation
func BeforeOperationCB ¶ added in v1.1.0
func BeforeOperationCB() cbCtxFunc
BeforeOperationCB returns callback that will be invoked before each operation
func RemoveEmptyDirs ¶ added in v1.1.14
func RemoveEmptyDirs(ctx context.Context, fs FileSystem, logger logrus.FieldLogger, basePath, algo string) (int, error)
RemoveEmptyDirs removed all subtrees of directories inside basePath which contains only empty directories recursively
func SetAfterOperationCB ¶ added in v1.1.0
func SetAfterOperationCB(f cbFunc)
SetAfterOperationCB sets callback that will be invoked after each operation
func SetBeforeOperationCB ¶ added in v1.1.0
func SetBeforeOperationCB(f cbCtxFunc)
SetBeforeOperationCB sets callback that will be invoked before each operation
Types ¶
type EmptySubtreeCleaner ¶ added in v1.1.14
type EmptySubtreeCleaner struct { FS FileSystem Count int Logger logrus.FieldLogger // contains filtered or unexported fields }
EmptySubtreeCleaner removes empty directories subtrees
type File ¶
type File interface { fs.File io.ReaderAt io.Writer io.Seeker Truncate(int64) error Sync() error Name() string }
File abstracts a file
type FileInfo ¶
type FileInfo interface { fs.FileInfo FS() FileSystem FullName() string }
FileInfo abstracts file information
type FileNameData ¶ added in v1.0.10
FileNameData represents file name and data
type FileSystem ¶
type FileSystem interface { Create(context.Context, string) (File, error) Open(context.Context, string) (File, error) OpenW(context.Context, string) (File, error) ReadFile(context.Context, string) ([]byte, error) WriteFile(context.Context, string, []byte) error WriteFiles(context.Context, []FileNameData) error Reader(context.Context, string) (io.ReadCloser, error) Exists(context.Context, string) (bool, error) MakePathAll(context.Context, string) error Remove(context.Context, string) error RemoveFiles(context.Context, []string) ([]string, error) RemoveAll(context.Context, string) error IsNotExist(error) bool IsEmptyPath(context.Context, string) (bool, error) PreparePath(context.Context, string) (string, error) Rename(context.Context, string, string) error Stat(context.Context, string) (FileInfo, error) ReadDir(context.Context, string) (FilesInfo, error) WalkDir(context.Context, string, WalkDirFunc) error Join(...string) string Dir(string) string Ext(string) string Base(string) string }
FileSystem abstracts a file system
type Local ¶
type Local struct{}
Local implements FileSystem. The implementation is not concurrent-safe
func (*Local) IsEmptyPath ¶
IsEmptyPath returns whether given name is empty (does not contain any subpaths)
func (*Local) IsNotExist ¶
IsNotExist returns whether err is a "file not exists" error
func (*Local) MakePathAll ¶
MakePathAll makes name recursively
func (*Local) PreparePath ¶
PreparePath constructs an absolute name from. If it does not exists, creates it.
func (*Local) RemoveFiles ¶ added in v1.0.13
RemoveFiles files given
func (*Local) WriteFiles ¶ added in v1.0.10
func (l *Local) WriteFiles(ctx context.Context, f []FileNameData) (err error)
WriteFiles by the data given
type LocalDirEntry ¶ added in v1.0.7
type LocalDirEntry struct {
// contains filtered or unexported fields
}
LocalDirEntry implements DirEntry
func (LocalDirEntry) FullName ¶ added in v1.0.7
func (s LocalDirEntry) FullName() string
FullName makes LocalDirEntry to implement DirEntry. Returns full name of the underlying FileInfo object
func (LocalDirEntry) Info ¶ added in v1.0.7
func (s LocalDirEntry) Info() (fs.FileInfo, error)
Info makes LocalDirEntry to implement DirEntry. It returns the underlying FileInfo object
func (LocalDirEntry) IsDir ¶ added in v1.0.7
func (s LocalDirEntry) IsDir() bool
IsDir makes LocalDirEntry to implement DirEntry. It calls IsDir() of the underlying FileInfo object
func (LocalDirEntry) Name ¶ added in v1.0.7
func (s LocalDirEntry) Name() string
Name makes LocalDirEntry to implement DirEntry. Returns name of the underlying FileInfo object
func (LocalDirEntry) Type ¶ added in v1.0.7
func (s LocalDirEntry) Type() fs.FileMode
Type makes LocalDirEntry to implement DirEntry. It calls Mode() of the underlying FileInfo object
type LocalFileInfo ¶ added in v1.0.7
type LocalFileInfo struct {
// contains filtered or unexported fields
}
LocalFileInfo implements FileInfo
func NewLocalFileInfo ¶ added in v1.0.7
func NewLocalFileInfo(fs *Local, fi os.FileInfo, fullName string) LocalFileInfo
NewLocalFileInfo returns new LocalFileInfo object
func (LocalFileInfo) FS ¶ added in v1.2.1
func (s LocalFileInfo) FS() FileSystem
FS makes LocalFileInfo to implement FileInfo
func (LocalFileInfo) FullName ¶ added in v1.0.7
func (s LocalFileInfo) FullName() string
FullName makes LocalFileInfo to implement FileInfo
func (LocalFileInfo) IsDir ¶ added in v1.0.7
func (s LocalFileInfo) IsDir() bool
IsDir makes LocalFileInfo to implement FileInfo
func (LocalFileInfo) ModTime ¶ added in v1.0.7
func (s LocalFileInfo) ModTime() time.Time
ModTime makes LocalFileInfo to implement FileInfo
func (LocalFileInfo) Mode ¶ added in v1.0.7
func (s LocalFileInfo) Mode() fs.FileMode
Mode makes LocalFileInfo to implement FileInfo
func (LocalFileInfo) Name ¶ added in v1.0.7
func (s LocalFileInfo) Name() string
Name makes LocalFileInfo to implement FileInfo
func (LocalFileInfo) Size ¶ added in v1.0.7
func (s LocalFileInfo) Size() int64
Size makes LocalFileInfo to implement FileInfo
func (LocalFileInfo) Sys ¶ added in v1.0.7
func (s LocalFileInfo) Sys() interface{}
Sys makes LocalFileInfo to implement FileInfo
type S3 ¶
type S3 struct {
// contains filtered or unexported fields
}
S3 implements FileSystem. The implementation is not concurrent-safe
func (*S3) Count ¶
func (s *S3) Count(ctx context.Context, name string, recursive bool, countFunc func(oi minio.ObjectInfo, num int64) (proceed bool, e error)) (c int64, err error)
Count returns count of items in a folder. May count in childs also if recursive param set to true.
func (*S3) Create ¶ added in v1.0.2
Create file with given name in the client's bucket. A file will be created locally for reading, writing, truncating. To remove the actual local file and write out into S3 object it should be properly closed by calling Close() on the caller's side. Calls to Open, Create, OpenW and S3OpenedFile.Close are concurrent-safe and mutually locking.
func (*S3) IsEmptyPath ¶
IsEmptyPath works according to the MakePathAll implementation. Returns true only if specified path contains only a dir stub file.
func (*S3) IsNotExist ¶
IsNotExist returns whether err is an 'bucket not exists' error or 'object not exists' error
func (*S3) MakePathAll ¶
MakePathAll does nothing in S3 FileSystem. As a workaround to make sure that we have a precreated folder, we create a small file in it. refer to: https://github.com/minio/minio/issues/3555, https://github.com/minio/minio/issues/2423
func (*S3) MinioClient ¶
func (s *S3) MinioClient() *minio.Client
MinioClient provides access to Minio Client, use mainly for tests
func (*S3) Open ¶
Open file with given name in the client's bucket. An object will be downloaded from S3 storage and opened as a local file for reading. To remove the actual local file and write out into S3 object it should be properly closed by calling Close() on the caller's side. Calls to Open, Create, OpenW and S3OpenedFile.Close are concurrent-safe and mutually locking.
func (*S3) OpenW ¶ added in v1.0.4
OpenW opens file in the FileSystem for writing. An object will be downloaded from S3 storage and opened as a local file for writing. To remove the actual local file and write out into S3 object it should be properly closed by calling Close() on the caller's side. Calls to Open, Create, OpenW and S3OpenedFile.Close are concurrent-safe and mutually locking.
func (*S3) OpenedFilesList ¶
func (s *S3) OpenedFilesList() *S3OpenedFilesList
OpenedFilesList provides access to opened files list, use mainly for tests
func (*S3) OpenedFilesListLock ¶
func (s *S3) OpenedFilesListLock()
OpenedFilesListLock locks opened files list associated mutex, use mainly for tests
func (*S3) OpenedFilesListUnlock ¶
func (s *S3) OpenedFilesListUnlock()
OpenedFilesListUnlock unlocks opened files list associated mutex, use mainly for tests
func (*S3) PreparePath ¶
PreparePath works according to the MakePathAll implementation.
func (*S3) Remove ¶
Remove object by the given name. Returns no error even if object does not exists
func (*S3) RemoveFiles ¶ added in v1.0.13
RemoveFiles removes multiple objects in batch by the given names. Returns no error even if any object does not exists
func (*S3) SetListDirectoryEntries ¶
SetListDirectoryEntries or unset it, use mainly for tests
func (*S3) TempFileName ¶ added in v1.0.5
TempFileName converts file name to a temporary file name
func (*S3) WriteFiles ¶ added in v1.0.10
func (s *S3) WriteFiles(ctx context.Context, f []FileNameData) (err error)
WriteFiles by the data given. An archive will be created by the underlying minio client
type S3DirEntry ¶
type S3DirEntry struct {
// contains filtered or unexported fields
}
S3DirEntry implements DirEntry
func (S3DirEntry) FullName ¶ added in v1.0.7
func (s S3DirEntry) FullName() string
FullName makes S3DirEntry to implement DirEntry. Returns full name of the underlying FileInfo object
func (S3DirEntry) Info ¶
func (s S3DirEntry) Info() (fs.FileInfo, error)
Info makes S3DirEntry to implement DirEntry. It returns the underlying FileInfo object
func (S3DirEntry) IsDir ¶
func (s S3DirEntry) IsDir() bool
IsDir makes S3DirEntry to implement DirEntry. It calls IsDir() of the underlying FileInfo object
func (S3DirEntry) Name ¶
func (s S3DirEntry) Name() string
Name makes S3DirEntry to implement DirEntry. Returns name of the underlying FileInfo object
func (S3DirEntry) Type ¶
func (s S3DirEntry) Type() fs.FileMode
Type makes S3DirEntry to implement DirEntry. It calls Mode() of the underlying FileInfo object
type S3FileInfo ¶
type S3FileInfo struct {
// contains filtered or unexported fields
}
S3FileInfo implements FileInfo
func NewS3FileInfo ¶ added in v1.0.1
func NewS3FileInfo(fs *S3, oi minio.ObjectInfo) S3FileInfo
NewS3FileInfo returns new S3FileInfo object
func NewS3FileInfoStub ¶ added in v1.0.1
func NewS3FileInfoStub(fs *S3, key string, modTime time.Time) S3FileInfo
NewS3FileInfoStub returns new stub S3FileInfo object
func (S3FileInfo) FS ¶ added in v1.2.1
func (s S3FileInfo) FS() FileSystem
FS makes S3FileInfo to implement FileInfo. Returns same as Sys() method, but an interface.
func (S3FileInfo) FullName ¶ added in v1.0.7
func (s S3FileInfo) FullName() string
FullName makes S3FileInfo to implement FileInfo. Returns last part (file name) of the key of S3 object
func (S3FileInfo) IsDir ¶
func (s S3FileInfo) IsDir() bool
IsDir makes S3FileInfo to implement FileInfo. It returns whether an object key ends in '/' (and it's size is 0)
func (S3FileInfo) ModTime ¶
func (s S3FileInfo) ModTime() time.Time
ModTime makes S3FileInfo to implement FileInfo. Returns last modified time
func (S3FileInfo) Mode ¶
func (s S3FileInfo) Mode() fs.FileMode
Mode makes S3FileInfo to implement FileInfo. It always returns 0
func (S3FileInfo) Name ¶
func (s S3FileInfo) Name() string
Name makes S3FileInfo to implement FileInfo. Returns last part (file name) of the key of S3 object
func (S3FileInfo) Size ¶
func (s S3FileInfo) Size() int64
Size makes S3FileInfo to implement FileInfo. Returns size of S3 object
func (S3FileInfo) Sys ¶
func (s S3FileInfo) Sys() interface{}
Sys makes S3FileInfo to implement FileInfo. It returns a value of type *S3: a pointer to the underlying FileSystem-implementing object
type S3OpenedFile ¶
type S3OpenedFile struct {
// contains filtered or unexported fields
}
S3OpenedFile implements a wrapper around File
func (*S3OpenedFile) Close ¶
func (of *S3OpenedFile) Close() error
Close makes S3OpenedFile to implement File. It closed the underlying File and removes it from local file system.
func (*S3OpenedFile) LocalName ¶ added in v1.0.5
func (of *S3OpenedFile) LocalName() string
LocalName returns local file name
func (*S3OpenedFile) Read ¶
func (of *S3OpenedFile) Read(bytes []byte) (int, error)
Read makes S3OpenedFile to implement File
func (*S3OpenedFile) ReadAt ¶
func (of *S3OpenedFile) ReadAt(p []byte, off int64) (n int, err error)
ReadAt makes S3OpenedFile to implement File
func (*S3OpenedFile) Seek ¶
func (of *S3OpenedFile) Seek(offset int64, whence int) (int64, error)
Seek makes S3OpenedFile to implement File
func (*S3OpenedFile) SetUnderlying ¶ added in v1.0.5
func (of *S3OpenedFile) SetUnderlying(f File)
SetUnderlying file
func (*S3OpenedFile) Stat ¶
func (of *S3OpenedFile) Stat() (fs.FileInfo, error)
Stat makes S3OpenedFile to implement File
func (*S3OpenedFile) Sync ¶
func (of *S3OpenedFile) Sync() error
Sync makes S3OpenedFile to implement File
func (*S3OpenedFile) Truncate ¶
func (of *S3OpenedFile) Truncate(size int64) error
Truncate makes S3OpenedFile to implement File
func (*S3OpenedFile) Underlying ¶ added in v1.0.5
func (of *S3OpenedFile) Underlying() File
Underlying returns an underlying file
type S3OpenedFilesList ¶
S3OpenedFilesList represents S3 opened files list
func NewS3OpenedFilesList ¶
func NewS3OpenedFilesList() *S3OpenedFilesList
NewS3OpenedFilesList returns a pointer to new S3 opened files list instance
func (*S3OpenedFilesList) AddAndLockEntry ¶ added in v1.0.5
func (ofl *S3OpenedFilesList) AddAndLockEntry(localFileName string, entry *S3OpenedFilesListEntry)
AddAndLockEntry adds an entry to the list and locks it
func (*S3OpenedFilesList) DeleteAndUnlockEntry ¶ added in v1.0.5
func (ofl *S3OpenedFilesList) DeleteAndUnlockEntry(localFileName string)
DeleteAndUnlockEntry deletes and unlocks an entry from the list if it exists
func (*S3OpenedFilesList) Len ¶ added in v1.0.5
func (ofl *S3OpenedFilesList) Len() int
Len returns length of list
func (*S3OpenedFilesList) Map ¶
func (ofl *S3OpenedFilesList) Map() map[string]*S3OpenedFilesListEntry
Map returns opened file list underlying map
type S3OpenedFilesListEntry ¶
type S3OpenedFilesListEntry struct { Added time.Time S3File *S3OpenedFile // contains filtered or unexported fields }
S3OpenedFilesListEntry is an walkDirEntry of opened files list
func (*S3OpenedFilesListEntry) Lock ¶ added in v1.0.5
func (ofle *S3OpenedFilesListEntry) Lock()
Lock or RLock the entry according to S3File Open mode
func (*S3OpenedFilesListEntry) Unlock ¶ added in v1.0.5
func (ofle *S3OpenedFilesListEntry) Unlock()
Unlock or RUnlock the entry according to S3File Open mode
type S3Params ¶
type S3Params struct { Endpoint string Region string AccessKey string SecretKey string UseSSL bool BucketName string OpenedFilesTTL time.Duration OpenedFilesTempDir string Logger logrus.FieldLogger EmulateEmptyDirs bool // without this directory modification time will not be available ListDirectoryEntries bool // in the ReadDir output }
S3Params are parameters for S3 filesystem client