fileTree

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: MIT Imports: 20 Imported by: 0

README

file-tree

This is a Go library that allows for quick traversal of folders. By inputting a valid file path, you will receive a file tree. Naturally, the final file tree supports output in Json and Yaml formats.


增量快照 & diff(实用★★★★☆ 成本★★★☆☆ 炫技★★★☆☆) 把每次扫描结果写进 bolt/badger 里做“快照”,下次再扫同一路径时直接 diff,输出“新增 / 删除 / 大小变化”列表。 关键词:文件指纹(xxhash64+mtime)、快照 ID、boltdb bucket。 2. 重复文件猎手(实用★★★★★ 成本★★★☆☆ 炫技★★☆☆☆) 用“大小→首512B→全文件 xxHash”三级过滤,把重复项聚合成组,支持交互式或 dry-run 删除/硬链接。 关键词:并发 hash、map[uint64][]string、hardlink syscall。 3. 热图可视化(实用★★★☆☆ 成本★★☆☆☆ 炫技★★★★☆) 扫描完把结果直接吐成 HTML,用 d3.js 画“可缩放旭日图”,颜色按文件类型/大小梯度。 关键词:template/html、embed FS、WebSocket 实时推送进度条。 4. 忽略语法 & .gitignore 兼容(实用★★★★☆ 成本★☆☆☆☆ 炫技☆☆☆☆☆) 把 git 的 glob 解析抄过来(github.com/go-git/go-git/v5/plumbing/gitignore),默认读取 .gitignore,支持 CLI 额外 -i 参数。 关键词:双栈匹配、预编译 glob。 5. 并发复制 / 镜像(实用★★★★☆ 成本★★☆☆☆ 炫技★★☆☆☆) 在现有 walker 基础上加“copier”插件,支持 --mirror src dst,用 go-chans 做生产者-消费者,带进度条、限速、断点续传(记录已复制文件列表)。 关键词:io.CopyBuffer、pb/v3、sparse file detect。 6. 大文件 TopN + 老化策略(实用★★★★☆ 成本★☆☆☆☆ 炫技☆☆☆☆☆) 扫完直接出“最大的 50 个文件”列表,支持 --older-than 30d --delete-dry-run 一键清理老化大文件。 关键词:最小堆、os.Stat、humanize.Time。 7. 插件系统(实用★★★☆☆ 成本★★★★☆ 炫技★★★★★) 用 go-plugin 或 yaegi 做脚本钩子,让用户写 lua/starlight 脚本自定义“文件名→权重”逻辑,实时影响树排序/过滤。 关键词:plugin.Open、reflect、lua.State。 8. 远程扫描 agent(实用★★★☆☆ 成本★★★☆☆ 炫技★★★☆☆) 把 walker 拆成 gRPC service,本地 CLI 只负责展示,agent 跑在 NAS/容器里;内网一次性扫 20 台机器。 关键词:grpc+protobuf、stream、tls mutual。 9. 权限修复助手(实用★★★☆☆ 成本★☆☆☆☆ 炫技☆☆☆☆☆) 扫树时记录 os.FileInfo.Mode(),一键把“其他用户可写”或“无执行位”的目录批量修正成 0755/0644,支持 dry-run。 关键词:unix.Perm、walk symlinks。 10. 交互式 TUI(实用★★★☆☆ 成本★★☆☆☆ 炫技★★★☆☆) 用 charm/bubbletea 写全屏 TUI,左右分栏:左边树,右边实时预览 / hex/文本;支持 vim 键位删除、复制路径到剪贴板。 关键词:bubbletea、lipgloss、clipboard。 11. 一键生成 .tar.zst / .zip(实用★★★☆☆ 成本★☆☆☆☆ 炫技☆☆☆☆☆) 扫完直接把过滤后的树打包,支持 zstd 级别 3,自动把时间戳、权限写回。 关键词:archive/tar、github.com/klauspost/compress/zstd。 12. 文件类型识别(实用★★☆☆☆ 成本★☆☆☆☆ 炫技★★☆☆☆) 不看后缀,读文件头 32 B,用 http.DetectContentType+mimetype 库,输出“真实类型 vs 后缀不符”列表。 关键词:magic number、sync.Pool 复用 buf。 13. 硬链 & 软链图谱(实用★★☆☆☆ 成本★★☆☆☆ 炫技★★☆☆☆) 统计 inode nlink>1 的硬链组,画“同一 inode 文件列表”;软链则检测是否 dangling。 关键词:sys.Stat_t.Ino、map[uint64][]string。 14. 监控模式(实用★★★☆☆ 成本★★★☆☆ 炫技★★☆☆☆) 用 fsnotify 监听根目录,树变动时增量更新内存结构,WebSocket 推给前端热图实时刷新。 关键词:fsnotify.Watcher、debounce、hub。 15. 许可证扫描(实用★★☆☆☆ 成本★☆☆☆☆ 炫技★☆☆☆☆) 遍历 node_modules、vendor,把 LICENSE* 文件摘出来,汇总 GPLv3 / BSD / MIT 计数,生成风险报告。 关键词:filepath.Glob、spdx 标识符映射表。

