Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if event is just an attrib flag that can be skipped #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ package main
import (
"flag"
"fmt"
"github.com/pilu/fresh/runner"
"os"

"github.com/pkieltyka/fresh/runner"
)

func main() {
configPath := flag.String("c", "", "config file path")
watchPath := flag.String("w", "", "path to watch files")

flag.Parse()

// TODO: nice big refactoring of the flags + config

if *configPath != "" {
if _, err := os.Stat(*configPath); err != nil {
fmt.Printf("Can't find config file `%s`\n", *configPath)
Expand All @@ -31,6 +36,7 @@ func main() {
os.Setenv("RUNNER_CONFIG_PATH", *configPath)
}
}
os.Setenv("RUNNER_WATCH_PATH", *watchPath)

runner.Start()
}
1 change: 1 addition & 0 deletions runner.conf.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
root: .
watch_path: .
tmp_path: ./tmp
build_name: runner-build
build_log: runner-build-errors.log
Expand Down
8 changes: 7 additions & 1 deletion runner/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package runner

import (
"fmt"
"github.com/pilu/config"
"os"
"path/filepath"
"strconv"
"strings"
"time"

"github.com/pilu/config"
)

const (
Expand All @@ -18,6 +19,7 @@ const (
var settings = map[string]string{
"config_path": "./runner.conf",
"root": ".",
"watch_path": ".",
"tmp_path": "./tmp",
"build_name": "runner-build",
"build_log": "runner-build-errors.log",
Expand Down Expand Up @@ -108,6 +110,10 @@ func root() string {
return settings["root"]
}

func watchPath() string {
return settings["watch_path"]
}

func tmpPath() string {
return settings["tmp_path"]
}
Expand Down
5 changes: 5 additions & 0 deletions runner/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func isTmpDir(path string) bool {
return absolutePath == absoluteTmpPath
}

func isVendorDir(path string) bool {
absolutePath, _ := filepath.Abs(path)
return filepath.Base(absolutePath) == "vendor"
}

func isWatchedFile(path string) bool {
absolutePath, _ := filepath.Abs(path)
absoluteTmpPath, _ := filepath.Abs(tmpPath())
Expand Down
15 changes: 10 additions & 5 deletions runner/watcher.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package runner

import (
"github.com/howeyc/fsnotify"
"os"
"path/filepath"
"strings"

"github.com/howeyc/fsnotify"
)

func watchFolder(path string) {
Expand All @@ -17,7 +18,7 @@ func watchFolder(path string) {
for {
select {
case ev := <-watcher.Event:
if isWatchedFile(ev.Name) {
if isWatchedFile(ev.Name) && !ev.IsAttrib() {
watcherLog("sending event %s", ev)
startChannel <- ev.String()
}
Expand All @@ -36,10 +37,14 @@ func watchFolder(path string) {
}

func watch() {
root := root()
filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
watchPath, err := filepath.Abs(watchPath())
if err != nil {
fatal(err)
}

filepath.Walk(watchPath, func(path string, info os.FileInfo, err error) error {
if info.IsDir() && !isTmpDir(path) {
if len(path) > 1 && strings.HasPrefix(filepath.Base(path), ".") {
if (len(path) > 1 && strings.HasPrefix(filepath.Base(path), ".")) || (isVendorDir(path)) {
return filepath.SkipDir
}

Expand Down