fs

package
v4.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2025 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package fs provides filesystem operations for OpenList

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCopyFailed 复制失败错误
	ErrCopyFailed = errors.New("failed to copy file or directory")

	// ErrSourceNotFound 源对象未找到错误
	ErrSourceNotFound = errors.New("source object not found")

	// ErrStreamCreationFailed 流创建失败错误
	ErrStreamCreationFailed = errors.New("failed to create file stream")

	// ErrOperationCanceled 操作已取消错误
	ErrOperationCanceled = errors.New("operation was canceled")
)

自定义错误类型

View Source
var (
	// ErrStorageNotFound 存储未找到错误
	ErrStorageNotFound = errors.New("storage not found")

	// ErrListFailed 列表获取失败错误
	ErrListFailed = errors.New("failed to get object list")
)

自定义错误类型

View Source
var (
	// ErrMakeDirFailed 创建目录失败错误
	ErrMakeDirFailed = errors.New("failed to create directory")

	// ErrMoveFailed 移动失败错误
	ErrMoveFailed = errors.New("failed to move object")

	// ErrRenameFailed 重命名失败错误
	ErrRenameFailed = errors.New("failed to rename object")

	// ErrRemoveFailed 删除失败错误
	ErrRemoveFailed = errors.New("failed to remove object")

	// ErrOtherOperationFailed 其他操作失败错误
	ErrOtherOperationFailed = errors.New("operation failed")
)

自定义错误类型

View Source
var (
	// ErrUploadFailed 上传失败错误
	ErrUploadFailed = errors.New("failed to upload file")

	// ErrTempFileFailed 临时文件创建失败错误
	ErrTempFileFailed = errors.New("failed to create temporary file")
)

自定义错误类型

View Source
var (
	// ErrWalkFailed 遍历失败错误
	ErrWalkFailed = errors.New("failed to walk filesystem")

	// ErrMaxDepthReached 已达到最大深度错误
	ErrMaxDepthReached = errors.New("maximum walk depth reached")
)

自定义错误类型

View Source
var ArchiveContentUploadTaskManager = &archiveContentUploadTaskManagerType{
	Manager: nil,
}

ArchiveContentUploadTaskManager manages archive content upload tasks

View Source
var ArchiveDownloadTaskManager *tache.Manager[*ArchiveDownloadTask]

ArchiveDownloadTaskManager manages asynchronous archive download tasks

View Source
var CopyTaskManager *tache.Manager[*CopyTask]

CopyTaskManager 管理异步复制任务

View Source
var DefaultConfig = Config{
	DriverCacheTTL:    5 * time.Minute,
	ObjectCacheTTL:    30 * time.Second,
	EnableDriverCache: true,
	EnableObjectCache: true,
}

DefaultConfig 默认配置

View Source
var (
	// ErrLinkFailed 链接获取失败错误
	ErrLinkFailed = errors.New("failed to get object link")
)

自定义错误类型

View Source
var (
	// ErrObjectNotFound 对象未找到错误
	ErrObjectNotFound = errors.New("object not found")
)

自定义错误类型

View Source
var MoveTaskManager *tache.Manager[*MoveTask]
View Source
var UploadTaskManager *tache.Manager[*UploadTask]

UploadTaskManager 上传任务管理器

Functions

func ArchiveDecompress

func ArchiveDecompress(ctx context.Context, srcObjPath, dstDirPath string, args model.ArchiveDecompressArgs, lazyCache ...bool) (task.TaskExtensionInfo, error)

ArchiveDecompress 解压归档 参数:

  • ctx: 上下文
  • srcObjPath: 源对象路径
  • dstDirPath: 目标目录路径
  • args: 归档解压参数
  • lazyCache: 是否延迟缓存

返回:

  • task.TaskExtensionInfo: 任务信息
  • error: 错误信息

func ArchiveDriverExtract

func ArchiveDriverExtract(ctx context.Context, path string, args model.ArchiveInnerArgs) (*model.Link, model.Obj, error)

ArchiveDriverExtract 提取归档内容 参数:

  • ctx: 上下文
  • path: 路径
  • args: 归档内部参数

返回:

  • *model.Link: 链接信息
  • model.Obj: 对象信息
  • error: 错误信息

func ArchiveInternalExtract

func ArchiveInternalExtract(ctx context.Context, path string, args model.ArchiveInnerArgs) (io.ReadCloser, int64, error)

