fs

package
v4.2.10 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: AGPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const MaxSeedGenerateSyncSize = 1 * 1024 * 1024 * 1024

MaxSeedGenerateSyncSize bounds synchronous seed generation (1GB). Larger requests are turned into an asynchronous task.

Variables

View Source
var (
	CopyTaskManager *tache.Manager[*FileTransferTask]
	MoveTaskManager *tache.Manager[*FileTransferTask]
)
View Source
var ArchiveContentUploadTaskManager = &archiveContentUploadTaskManagerType{
	Manager: nil,
}
View Source
var ArchiveDownloadTaskManager *tache.Manager[*ArchiveDownloadTask]
View Source
var SeedGenerateTaskManager *tache.Manager[*SeedGenerateTask]
View Source
var SeedSaveTaskManager *tache.Manager[*SeedSaveTask]
View Source
var UploadTaskManager *tache.Manager[*UploadTask]

Functions

func AcquireSeedHashSlot added in v4.2.10

func AcquireSeedHashSlot(ctx context.Context) (func(), error)

AcquireSeedHashSlot limits simultaneous file-hashing operations across seed APIs.

func AddSeedGenerateTask added in v4.2.8

func AddSeedGenerateTask(ctx context.Context, user *model.User, params SeedGenerateParams) (task.TaskExtensionInfo, error)

AddSeedGenerateTask schedules an asynchronous seed generation task.

func ArchiveDecompress

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

func ArchiveDriverExtract

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

func ArchiveInternalExtract

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

func ArchiveList

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

func Copy

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

func CopyTo added in v4.2.8

func CopyTo(ctx context.Context, srcObjPath, dstDirPath, dstName string, skipHook ...bool) (task.TaskExtensionInfo, error)

CopyTo copies a file or directory to dstDirPath using dstName as its name.

func DeriveSeedName added in v4.2.8

func DeriveSeedName(paths []string) string

DeriveSeedName 给出默认种子名:

  • 只选了一个文件/目录:用它的名字(文件去掉扩展名);
  • 选了多个(合并成一个种子):固定用 "torrent"。

后者是刻意的:多选往往来自不同目录,按「公共父目录」猜名字容易得到 空串或毫无意义的目录名,不如给一个稳定的默认值,让用户自己改。

func EncodeGeneratedSeed added in v4.2.8

func EncodeGeneratedSeed(seed *torrent.Seed, format string, standardPieces []byte) ([]byte, error)

EncodeGeneratedSeed serializes a seed in the requested container format.

func Get

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

func GetDirectUploadInfo added in v4.1.7

func GetDirectUploadInfo(ctx context.Context, tool, path, dstName string, fileSize int64, overwrite bool) (any, error)

func GetStorage

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

func IsSeedContainerName added in v4.2.10

func IsSeedContainerName(name string) bool

IsSeedContainerName reports whether name is a transfer-seed container (.oss/.torrent/.cas/.cas.torrent) rather than real content.

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

func List

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

func MakeDir

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

func Merge added in v4.1.8

func Merge(ctx context.Context, srcObjPath, dstDirPath string, skipHook ...bool) (task.TaskExtensionInfo, error)

func Move

func Move(ctx context.Context, srcPath, dstDirPath string, skipHook ...bool) (task.TaskExtensionInfo, error)

func NormalizeSeedFormats added in v4.2.8

func NormalizeSeedFormats(rawFormats []string) ([]string, error)

NormalizeSeedFormats validates and deduplicates a list of seed format names.

func Other

func Other(ctx context.Context, args model.FsOtherArgs) (interface{}, error)

func PutAsTask

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

func PutDirectly

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

func PutURL

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

func RehashSeedFromFiles added in v4.2.10

func RehashSeedFromFiles(
	ctx context.Context,
	user *model.User,
	seed *torrent.Seed,
	basePath string,
	targetFormat string,
) ([]byte, error)

RehashSeedFromFiles 读取 basePath 下的实际文件,补全目标格式所需的哈希。

返回目标为 torrent 时的「整包」SHA-1 pieces:标准 torrent 的 pieces 是 所有文件首尾相接后按 piece 切分的,跨文件边界不能按文件单独切, 所以必须整包读一遍(这也是转换时提示 piece boundary crosses the next file 的原因)。

func RehashSeedFromFilesWithMatrix added in v4.2.10

func RehashSeedFromFilesWithMatrix(
	ctx context.Context,
	user *model.User,
	seed *torrent.Seed,
	basePath string,
	targetFormat string,
	matrix SeedHashMatrix,
) ([]byte, error)

RehashSeedFromFilesWithMatrix adds requested hashes and the target format's required hashes.

func Remove

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

func Rename

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

func SeedGenerateNeedsAsync added in v4.2.8

func SeedGenerateNeedsAsync(ctx context.Context, user *model.User, paths []string) (bool, error)

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.

Types

type ArchiveContentUploadTask

type ArchiveContentUploadTask struct {
	task.TaskExtension

	ObjName       string
	InPlace       bool
	FilePath      string
	DstActualPath string

	DstStorageMp string
	// contains filtered or unexported fields
}

