Skip to content

Commit

Permalink
Merge pull request #37 from CiscoCloud/fix/sync-errors
Browse files Browse the repository at this point in the history
Fix/sync errors
  • Loading branch information
ryane committed Mar 9, 2016
2 parents 655fed8 + 860073c commit 962fb4e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
21 changes: 12 additions & 9 deletions install/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package install
import (
"errors"
"fmt"
log "github.com/Sirupsen/logrus"
consul "github.com/hashicorp/consul/api"
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"time"

log "github.com/Sirupsen/logrus"
consul "github.com/hashicorp/consul/api"
)

const (
Expand Down Expand Up @@ -59,19 +60,22 @@ func (install *Install) sourceLastUpdated(source *Source) (time.Time, error) {
func (install *Install) sync(source *Source, sourcePath string) error {
// TODO: lock or something to prevent simultaneous syncs?
err := filepath.Walk(sourcePath, func(filePath string, f os.FileInfo, e error) error {
var err error
var relkey string
if isSourceArtifact(filePath) {
relkey, err := filepath.Rel(sourcePath, filePath)
var data []byte
relkey, err = filepath.Rel(sourcePath, filePath)
if err == nil {
data, err := ioutil.ReadFile(filePath)
data, err = ioutil.ReadFile(filePath)
if err == nil {
key := path.Join(source.rootKey(), relkey)
install.addSourceArtifact(key, data)
err = install.addSourceArtifact(key, data)
} else {
log.Errorf("Could not read file %v: %v", filePath, err)
}
}
}
return nil
return err
})

if err != nil {
Expand Down Expand Up @@ -143,14 +147,13 @@ func (install *Install) setTimestamp(source *Source) error {
return err
}

func (install *Install) addSourceArtifact(key string, data []byte) {
func (install *Install) addSourceArtifact(key string, data []byte) error {
kp := &consul.KVPair{Key: key, Value: data}
_, err := install.kv.Put(kp, nil)
if err == nil {
log.Debugf("Wrote %v", key)
} else {
log.Errorf("Could not write %v to KV: %v", key, err)
}
return err
}

func isSourceArtifact(filePath string) bool {
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

const Name = "mantl-api"
const Version = "0.1.6"
const Version = "0.1.7"

var wg sync.WaitGroup

Expand Down Expand Up @@ -243,7 +243,9 @@ func syncRepo(inst *install.Install, force bool) {
sources = defaultSources
}

inst.SyncSources(sources, force)
if err := inst.SyncSources(sources, force); err != nil {
log.Fatal(err)
}
}

func readConfigFile() {
Expand Down

0 comments on commit 962fb4e

Please sign in to comment.