diff --git a/config.yaml.example b/config.yaml.example index dd0aa3c..d9eb814 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -21,8 +21,64 @@ scanner: include_paths: - / exclude_paths: + # ========== 虚拟/临时文件系统========== - /proc - /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_size: 100MB fast_hash_chunk: 2MB diff --git a/internal/scanner/file/file.go b/internal/scanner/file/file.go index e220533..47d5c79 100644 --- a/internal/scanner/file/file.go +++ b/internal/scanner/file/file.go @@ -56,19 +56,26 @@ func (s *Scanner) Scan() ([]FileInfo, error) { var allFiles []FileInfo hashCfg, _ := s.cfg.GetHashConfig() - bar := progressbar.NewOptions(len(allPaths), - progressbar.OptionSetDescription("[scan]计算文件哈希"), - progressbar.OptionSetWriter(os.Stderr), - progressbar.OptionShowCount(), - progressbar.OptionShowIts(), - progressbar.OptionSetItsString("files"), - progressbar.OptionOnCompletion(func() { - logger.Log.Info("[scan]文件哈希计算完成") - }), - ) + var bar *progressbar.ProgressBar + if isInteractiveTerminal() { + bar = progressbar.NewOptions(len(allPaths), + progressbar.OptionSetDescription("[scan]计算文件哈希"), + progressbar.OptionSetWriter(os.Stderr), + progressbar.OptionShowCount(), + progressbar.OptionShowIts(), + progressbar.OptionSetItsString("files"), + progressbar.OptionOnCompletion(func() { + logger.Log.Info("[scan]文件哈希计算完成") + }), + ) + } else { + logger.Log.Info("[scan]开始计算文件哈希", zap.Int("total_files", len(allPaths))) + } for _, path := range allPaths { - bar.Add(1) + if bar != nil { + bar.Add(1) + } info, err := os.Stat(path) 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 { return fmt.Sprintf("%s:%s", f.Path, f.Hash) }