parent
c032cdba58
commit
84a4bf8093
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -56,19 +56,26 @@ 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
|
||||||
progressbar.OptionSetDescription("[scan]计算文件哈希"),
|
if isInteractiveTerminal() {
|
||||||
progressbar.OptionSetWriter(os.Stderr),
|
bar = progressbar.NewOptions(len(allPaths),
|
||||||
progressbar.OptionShowCount(),
|
progressbar.OptionSetDescription("[scan]计算文件哈希"),
|
||||||
progressbar.OptionShowIts(),
|
progressbar.OptionSetWriter(os.Stderr),
|
||||||
progressbar.OptionSetItsString("files"),
|
progressbar.OptionShowCount(),
|
||||||
progressbar.OptionOnCompletion(func() {
|
progressbar.OptionShowIts(),
|
||||||
logger.Log.Info("[scan]文件哈希计算完成")
|
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 {
|
for _, path := range allPaths {
|
||||||
bar.Add(1)
|
if bar != nil {
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user