ArchiveInternalExtract 内部提取归档内容 参数:

  • ctx: 上下文
  • path: 路径
  • args: 归档内部参数

返回:

  • io.ReadCloser: 读取器
  • int64: 大小
  • error: 错误信息

func ArchiveList

func ArchiveList(ctx context.Context, path string, args model.ArchiveListArgs) ([]model.Obj, error)

ArchiveList 列出归档内容 参数:

  • ctx: 上下文
  • path: 路径
  • args: 归档列表参数

返回:

  • []model.Obj: 对象列表
  • error: 错误信息

func ArchiveMeta

func ArchiveMeta(ctx context.Context, path string, args model.ArchiveMetaArgs) (*model.ArchiveMetaProvider, error)

ArchiveMeta 获取归档元数据 参数:

  • ctx: 上下文
  • path: 路径
  • args: 归档元数据参数

返回:

  • *model.ArchiveMetaProvider: 归档元数据提供者
  • error: 错误信息

func ClearCache added in v4.2.5

func ClearCache()

ClearCache 清除所有缓存

func Copy

func Copy(ctx context.Context, srcObjPath, dstDirPath string, lazyCache ...bool) (task.TaskExtensionInfo, error)

Copy 复制文件或目录 参数:

  • ctx: 上下文
  • srcObjPath: 源对象路径
  • dstDirPath: 目标目录路径
  • lazyCache: 是否延迟缓存

返回:

  • task.TaskExtensionInfo: 任务信息
  • error: 错误信息

func Get

func Get(ctx context.Context, path string, args *GetArgs) (model.Obj, error)

Get 获取指定路径的对象 参数:

  • ctx: 上下文
  • path: 路径
  • args: 获取参数

返回:

  • model.Obj: 对象信息
  • error: 错误信息

func GetStorage

func GetStorage(path string, args *GetStoragesArgs) (driver.Driver, error)

GetStorage 获取存储驱动 参数:

  • path: 路径
  • args: 获取存储参数

返回:

  • driver.Driver: 存储驱动
  • error: 错误信息
func Link(ctx context.Context, path string, args model.LinkArgs) (*model.Link, model.Obj, error)

Link 获取指定路径对象的链接 参数:

  • ctx: 上下文
  • path: 路径
  • args: 链接参数

返回:

  • *model.Link: 链接信息
  • model.Obj: 对象信息
  • error: 错误信息

func List

func List(ctx context.Context, path string, args *ListArgs) ([]model.Obj, error)

List 列出指定路径下的对象 参数:

  • ctx: 上下文
  • path: 路径
  • args: 列表参数

返回:

  • []model.Obj: 对象列表
  • error: 错误信息

func MakeDir

func MakeDir(ctx context.Context, path string, lazyCache ...bool) error

MakeDir 创建目录 参数:

  • ctx: 上下文
  • path: 目录路径
  • lazyCache: 是否延迟缓存

返回:

  • error: 错误信息

func Move

func Move(ctx context.Context, srcPath, dstDirPath string, lazyCache ...bool) error

Move 移动文件或目录 参数:

  • ctx: 上下文
  • srcPath: 源路径
  • dstDirPath: 目标目录路径
  • lazyCache: 是否延迟缓存

返回:

  • error: 错误信息

func MoveWithTask

func MoveWithTask(ctx context.Context, srcPath, dstDirPath string, lazyCache ...bool) (task.TaskExtensionInfo, error)

MoveWithTask 创建移动任务 参数:

  • ctx: 上下文
  • srcPath: 源路径
  • dstDirPath: 目标目录路径
  • lazyCache: 是否延迟缓存

返回:

  • task.TaskExtensionInfo: 任务信息
  • error: 错误信息

func MoveWithTaskAndValidation

func MoveWithTaskAndValidation(ctx context.Context, srcPath, dstDirPath string, validateExistence bool, lazyCache ...bool) (task.TaskExtensionInfo, error)

MoveWithTaskAndValidation 创建带验证的移动任务 参数:

  • ctx: 上下文
  • srcPath: 源路径
  • dstDirPath: 目标目录路径
  • validateExistence: 是否验证目标存在性
  • lazyCache: 是否延迟缓存

返回:

  • task.TaskExtensionInfo: 任务信息
  • error: 错误信息

func Other

func Other(ctx context.Context, args model.FsOtherArgs) (any, error)

Other 执行其他文件系统操作 参数:

  • ctx: 上下文
  • args: 其他操作参数