Documentation

Index

Constants

View Source
const (
	TypeDir = iota
	TypeFile
	TypeLink
)
View Source
const (
	Byte     = 1
	KiloByte = Byte << 10
	MegaByte = KiloByte << 10
	GigaByte = MegaByte << 10
	TeraByte = GigaByte << 10
)
View Source
const VERSION = "0.1.3"

Variables

This section is empty.

Functions

func ByteString

func ByteString(b int64) (res string)

func NewTreeMapHttp added in v0.1.3

func NewTreeMapHttp(addr, tmpPath string)

func PathDepth added in v0.1.2

func PathDepth(path string) int

PathDepth Calculate path depth through delimiter

func StringToByte added in v0.1.2

func StringToByte(s string) (res int, err error)

Types

type CountFile added in v0.1.1

type CountFile struct {
	// contains filtered or unexported fields
}

func NewCountFile added in v0.1.1

func NewCountFile(shardBit uint32) *CountFile

func (*CountFile) Add added in v0.1.1

func (cf *CountFile) Add(key string, size int64)

func (*CountFile) Mix added in v0.1.1

func (cf *CountFile) Mix() map[string]*FileInfo

type DelFail added in v0.1.2

type DelFail struct {
	Path string `json:"path"`
	Msg  string `json:"msg"`
}

func DelSync added in v0.1.2

func DelSync(paths []string) (failed []DelFail)

type Dir

type Dir struct {
	sync.Mutex `json:"-" yaml:"-"`
	Name       string `json:"name" yaml:"name"`
	FullPath   string `json:"path" yaml:"full_path"`
	Size       int64  `json:"value" yaml:"size"`
	Type       uint16 `json:"type" yaml:"type"`
	Perm       uint16 `json:"perm" yaml:"perm"`
	Children   []any  `json:"children" yaml:"children"`
}

Dir Directory

func (*Dir) GetFullPath added in v0.1.2

func (d *Dir) GetFullPath() string

func (*Dir) GetName added in v0.1.2

func (d *Dir) GetName() string

func (*Dir) GetSize added in v0.1.2

func (d *Dir) GetSize() int64

func (*Dir) IsDir added in v0.1.2

func (d *Dir) IsDir() bool

func (*Dir) Print added in v0.1.2

func (d *Dir) Print(i int)

func (*Dir) String added in v0.1.2

func (d *Dir) String() string

func (*Dir) Walk

func (d *Dir) Walk(countFile *CountFile, ignoreRules RuleList, topK *TopK, duplicateFiles *DuplicateFiles) error

Walk The most normal depth first traversal

func (*Dir) WalkSync

func (d *Dir) WalkSync(depth uint8, syncMaxDepth uint8, countFile *CountFile, ignoreRules RuleList, topK *TopK, duplicateFiles *DuplicateFiles) error

type DirectoryRule added in v0.1.2

type DirectoryRule struct {
	// contains filtered or unexported fields
}

func (DirectoryRule) Ignore added in v0.1.2

func (d DirectoryRule) Ignore(node Node) bool

type DuplicateFiles added in v0.1.4

type DuplicateFiles struct {
	// contains filtered or unexported fields
}

func NewDuplicateFiles added in v0.1.4

func NewDuplicateFiles() *DuplicateFiles

func (*DuplicateFiles) Check added in v0.1.4

func (d *DuplicateFiles) Check() (ret []FileCluster)

func (*DuplicateFiles) Push added in v0.1.4

func (d *DuplicateFiles) Push(f File)

type File

type File struct {
	Name     string `json:"name" yaml:"name"`
	FullPath string `json:"path" yaml:"full_path"`
	Size     int64  `json:"value" yaml:"size"`
	Type     uint8  `json:"type" yaml:"type"`
	Perm     uint16 `json:"perm" yaml:"perm"`
	Suffix   string `json:"suffix" yaml:"suffix"`
}

