From 1148047438f46bbbb7ff08816c655c2bfdd1e243 Mon Sep 17 00:00:00 2001 From: alessio Date: Sat, 17 Dec 2016 01:48:04 +0100 Subject: [PATCH] realize files moved in .realize hidden dir --- realize.go | 1 - settings/io.go | 9 ++++++++- settings/settings.go | 7 ++++--- watcher/exec.go | 3 +-- watcher/watcher.go | 10 +++------- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/realize.go b/realize.go index 221a91b..4a148b2 100644 --- a/realize.go +++ b/realize.go @@ -17,7 +17,6 @@ const ( config = "realize.yaml" output = "outputs.log" log = "logs.log" - err = "errors.log" host = "localhost" port = 5000 server = true diff --git a/settings/io.go b/settings/io.go index 02b9e6d..9619aea 100644 --- a/settings/io.go +++ b/settings/io.go @@ -3,6 +3,7 @@ package settings import ( "io/ioutil" "os" + "path/filepath" ) // Scan return a byte stream of a given file @@ -23,7 +24,13 @@ func (s Settings) Write(name string, data []byte) error { } // Create a new file and return its pointer -func (s Settings) Create(file string) *os.File { +func (s Settings) Create(path string, name string) *os.File { + var file string + if _, err := os.Stat(".realize/"); err == nil { + file = filepath.Join(path, ".realize/", name) + } else { + file = filepath.Join(path, name) + } out, err := os.OpenFile(file, os.O_APPEND|os.O_WRONLY|os.O_CREATE|os.O_SYNC, 0655) s.Validate(err) return out diff --git a/settings/settings.go b/settings/settings.go index c44fca2..57f671e 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -1,9 +1,8 @@ package settings import ( - "os" - "gopkg.in/yaml.v2" + "os" ) type Settings struct { @@ -51,7 +50,9 @@ func (s *Settings) Record(out interface{}) error { return err } if _, err := os.Stat(".realize/"); os.IsNotExist(err) { - os.Mkdir(".realize", 0770) + if err = os.Mkdir(".realize/", 0770); err != nil { + return s.Write(s.Resources.Config, y) + } } return s.Write(".realize/"+s.Resources.Config, y) } diff --git a/watcher/exec.go b/watcher/exec.go index 283b276..4523819 100644 --- a/watcher/exec.go +++ b/watcher/exec.go @@ -81,8 +81,7 @@ func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup) log.Println(p.pname(p.Name, 3), ":", p.Blue.Regular(output.Text())) } if p.File.Streams { - path := filepath.Join(p.base, p.Resources.Output) - f := p.Create(path) + f := p.Create(p.base, p.parent.Resources.Output) t := time.Now() if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + output.Text() + "\r\n"); err != nil { p.Fatal(err, "") diff --git a/watcher/watcher.go b/watcher/watcher.go index 774fea4..b9d3103 100644 --- a/watcher/watcher.go +++ b/watcher/watcher.go @@ -25,7 +25,6 @@ func (p *Project) watching() { defer func() { wg.Done() }() - if err != nil { log.Fatalln(p.pname(p.Name, 2), ":", p.Red.Bold(err.Error())) return @@ -312,8 +311,7 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) { case "out": p.Buffer.StdOut = append(p.Buffer.StdOut, o) if p.File.Streams { - path := filepath.Join(p.base, p.Resources.Output) - f := p.Create(path) + f := p.Create(p.base, p.parent.Resources.Output) t := time.Now() if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil { p.Fatal(err, "") @@ -322,8 +320,7 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) { case "log": p.Buffer.StdLog = append(p.Buffer.StdLog, o) if p.File.Logs { - path := filepath.Join(p.base, p.Resources.Log) - f := p.Create(path) + f := p.Create(p.base, p.parent.Resources.Log) t := time.Now() if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil { p.Fatal(err, "") @@ -332,8 +329,7 @@ func (p *Project) print(t string, o BufferOut, msg string, stream string) { case "error": p.Buffer.StdErr = append(p.Buffer.StdErr, o) if p.File.Errors { - path := filepath.Join(p.base, p.Resources.Log) - f := p.Create(path) + f := p.Create(p.base, p.parent.Resources.Log) t := time.Now() if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + o.Text + "\r\n"); err != nil { p.Fatal(err, "")