返回:

  • any: 操作结果
  • error: 错误信息

func PutAsTask

func PutAsTask(ctx context.Context, dstDirPath string, file model.FileStreamer) (task.TaskExtensionInfo, error)

PutAsTask 创建上传任务 参数:

  • ctx: 上下文
  • dstDirPath: 目标目录路径
  • file: 文件流

返回:

  • task.TaskExtensionInfo: 任务信息
  • error: 错误信息

func PutDirectly

func PutDirectly(ctx context.Context, dstDirPath string, file model.FileStreamer, lazyCache ...bool) error

PutDirectly 直接上传文件 参数:

  • ctx: 上下文
  • dstDirPath: 目标目录路径
  • file: 文件流
  • lazyCache: 是否延迟缓存

返回:

  • error: 错误信息

func PutURL

func PutURL(ctx context.Context, path, dstName, urlStr string) error

PutURL 从URL上传文件 参数:

  • ctx: 上下文
  • path: 路径
  • dstName: 目标名称
  • urlStr: URL字符串

返回:

  • error: 错误信息

func Remove

func Remove(ctx context.Context, path string) error

Remove 删除文件或目录 参数:

  • ctx: 上下文
  • path: 路径

返回:

  • error: 错误信息

func Rename

func Rename(ctx context.Context, srcPath, dstName string, lazyCache ...bool) error

Rename 重命名文件或目录 参数:

  • ctx: 上下文
  • srcPath: 源路径
  • dstName: 新名称
  • lazyCache: 是否延迟缓存

返回:

  • error: 错误信息

func SetConfig added in v4.2.5

func SetConfig(config Config)

SetConfig 设置文件系统配置

func WalkFS

func WalkFS(ctx context.Context, depth int, name string, info model.Obj, walkFn func(reqPath string, info model.Obj) error) error

WalkFS traverses filesystem fs starting at name up to depth levels.

WalkFS will stop when current depth > `depth`. For each visited node, WalkFS calls walkFn. If a visited file system node is a directory and walkFn returns path.SkipDir, walkFS will skip traversal of this node.

参数:

  • ctx: 上下文
  • depth: 最大遍历深度
  • name: 起始路径
  • info: 起始对象信息
  • walkFn: 遍历回调函数

返回:

  • error: 错误信息

Types

type ArchiveContentUploadTask

type ArchiveContentUploadTask struct {
	task.TaskExtension

	ObjName    string // Object name
	InPlace    bool   // Whether to upload in place or in a new directory
	FilePath   string // Path to the file or directory to upload
	DstDirPath string // Destination directory path

	DstStorageMp string // Destination storage mount path
	// contains filtered or unexported fields
}

ArchiveContentUploadTask represents a task for uploading decompressed archive content

func (*ArchiveContentUploadTask) Cancel

func (t *ArchiveContentUploadTask) Cancel()

Cancel cancels the task and cleans up resources if allowed

func (*ArchiveContentUploadTask) GetName

func (t *ArchiveContentUploadTask) GetName() string

GetName returns a human-readable name for the archive content upload task

func (*ArchiveContentUploadTask) GetStatus

func (t *ArchiveContentUploadTask) GetStatus() string

GetStatus returns the current status of the archive content upload task

func (*ArchiveContentUploadTask) Run

Run executes the archive content upload task

func (*ArchiveContentUploadTask) RunWithNextTaskCallback

func (t *ArchiveContentUploadTask) RunWithNextTaskCallback(nextTaskCallback func(nextTask *ArchiveContentUploadTask) error) error

RunWithNextTaskCallback executes the upload task with a custom callback for handling subtasks

type ArchiveDownloadTask

type ArchiveDownloadTask struct {
	task.TaskExtension
	model.ArchiveDecompressArgs

	SrcObjPath string // Source object path
	DstDirPath string // Destination directory path

	SrcStorageMp string // Source storage mount path
	DstStorageMp string // Destination storage mount path
	// contains filtered or unexported fields
}

ArchiveDownloadTask represents a task for downloading and decompressing archive files

func (*ArchiveDownloadTask) GetName

func (t *ArchiveDownloadTask) GetName() string

GetName returns a human-readable name for the archive download task

func (*ArchiveDownloadTask) GetStatus

func (t *ArchiveDownloadTask) GetStatus() string

GetStatus returns the current status of the archive download task

func (*ArchiveDownloadTask) Run

