Skip to content

Commit

Permalink
Change event to access old and new path on events
Browse files Browse the repository at this point in the history
  • Loading branch information
llescouzeres committed Jul 8, 2018
1 parent 0d9d326 commit 37111d4
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func (e Op) String() string {
// directory and the type of event that's occurred and the full path of the file.
type Event struct {
Op
Path string
Path string
OldPath string
os.FileInfo
}

Expand Down Expand Up @@ -547,14 +548,14 @@ func (w *Watcher) pollEvents(files map[string]os.FileInfo, evt chan Event,
select {
case <-cancel:
return
case evt <- Event{Write, path, info}:
case evt <- Event{Write, path, path, info}:
}
}
if oldInfo.Mode() != info.Mode() {
select {
case <-cancel:
return
case evt <- Event{Chmod, path, info}:
case evt <- Event{Chmod, path, path, info}:
}
}
}
Expand All @@ -565,7 +566,8 @@ func (w *Watcher) pollEvents(files map[string]os.FileInfo, evt chan Event,
if sameFile(info1, info2) {
e := Event{
Op: Move,
Path: fmt.Sprintf("%s -> %s", path1, path2),
Path: path2,
OldPath: path1,
FileInfo: info1,
}
// If they are from the same directory, it's a rename
Expand All @@ -591,14 +593,14 @@ func (w *Watcher) pollEvents(files map[string]os.FileInfo, evt chan Event,
select {
case <-cancel:
return
case evt <- Event{Create, path, info}:
case evt <- Event{Create, path, "", info}:
}
}
for path, info := range removes {
select {
case <-cancel:
return
case evt <- Event{Remove, path, info}:
case evt <- Event{Remove, "", path, info}:
}
}
}
Expand Down

0 comments on commit 37111d4

Please sign in to comment.