func (*ArchiveContentUploadTask) Cancel

func (t *ArchiveContentUploadTask) Cancel()

func (*ArchiveContentUploadTask) GetName

func (t *ArchiveContentUploadTask) GetName() string

func (*ArchiveContentUploadTask) GetStatus

func (t *ArchiveContentUploadTask) GetStatus() string

func (*ArchiveContentUploadTask) OnFailed added in v4.0.9

func (t *ArchiveContentUploadTask) OnFailed()

func (*ArchiveContentUploadTask) OnSucceeded added in v4.0.9

func (t *ArchiveContentUploadTask) OnSucceeded()

func (*ArchiveContentUploadTask) Run

func (*ArchiveContentUploadTask) RunWithNextTaskCallback

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

func (*ArchiveContentUploadTask) SetRetry added in v4.0.9

func (t *ArchiveContentUploadTask) SetRetry(retry int, maxRetry int)

type ArchiveDownloadTask

type ArchiveDownloadTask struct {
	TaskData
	model.ArchiveDecompressArgs
}

func (*ArchiveDownloadTask) GetName

func (t *ArchiveDownloadTask) GetName() string

func (*ArchiveDownloadTask) Run

func (t *ArchiveDownloadTask) Run() error

func (*ArchiveDownloadTask) RunWithoutPushUploadTask

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

type FileTransferTask added in v4.0.9

type FileTransferTask struct {
	TaskData
	TaskType taskType
	// contains filtered or unexported fields
}

func (*FileTransferTask) GetName added in v4.0.9

func (t *FileTransferTask) GetName() string

func (*FileTransferTask) OnFailed added in v4.0.9

func (t *FileTransferTask) OnFailed()

func (*FileTransferTask) OnSucceeded added in v4.0.9

func (t *FileTransferTask) OnSucceeded()

func (*FileTransferTask) Run added in v4.0.9

func (t *FileTransferTask) Run() error

func (*FileTransferTask) RunWithNextTaskCallback added in v4.1.0

func (t *FileTransferTask) RunWithNextTaskCallback(f func(nextTask *FileTransferTask) error) error

func (*FileTransferTask) SetRetry added in v4.0.9

func (t *FileTransferTask) SetRetry(retry int, maxRetry int)

type GetArgs

type GetArgs struct {
	NoLog              bool
	WithStorageDetails bool
}

type GetStoragesArgs

type GetStoragesArgs struct {
}

type ListArgs

type ListArgs struct {
	Refresh            bool
	NoLog              bool
	WithStorageDetails bool
}

type SeedArtifact added in v4.2.8

type SeedArtifact struct {
	Format   string `json:"format"`
	Name     string `json:"name"`
	FileName string `json:"file_name"`
	SeedData string `json:"seed_data"`
	Size     int    `json:"size"`
	Path     string `json:"path,omitempty"`
}

SeedArtifact is one generated seed container.

func GenerateSeedArtifacts added in v4.2.8

func GenerateSeedArtifacts(ctx context.Context, user *model.User, params SeedGenerateParams) ([]SeedArtifact, *torrent.Seed, error)

GenerateSeedArtifacts reads each file once while computing the requested hashes, then emits one or more seed containers. It has no HTTP dependency and can be driven synchronously or from a background task.

目录会先递归展开;params.Split 为 true 时每个文件单独一个种子, 否则全部合并成一个(默认)。

type SeedGenerateParams added in v4.2.8

type SeedGenerateParams struct {
	Paths               []string
	Formats             []string
	Name                string
	Comment             string
	FileComments        map[string]string
	HashMatrix          SeedHashMatrix
	PieceSize           int64
	Trackers            []string
	Channels            []torrent.SeedChannel
	OutputPath          string
	IncludeShare        bool
	IncludeDirectSource bool
	ShareFiles          []string
	DirectFiles         []string

	// PreserveStructure 目录展开后是否保留目录结构;默认 false(拍平成文件名)。
	PreserveStructure bool
	// Split 为 true 时每个文件生成一个种子;默认 false(全部合并成一个)。
	Split bool

	// OnProgress 可选:读取文件计算哈希时回调 (已读字节, 总字节),用于任务进度展示。
	OnProgress func(read, total int64)
	// OnStage 可选:进入新阶段时回调,用于展示「正在计算哈希 2/5」这类状态文案。
	OnStage func(stage string)
}

SeedGenerateParams carries a fully-resolved seed generation request, free of any HTTP transport concerns so it can run synchronously or as a task.

type SeedGenerateTask added in v4.2.8

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

SeedGenerateTask generates seed containers asynchronously, writing them into params.OutputPath so they appear in the target folder once done.

func (*SeedGenerateTask) GetName added in v4.2.8

func (t *SeedGenerateTask) GetName() string

func (*SeedGenerateTask) GetStatus added in v4.2.8

func (t *SeedGenerateTask) GetStatus() string

func (*SeedGenerateTask) Run added in v4.2.8