func (t *ArchiveDownloadTask) Run() error

Run executes the archive download task

func (*ArchiveDownloadTask) RunWithoutPushUploadTask

func (t *ArchiveDownloadTask) RunWithoutPushUploadTask() (*ArchiveContentUploadTask, error)

RunWithoutPushUploadTask performs the decompression without adding the resulting upload task to the manager Returns the upload task for the extracted content

type Config added in v4.2.5

type Config struct {
	// 驱动缓存TTL
	DriverCacheTTL time.Duration

	// 对象缓存TTL
	ObjectCacheTTL time.Duration

	// 是否启用驱动缓存
	EnableDriverCache bool

	// 是否启用对象缓存
	EnableObjectCache bool
}

Config 配置选项

func GetConfig added in v4.2.5

func GetConfig() Config

GetConfig 获取当前配置

type CopyTask

type CopyTask struct {
	task.TaskExtension
	Status       string // 当前状态
	SrcObjPath   string // 源对象路径
	DstDirPath   string // 目标目录路径
	SrcStorageMp string // 源存储挂载路径
	DstStorageMp string // 目标存储挂载路径
	// contains filtered or unexported fields
}

CopyTask 表示异步文件/目录复制操作

func (*CopyTask) GetName

func (t *CopyTask) GetName() string

GetName 返回复制任务的可读名称

func (*CopyTask) GetStatus

func (t *CopyTask) GetStatus() string

GetStatus 返回复制任务的当前状态

func (*CopyTask) Run

func (t *CopyTask) Run() error

Run 执行复制任务 初始化存储驱动(如果需要)并委托给copyBetween2Storages

type GetArgs

type GetArgs struct {
	NoLog   bool // 是否不记录日志
	Refresh bool // 是否刷新缓存
}

GetArgs 获取参数结构体

type GetStoragesArgs

type GetStoragesArgs struct {
	Refresh bool // 是否刷新缓存
}

GetStoragesArgs 获取存储参数结构体

type ListArgs

type ListArgs struct {
	Refresh bool // 是否刷新缓存
	NoLog   bool // 是否不记录日志
}

ListArgs 列表参数结构体

type MoveProgress

type MoveProgress struct {
	TaskID         string `json:"task_id"`
	Phase          string `json:"phase"`
	TotalFiles     int    `json:"total_files"`
	CompletedFiles int    `json:"completed_files"`
	CurrentFile    string `json:"current_file"`
	Status         string `json:"status"`
	Progress       int    `json:"progress"`
}

func GetMoveProgress

func GetMoveProgress(taskID string) (*MoveProgress, bool)

GetMoveProgress returns the progress of a move task by task ID

func GetMoveTaskProgress

func GetMoveTaskProgress(task *MoveTask) *MoveProgress

GetMoveTaskProgress returns the progress of a specific move task

type MoveTask

type MoveTask struct {
	task.TaskExtension
	Status     string `json:"-"`
	SrcObjPath string `json:"src_path"`
	DstDirPath string `json:"dst_path"`

	SrcStorageMp      string `json:"src_storage_mp"`
	DstStorageMp      string `json:"dst_storage_mp"`
	IsRootTask        bool   `json:"is_root_task"`
	RootTaskID        string `json:"root_task_id"`
	TotalFiles        int    `json:"total_files"`
	CompletedFiles    int    `json:"completed_files"`
	Phase             string `json:"phase"` // "copying", "verifying", "deleting", "completed"
	ValidateExistence bool   `json:"validate_existence"`
	// contains filtered or unexported fields
}

func (*MoveTask) GetMoveProgress

func (t *MoveTask) GetMoveProgress() *MoveProgress

func (*MoveTask) GetName

func (t *MoveTask) GetName() string

func (*MoveTask) GetProgress

func (t *MoveTask) GetProgress() float64

func (*MoveTask) GetStatus

func (t *MoveTask) GetStatus() string

func (*MoveTask) Run

func (t *MoveTask) Run() error

type UploadTask

type UploadTask struct {
	task.TaskExtension
	// contains filtered or unexported fields
}

UploadTask 上传任务结构体

func (*UploadTask) GetName

func (t *UploadTask) GetName() string

GetName 获取任务名称

func (*UploadTask) GetStatus

func (t *UploadTask) GetStatus() string

GetStatus 获取任务状态

func (*UploadTask) Run

func (t *UploadTask) Run() error

Run 执行上传任务

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL