[cfg]增加文件扫描器的排除路径配置

[scanner]进度条显示优化
This commit is contained in:
wuko233 2026-04-19 19:24:55 +08:00
parent c032cdba58
commit 84a4bf8093
2 changed files with 83 additions and 11 deletions

View File

@ -21,8 +21,64 @@ scanner:
include_paths: include_paths:
- / - /
exclude_paths: exclude_paths:
# ========== 虚拟/临时文件系统==========
- /proc - /proc
- /sys - /sys
- /dev
- /tmp
- /var/tmp
- /run
- /mnt
- /media
# ========== 系统高频写入目录==========
- /var/log
- /var/cache
- /var/mail
- /var/spool
- /var/lib/docker
- /var/lib/containerd
# ========== 内核模块==========
- /usr/lib/modules
- /lib/modules
- /usr/src
# ========== 应用缓存和构建目录==========
# 通用
- "**/node_modules"
- "**/.git"
- "**/.cache"
- "**/build"
- "**/dist"
- "**/unpackage"
- "**/vendor"
- "**/__pycache__"
- "**/.idea"
- "**/.vscode"
# ========== Web 应用特定==========
- "**/cache"
- "**/logs"
- "**/tmp"
- "**/temp"
- "**/uploads/tmp"
# ========== 用户缓存目录 ==========
- /root/.cache
- /root/.npm
- /root/.local
- /home/*/.cache
- /home/*/.npm
- /home/*/.local
- /home/*/.gradle
- /home/*/.m2
# ========== 其他高频变化目录 ==========
- /var/run
- /var/lock
- /opt/*/cache
- /opt/*/logs
fast_hash: true fast_hash: true
fast_hash_size: 100MB fast_hash_size: 100MB
fast_hash_chunk: 2MB fast_hash_chunk: 2MB

View File

@ -56,7 +56,9 @@ func (s *Scanner) Scan() ([]FileInfo, error) {
var allFiles []FileInfo var allFiles []FileInfo
hashCfg, _ := s.cfg.GetHashConfig() hashCfg, _ := s.cfg.GetHashConfig()
bar := progressbar.NewOptions(len(allPaths), var bar *progressbar.ProgressBar
if isInteractiveTerminal() {
bar = progressbar.NewOptions(len(allPaths),
progressbar.OptionSetDescription("[scan]计算文件哈希"), progressbar.OptionSetDescription("[scan]计算文件哈希"),
progressbar.OptionSetWriter(os.Stderr), progressbar.OptionSetWriter(os.Stderr),
progressbar.OptionShowCount(), progressbar.OptionShowCount(),
@ -66,9 +68,14 @@ func (s *Scanner) Scan() ([]FileInfo, error) {
logger.Log.Info("[scan]文件哈希计算完成") logger.Log.Info("[scan]文件哈希计算完成")
}), }),
) )
} else {
logger.Log.Info("[scan]开始计算文件哈希", zap.Int("total_files", len(allPaths)))
}
for _, path := range allPaths { for _, path := range allPaths {
if bar != nil {
bar.Add(1) bar.Add(1)
}
info, err := os.Stat(path) info, err := os.Stat(path)
if err != nil { if err != nil {
@ -167,6 +174,15 @@ func (s *Scanner) collectPathsFunc(result *[]string) fs.WalkDirFunc {
} }
} }
func isInteractiveTerminal() bool {
fileInfo, err := os.Stderr.Stat()
if err != nil {
return false
}
return (fileInfo.Mode() & os.ModeCharDevice) != 0
}
func (f FileInfo) String() string { func (f FileInfo) String() string {
return fmt.Sprintf("%s:%s", f.Path, f.Hash) return fmt.Sprintf("%s:%s", f.Path, f.Hash)
} }