func (t *SeedGenerateTask) Run() error

type SeedHashMatrix added in v4.2.8

type SeedHashMatrix struct {
	MD5    SeedHashSelection `json:"md5"`
	SHA1   SeedHashSelection `json:"sha1"`
	SHA256 SeedHashSelection `json:"sha256"`
}

SeedHashMatrix controls the optional hash metadata stored in a seed.

type SeedHashSelection added in v4.2.8

type SeedHashSelection struct {
	Whole  bool `json:"whole"`
	Pieces bool `json:"pieces"`
}

SeedHashSelection controls whole-file and piece hash inclusion.

type SeedSaveTask added in v4.2.10

type SeedSaveTask struct {
	task.TaskExtension
	Title string
	// contains filtered or unexported fields
}

SeedSaveTask 是「种子秒传 / 中转保存」这类同步操作的进度载体。

这些操作本身仍然是同步的(HTTP 请求内完成,响应里带逐文件结果),但用户 希望在任务列表里看到进度,所以这里额外注册一个任务对象:由调用方在循环里 推进度,完成后写入最终状态。

注意:该 manager 以 Running=false 创建,worker 不会调度任务;Add 之前先把 状态置为 Succeeded,是为了让 tache 不把任务放进执行队列(队列没有消费者, 会一直堆积)。Add 之后立刻改回 Running,任务就变成「只展示、不执行」。

func NewSeedSaveTask added in v4.2.10

func NewSeedSaveTask(ctx context.Context, user *model.User, title string) *SeedSaveTask

NewSeedSaveTask 注册一个可见的种子保存任务并返回它。 调用方负责在执行过程中调用 Report,结束时调用 Finish。

func (*SeedSaveTask) Finish added in v4.2.10

func (t *SeedSaveTask) Finish(err error)

Finish 结束任务:成功后进度置 100,失败时记录错误,取消则保留「已取消」

func (*SeedSaveTask) GetName added in v4.2.10

func (t *SeedSaveTask) GetName() string

func (*SeedSaveTask) GetStatus added in v4.2.10

func (t *SeedSaveTask) GetStatus() string

func (*SeedSaveTask) Report added in v4.2.10

func (t *SeedSaveTask) Report(index, total int, name, action string)

Report 记录「第 index/total 个文件」的进度

func (*SeedSaveTask) Run added in v4.2.10

func (t *SeedSaveTask) Run() error

Run 不会被调度执行(见类型注释),保留实现以满足 tache.Task 接口。

func (*SeedSaveTask) SetStatus added in v4.2.10

func (t *SeedSaveTask) SetStatus(status string)

SetStatus 更新任务列表里显示的阶段文案

type SeedSourceEntry added in v4.2.10

type SeedSourceEntry struct {
	// Requested 用户视角路径:目录展开出来的文件为「目录/相对路径」,
	// 用于和 file_comments / share_files / direct_files 对应。
	Requested string
	// FullPath 完整 VFS 路径(已包含用户 base path)。
	FullPath string
	// SeedPath 种子内路径:保留结构时为相对 root 的路径,否则是纯文件名。
	SeedPath string
	Size     int64
	Modified string
	Obj      model.Obj
}

SeedSourceEntry 是展开目录后真正要打包进种子的一个文件。

func ExpandSeedSources added in v4.2.10

func ExpandSeedSources(ctx context.Context, user *model.User, paths []string, preserve bool) ([]SeedSourceEntry, error)

ExpandSeedSources 把用户选择的路径展开成待打包文件列表。

目录会被递归展开(含所有子目录里的文件);preserve 决定种子内是否保留 目录结构:true 时按「相对公共父目录」的路径写入,false 时拍平成文件名, 重名文件会自动加序号,避免 torrent 内路径冲突。

type TaskData added in v4.0.9

type TaskData struct {
	task.TaskExtension
	Status        string        `json:"-"` //don't save status to save space
	SrcActualPath string        `json:"src_path"`
	DstActualPath string        `json:"dst_path"`
	DstName       string        `json:"dst_name,omitempty"`
	SrcStorage    driver.Driver `json:"-"`
	DstStorage    driver.Driver `json:"-"`
	SrcStorageMp  string        `json:"src_storage_mp"`
	DstStorageMp  string        `json:"dst_storage_mp"`
}

func (*TaskData) GetStatus added in v4.0.9

func (t *TaskData) GetStatus() string

type UploadTask

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

func (*UploadTask) GetName

func (t *UploadTask) GetName() string

func (*UploadTask) GetStatus

func (t *UploadTask) GetStatus() string

func (*UploadTask) OnFailed added in v4.0.9

func (t *UploadTask) OnFailed()

func (*UploadTask) OnSucceeded added in v4.0.9

func (t *UploadTask) OnSucceeded()

func (*UploadTask) Run

func (t *UploadTask) Run() error

func (*UploadTask) SetRetry added in v4.0.9

func (t *UploadTask) SetRetry(retry int, maxRetry int)

Jump to

Keyboard shortcuts

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