Skip to content

Commit

Permalink
Rsync should use relative path.
Browse files Browse the repository at this point in the history
Alos use logrus to replace glog.
  • Loading branch information
sohoffice committed May 22, 2019
1 parent ba7affe commit fde8b94
Show file tree
Hide file tree
Showing 22 changed files with 145 additions and 86 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
dist
tmp
/piaasconfig.yml
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Go parameters
PROJECT_NAME=PIAAS
VERSION=v0.0.3
VERSION=v0.0.4
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
Expand All @@ -10,7 +10,7 @@ BINARY_NAME=piaas
TESTMODE?=
LDFLAGS=-ldflags "-X main.version=$(VERSION)"

all: test$(TESTMODE) build-all
all: test$(TESTMODE) build-all update-latest

build:
cd main && CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o ../dist/$(VERSION)/darwin_amd64/$(BINARY_NAME) -v && cd ..
Expand All @@ -28,7 +28,7 @@ clean:
$(GOCLEAN)
rm -rf dist
run: build
./dist/darwin-amd64/$(BINARY_NAME)
./dist/$(VERSION)/darwin_amd64/$(BINARY_NAME) sync cent -debug
deps:
$(GOGET) github.com/markbates/goth
$(GOGET) github.com/markbates/pop
Expand All @@ -48,6 +48,10 @@ build-windows:
chmod a+x dist/$(VERSION)/windows_amd64/$(BINARY_NAME).exe
@echo " Built windows-amd64"

update-latest:
@rm -f dist/latest
@ln -s ./$(VERSION) dist/latest

# Publish new release
publish: tests$(TESTMODE) build-all
# Tag the main repo with the release version
Expand Down
12 changes: 3 additions & 9 deletions fsevent_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ package piaas

