mirror of
https://github.com/simon987/beemer.git
synced 2025-12-17 09:09:01 +00:00
More refactoring
This commit is contained in:
25
util.go
25
util.go
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user