2022-07-13 06:30:54 +00:00
|
|
|
package file
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io/fs"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PathFilter provides a filter function for paths.
|
|
|
|
type PathFilter interface {
|
|
|
|
Accept(ctx context.Context, path string, info fs.FileInfo) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type PathFilterFunc func(path string) bool
|
|
|
|
|
|
|
|
func (pff PathFilterFunc) Accept(path string) bool {
|
|
|
|
return pff(path)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter provides a filter function for Files.
|
|
|
|
type Filter interface {
|
2022-07-18 00:51:59 +00:00
|
|
|
Accept(ctx context.Context, f File) bool
|
2022-07-13 06:30:54 +00:00
|
|
|
}
|
|
|
|
|
2022-07-18 00:51:59 +00:00
|
|
|
type FilterFunc func(ctx context.Context, f File) bool
|
2022-07-13 06:30:54 +00:00
|
|
|
|
2022-07-18 00:51:59 +00:00
|
|
|
func (ff FilterFunc) Accept(ctx context.Context, f File) bool {
|
|
|
|
return ff(ctx, f)
|
2022-07-13 06:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handler provides a handler for Files.
|
|
|
|
type Handler interface {
|
|
|
|
Handle(ctx context.Context, f File) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// FilteredHandler is a Handler runs only if the filter accepts the file.
|
|
|
|
type FilteredHandler struct {
|
|
|
|
Handler
|
|
|
|
Filter
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle runs the handler if the filter accepts the file.
|
|
|
|
func (h *FilteredHandler) Handle(ctx context.Context, f File) error {
|
2022-07-18 00:51:59 +00:00
|
|
|
if h.Accept(ctx, f) {
|
2022-07-13 06:30:54 +00:00
|
|
|
return h.Handler.Handle(ctx, f)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CleanHandler provides a handler for cleaning Files and Folders.
|
|
|
|
type CleanHandler interface {
|
|
|
|
HandleFile(ctx context.Context, fileDeleter *Deleter, fileID ID) error
|
|
|
|
HandleFolder(ctx context.Context, fileDeleter *Deleter, folderID FolderID) error
|
|
|
|
}
|