[Fix] Fixed usage of old watcher Event API. Resolves #7.

* The `watcher` `Event` API changed from stuffing old/new path into a single field to having them as separate fields.  Update the code to use the new API.
This commit is contained in:
Thomas M. Edwards 2020-02-24 16:19:07 -06:00
parent 6e2090b23d
commit 2d91f1ce96

View file

@ -12,7 +12,6 @@ import (
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"time" "time"
// external packages // external packages
"github.com/radovskyb/watcher" "github.com/radovskyb/watcher"
@ -133,12 +132,9 @@ func watchFilesystem(pathnames []string, outFilename string, buildCallback func(
var pathname string var pathname string
switch event.Op { switch event.Op {
case watcher.Move, watcher.Rename: case watcher.Move, watcher.Rename:
// NOTE: Format of Move/Rename event `Path` field: "oldName -> newName". pathname = fmt.Sprintf("%s -> %s", relPath(event.OldPath), relPath(event.Path))
// TODO: Should probably error out if we can't split the event.Path value.
names := strings.Split(event.Path, " -> ")
pathname = fmt.Sprintf("%s -> %s", relPath(names[0]), relPath(names[1]))
if !build && !isDir { if !build && !isDir {
build = knownFileType(names[0]) || knownFileType(names[1]) build = knownFileType(event.OldPath) || knownFileType(event.Path)
} }
default: default:
pathname = relPath(event.Path) pathname = relPath(event.Path)