dropdir

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dropdir 把拖入的文件写到本机用户的 ~/.handoff/drop/ 收件箱。

职责:

  • 按 basename 落盘,同名加 -2/-3 后缀,不覆盖已有文件
  • 强制 32 MiB 未编码字节上限;超限整次拒绝,不留成品名
  • 先写点开头临时文件再放到目标名,失败即删临时文件

边界:

  • 不认 HTTP、不认 PTY、不认工作树。HOME 由调用方注入,本包不调 os.UserHomeDir
  • 不列目录、不删除用户文件、不清理崩溃残留的点开头临时文件
  • 不把文件内容写进日志

Index

Constants

View Source
const MaxBytes = 32 << 20

MaxBytes 是单文件未编码内容上限(32 MiB)。

Variables

View Source
var (
	// ErrTooLarge 是内容超过 MaxBytes。
	ErrTooLarge = errors.New("文件超过 32 MiB")
	// ErrBadName 是文件名不合法(空、.、..)。
	ErrBadName = errors.New("文件名不合法")
	// ErrNoHome 是调用方没给出 HOME。
	ErrNoHome = errors.New("HOME 为空")
	// ErrNotFile 是调用方声明这不是普通文件(目录等)。
	ErrNotFile = errors.New("不是普通文件")
)

Functions

func Dir

func Dir(home string) string

Dir 返回该 HOME 下的 drop 收件箱路径。

func Put

func Put(home, originalName string, r io.Reader) (string, int64, error)

Put 把 r 的内容写进 home/.handoff/drop/,返回实际绝对路径和写入字节数。

参数:

  • home: 用户主目录(测试注入临时目录;生产由调用方 os.UserHomeDir)
  • originalName: 用户给的文件名,本函数只取 basename
  • r: 文件内容

返回:写成的绝对路径、字节数;失败时路径为空。

Types

This section is empty.

Jump to

Keyboard shortcuts

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