import (
"github.com/fsnotify/fsevents"
"github.com/golang/glog"
"log"
log "github.com/sirupsen/logrus"
"path/filepath"
"time"
)
Expand Down Expand Up @@ -46,7 +45,7 @@ func (fsm *FSEventMonitor) Start(debounceTime uint64) {

func (fsm *FSEventMonitor) Subscribe(subscriber chan<- []string) {
fsm.collectObservers = append(fsm.collectObservers, subscriber)
glog.Infof("Added collect observer: %d.", len(fsm.collectObservers))
log.Debugf("Added collect observer: %d.", len(fsm.collectObservers))
}

func (fsm *FSEventMonitor) Stop() {
Expand Down Expand Up @@ -76,16 +75,11 @@ func handleCollectedFSEvent(fsm *FSEventMonitor) {
func NewFSEventMonitor(path string) FSEventMonitor {
evaluated, err := filepath.EvalSymlinks(path)
if err != nil {
glog.Errorf("Error evaluating sym links: %s", err)
log.Errorf("Error evaluating sym links: %s", err)
evaluated = path
}
return FSEventMonitor{
startDir: evaluated,
collectsCh: make(chan []string),
}
}

func NewMonitor(startDir string) Monitor {
fsm := NewFSEventMonitor(startDir)
return &fsm
}
8 changes: 5 additions & 3 deletions fsevent_monitor_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// +build darwin

package piaas

import (
"fmt"
"github.com/golang/glog"
log "github.com/sirupsen/logrus"
"github.com/sohoffice/piaas/stringarrays"
"io/ioutil"
"os"
Expand All @@ -29,7 +31,7 @@ func TestFSEventMonitor(t *testing.T) {
}()

mon.Subscribe(collectedCh)
mon.Start(500)
mon.Start(600)

expected := []string{
pathConvert(path.Join(tempDir, "dir-to-delete")),
Expand All @@ -46,7 +48,7 @@ func TestFSEventMonitor(t *testing.T) {

<-completed

glog.Infof("Collected FSEvents:\n%s\n", stringarrays.ToString(collected))
log.Debugf("Collected FSEvents:\n%s\n", stringarrays.ToString(collected))
expected = append(expected, path.Join(tempDir, "dir"), path.Join(tempDir, "dir", "foo"))
validate(t, collected, expected, []string{}, pathConvert)
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ require (
github.com/fsnotify/fsnotify v1.4.7
github.com/go-yaml/yaml v2.1.0+incompatible
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/sirupsen/logrus v1.4.2
github.com/urfave/cli v1.20.0
golang.org/x/sys v0.0.0-20190509141414-a5b02f93d862 // indirect
)
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsevents v0.1.1 h1:/125uxJvvoSDDBPen6yUZbil8J9ydKZnnl3TWWmvnkw=
github.com/fsnotify/fsevents v0.1.1/go.mod h1:+d+hS27T6k5J8CRaPLKFgwKYcpS7GwW3Ule9+SC2ZRc=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
Expand All @@ -6,7 +7,15 @@ github.com/go-yaml/yaml v2.1.0+incompatible h1:RYi2hDdss1u4YE7GwixGzWwVo47T8UQwn
github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190509141414-a5b02f93d862 h1:rM0ROo5vb9AdYJi1110yjWGMej9ITfKddS89P3Fkhug=
golang.org/x/sys v0.0.0-20190509141414-a5b02f93d862/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
8 changes: 4 additions & 4 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"flag"
"fmt"
"github.com/golang/glog"
log "github.com/sirupsen/logrus"
"github.com/sohoffice/piaas/sync"
"github.com/urfave/cli"
"io/ioutil"
Expand All @@ -18,8 +18,10 @@ func main() {
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
// Do not print any output from flag module.
flag.CommandLine.SetOutput(ioutil.Discard)
// We still would like the service of flag, for it will be used to initialize glog.
// We still would like the service of flag
flag.Parse()
// default log level is INFO
log.SetLevel(log.InfoLevel)

app := cli.NewApp()
app.Name = "Piaas, tools to develop using multiple machines as if using Personal IAAS."
Expand All @@ -36,8 +38,6 @@ func main() {
sync.Prepare(),
}

defer glog.Flush()

exitCh := make(chan os.Signal, 1)
signal.Notify(exitCh, os.Interrupt, os.Kill)
go func() {
Expand Down
13 changes: 13 additions & 0 deletions monitor_all.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// +build !darwin

package piaas

import (
log "github.com/sirupsen/logrus"
)

func NewMonitor(startDir string) Monitor {
log.Infof("Use fsnotify recursive monitor.")
rm := NewRecursiveMonitor(startDir)
return &rm
}
13 changes: 13 additions & 0 deletions monitor_macos.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// +build darwin

package piaas

import (
log "github.com/sirupsen/logrus"
)

func NewMonitor(startDir string) Monitor {
log.Infof("Use fsevent monitor.")
fsm := NewFSEventMonitor(startDir)
return &fsm
}
5 changes: 2 additions & 3 deletions piaas.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package piaas

import (
"flag"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
"log"
)

// Below are common option handler.
Expand All @@ -12,7 +11,7 @@ import (
func HandleDebug(c *cli.Context) error {
if c.Bool("debug") == true {
log.Println("Debug is on.")
flag.Lookup("logtostderr").Value.Set("true")
log.SetLevel(log.DebugLevel)
}
return nil
}
2 changes: 0 additions & 2 deletions piaas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package piaas

import (
"flag"
"github.com/golang/glog"
"os"
"testing"
)

// The method to setup and tear down the tests of this package.
func TestMain(m *testing.M) {
defer glog.Flush()
flag.Parse()
// flag.Lookup("logtostderr").Value.Set("true")
os.Exit(m.Run())
Expand Down
7 changes: 7 additions & 0 deletions piaasconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: 1
profiles:
- name: cent
connection:
host: centaurium.sohoffice.com
user: gowithme
destination: /tmp/piaas
Loading

0 comments on commit fde8b94

Please sign in to comment.