瀏覽代碼

ft: fsnotify+go版本升级

master
lijie 2 年之前
父節點
當前提交
abc6cf3991
共有 5 個檔案被更改,包括 22 行新增19 行删除
  1. +3
    -0
      README.md
  2. 二進制
      fileSync
  3. 二進制
      fileSync.exe
  4. +16
    -16
      fileSync.go
  5. +3
    -3
      go.mod

+ 3
- 0
README.md 查看文件

@ -8,6 +8,9 @@
go build -ldflags "-a -s -w"
./upx396/upx --best fileSync
# 升级版本
先删除 go.mod go.sum 然后执行go mod init fileSync go mod tidy 然后编译

二進制
fileSync 查看文件


二進制
fileSync.exe 查看文件


+ 16
- 16
fileSync.go 查看文件

@ -75,17 +75,17 @@ func CollectFile(File string) {
}
func isHidden(path string) bool {
for i := len(path) - 1; i > 0; i-- {
if path[i] != '.' {
continue
}
if os.IsPathSeparator(path[i-1]) {
return true
}
}
if path[0] == '.' {
return true
}
// for i := len(path) - 1; i > 0; i-- {
// if path[i] != '.' {
// continue
// }
// if os.IsPathSeparator(path[i-1]) {
// return true
// }
// }
// if path[0] == '.' {
// return true
// }
return false
}
@ -137,7 +137,7 @@ func (w *Watch) watchDir(dir string) {
select {
case ev := <-w.watch.Events:
{
if ev.Op&fsnotify.Create == fsnotify.Create {
if ev.Has(fsnotify.Create) {
//这里获取新创建文件的信息,如果是目录,则加入监控中
fi, err := os.Stat(ev.Name)
if err == nil && fi.IsDir() {
@ -154,24 +154,24 @@ func (w *Watch) watchDir(dir string) {
CollectFile(ev.Name)
}
}
if ev.Op&fsnotify.Write == fsnotify.Write {
if ev.Has(fsnotify.Write) {
CollectFile(ev.Name)
}
if ev.Op&fsnotify.Remove == fsnotify.Remove {
if ev.Has(fsnotify.Remove) {
//如果删除文件是目录,则移除监控
fi, err := os.Stat(ev.Name)
if err == nil && fi.IsDir() {
w.watch.Remove(ev.Name)
}
}
if ev.Op&fsnotify.Rename == fsnotify.Rename {
if ev.Has(fsnotify.Rename) {
//如果重命名文件是目录,则移除监控
//注意这里无法使用os.Stat来判断是否是目录了
//因为重命名后,go已经无法找到原文件来获取信息了
//所以这里就简单粗爆的直接remove好了
w.watch.Remove(ev.Name)
}
if ev.Op&fsnotify.Chmod == fsnotify.Chmod {
if ev.Has(fsnotify.Chmod) {
}
}
case <-w.watch.Errors:

+ 3
- 3
go.mod 查看文件

@ -1,7 +1,7 @@
module fileSync
go 1.18
go 1.19
require github.com/fsnotify/fsnotify v1.5.4
require github.com/fsnotify/fsnotify v1.6.0
require golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
require golang.org/x/sys v0.0.0-20220908164124-27713097b956 // indirect

Loading…
取消
儲存