More refactoring

This commit is contained in:
2019-07-16 21:39:27 -04:00
parent b0895015ea
commit dc954bc85b
4 changed files with 294 additions and 275 deletions

25
util.go
View File

@@ -9,21 +9,21 @@ import (
"strings"
)
func initTempDir() {
tmpdir := filepath.Join(os.TempDir(), "beemer")
func (b Beemer) initTempDir() {
tmpdir := filepath.Join(os.TempDir(), "work")
err := os.Mkdir(tmpdir, 0700)
if err != nil && !os.IsExist(err) {
logrus.Fatal(err)
}
ctx.TempDir = tmpdir
b.tempDir = tmpdir
logrus.WithField("dir", tmpdir).Infof("Initialized temp dir")
}
func moveToTempDir(name string) string {
func moveToTempDir(name string, tempDir string) string {
dir := filepath.Join(ctx.TempDir, filepath.Dir(name))
dir := filepath.Join(tempDir, filepath.Dir(name))
newName := filepath.Join(dir, filepath.Base(name))
err := os.MkdirAll(dir, 0700)
if err != nil && !os.IsExist(err) {
@@ -98,3 +98,18 @@ func parseCommand(command string) func(string, string) (string, []string) {
return args[0][0], newTokens[1:]
}
}
func isDir(name string) bool {
if stat, err := os.Stat(name); err == nil && stat.IsDir() {
return true
}
return false
}
func (b Beemer) dispose() {
b.watcher.Close()
err := os.RemoveAll(b.tempDir)
if err != nil {
logrus.Fatal(err)
}
}