mirror of
https://github.com/simon987/beemer.git
synced 2025-04-10 13:56:42 +00:00
fix #1
This commit is contained in:
parent
65be543878
commit
d433d81dbe
4
cli.go
4
cli.go
@ -28,7 +28,7 @@ func main() {
|
|||||||
app.Usage = "Execute a command on a file after a delay of inactivity"
|
app.Usage = "Execute a command on a file after a delay of inactivity"
|
||||||
app.Email = "me@simon987.net"
|
app.Email = "me@simon987.net"
|
||||||
app.Author = "simon987"
|
app.Author = "simon987"
|
||||||
app.Version = "1.1"
|
app.Version = "1.2"
|
||||||
|
|
||||||
var cmdString string
|
var cmdString string
|
||||||
var watchDir string
|
var watchDir string
|
||||||
@ -85,7 +85,7 @@ func main() {
|
|||||||
fileMap: &sync.Map{},
|
fileMap: &sync.Map{},
|
||||||
beemChan: make(chan string, transfers),
|
beemChan: make(chan string, transfers),
|
||||||
tarChan: make(chan string, 100),
|
tarChan: make(chan string, 100),
|
||||||
beemCommand: parseCommand(cmdString),
|
beemCommand: parseCommand(watchDir, cmdString),
|
||||||
inactiveDelay: inactiveDelay,
|
inactiveDelay: inactiveDelay,
|
||||||
beemWg: &sync.WaitGroup{},
|
beemWg: &sync.WaitGroup{},
|
||||||
tarWg: &sync.WaitGroup{},
|
tarWg: &sync.WaitGroup{},
|
||||||
|
13
util.go
13
util.go
@ -82,8 +82,9 @@ func copyFile(src string, dst string) error {
|
|||||||
return out.Close()
|
return out.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCommand(command string) func(string, string) (string, []string) {
|
func parseCommand(watchDir, command string) func(string, string) (string, []string) {
|
||||||
args, _ := argv.Argv([]rune(command), argv.ParseEnv(os.Environ()), argv.Run)
|
args, _ := argv.Argv([]rune(command), argv.ParseEnv(os.Environ()), argv.Run)
|
||||||
|
absWatchDir, _ := filepath.Abs(watchDir)
|
||||||
|
|
||||||
logrus.WithField("cmd", args[0]).Info("Parsed beem command")
|
logrus.WithField("cmd", args[0]).Info("Parsed beem command")
|
||||||
|
|
||||||
@ -93,7 +94,11 @@ func parseCommand(command string) func(string, string) (string, []string) {
|
|||||||
|
|
||||||
for i := range newTokens {
|
for i := range newTokens {
|
||||||
newTokens[i] = strings.Replace(newTokens[i], "%file", name, -1)
|
newTokens[i] = strings.Replace(newTokens[i], "%file", name, -1)
|
||||||
newTokens[i] = strings.Replace(newTokens[i], "%dir", dir, -1)
|
d, _ := filepath.Rel(absWatchDir, dir)
|
||||||
|
if d == "." {
|
||||||
|
d = ""
|
||||||
|
}
|
||||||
|
newTokens[i] = strings.Replace(newTokens[i], "%dir", d, -1)
|
||||||
newTokens[i] = strings.Replace(newTokens[i], "%name", filepath.Base(name), -1)
|
newTokens[i] = strings.Replace(newTokens[i], "%name", filepath.Base(name), -1)
|
||||||
}
|
}
|
||||||
return args[0][0], newTokens[1:]
|
return args[0][0], newTokens[1:]
|
||||||
@ -118,9 +123,9 @@ func (b *Beemer) dispose() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(15 * time.Second)
|
time.Sleep(30 * time.Second)
|
||||||
close(b.beemChan)
|
|
||||||
logrus.WithField("chanLen", len(b.beemChan)).Info("Forcefully closed beem channel")
|
logrus.WithField("chanLen", len(b.beemChan)).Info("Forcefully closed beem channel")
|
||||||
|
close(b.beemChan)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
logrus.WithField("chanLen", len(b.beemChan)).Info("Waiting for beem queue to drain...")
|
logrus.WithField("chanLen", len(b.beemChan)).Info("Waiting for beem queue to drain...")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user