func (*File) GetFullPath

func (f *File) GetFullPath() string

func (*File) GetName

func (f *File) GetName() string

func (*File) GetSize

func (f *File) GetSize() int64

func (*File) IsDir

func (f *File) IsDir() bool

func (*File) Print

func (f *File) Print(i int)

func (*File) String

func (f *File) String() string

type FileCluster added in v0.1.4

type FileCluster struct {
	Name          string
	Hash          string
	Size          int64
	FileFullPaths []string
}

type FileHead added in v0.1.4

type FileHead []File

func (FileHead) Len added in v0.1.4

func (h FileHead) Len() int

func (FileHead) Less added in v0.1.4

func (h FileHead) Less(i, j int) bool

func (*FileHead) Pop added in v0.1.4

func (h *FileHead) Pop() interface{}

func (FileHead) Println added in v0.1.4

func (h FileHead) Println()

func (*FileHead) Push added in v0.1.4

func (h *FileHead) Push(x interface{})

func (FileHead) Swap added in v0.1.4

func (h FileHead) Swap(i, j int)

type FileInfo added in v0.1.1

type FileInfo struct {
	Size  int64
	Count int64
}

func (*FileInfo) Add added in v0.1.1

func (f *FileInfo) Add(s int64)

type FileNameRule added in v0.1.2

type FileNameRule struct {
	// contains filtered or unexported fields
}

func (FileNameRule) Ignore added in v0.1.2

func (f FileNameRule) Ignore(node Node) bool

type FilePathRule added in v0.1.2

type FilePathRule struct {
	// contains filtered or unexported fields
}

func (FilePathRule) Ignore added in v0.1.2

func (f FilePathRule) Ignore(node Node) bool

type FileSizeRule added in v0.1.2

type FileSizeRule struct {
	// contains filtered or unexported fields
}

func (FileSizeRule) Ignore added in v0.1.2

func (f FileSizeRule) Ignore(node Node) bool
type Link struct {
	Name     string `json:"name" yaml:"name"`
	FullPath string `json:"path" yaml:"full_path"`
	Size     int64  `json:"value" yaml:"size"`
	Type     uint8  `json:"type" yaml:"type"`
	Perm     uint16 `json:"perm" yaml:"perm"`
	LinkTo   string `json:"link_to" yaml:"link_to"`
}

func (Link) GetFullPath added in v0.1.2

func (l Link) GetFullPath() string

func (Link) GetName added in v0.1.2

func (l Link) GetName() string

func (Link) GetSize added in v0.1.2

func (l Link) GetSize() int64

func (Link) IsDir added in v0.1.2

func (l Link) IsDir() bool

func (Link) Print added in v0.1.2

func (l Link) Print(i int)

func (Link) String added in v0.1.2

func (l Link) String() string

type Node

type Node interface {
	GetName() string
	GetFullPath() string
	GetSize() int64
	IsDir() bool
	String() string
	Print(int)
}

type Rule added in v0.1.2

type Rule interface {
	// Ignore true mean no pass
	Ignore(node Node) bool
}

type RuleList added in v0.1.2

type RuleList []Rule

func ReadIgnore added in v0.1.2

func ReadIgnore(path string) (rules RuleList, ok bool)

func (RuleList) Ignore added in v0.1.2

func (r RuleList) Ignore(node Node) (res bool)

type ShardedMap added in v0.1.1

type ShardedMap struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewShardedMap added in v0.1.1

func NewShardedMap() *ShardedMap

type SuffixRule added in v0.1.2

type SuffixRule struct {
	// contains filtered or unexported fields
}

func (SuffixRule) Ignore added in v0.1.2

func (s SuffixRule) Ignore(node Node) bool

type TopK added in v0.1.4

type TopK struct {
	// contains filtered or unexported fields
}

func NewTopK added in v0.1.4

func NewTopK(k int) *TopK

func (*TopK) Enabled added in v0.1.4

func (t *TopK) Enabled() bool

func (*TopK) Push added in v0.1.4

func (t *TopK) Push(f File)

func (*TopK) TopK added in v0.1.4

func (t *TopK) TopK() []File

func (*TopK) TopKSorted added in v0.1.4

func (t *TopK) TopKSorted() []File

Directories

Path Synopsis
cmd
fileTree command

Jump to

Keyboard shortcuts

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