oniony / TMSU

TMSU lets you tags your files and then access them through a nifty virtual filesystem from any other application.
Other
2.01k stars 115 forks source link

database locked occasionally #261

Open Alsan opened 1 year ago

Alsan commented 1 year ago

I'm trying to write a program to auto tag my collections. It'll call the tmsu through shell execution, then combining fd to loop through all files in my collections. It worked as expected, except the tmsu returns database locked error occasionally.

Here's my program fragment:

func runCommand(filename string, command string, ch chan output) {
  // fmt.Println(cmd)
  fields := strings.Fields(command)
  cmd := exec.Command(fields[0], fields[1:]...)
  out, err := cmd.CombinedOutput()
  ch <- output{out, err}
}

...

ch := make(chan output)
go runCommand(fn, cmd, ch)

select {
case <-time.After(2 * time.Second):
  errs.PrintToStdErrAndExit(fmt.Sprintf("timeout: %s", cmd))
case x := <-ch:
  if x.err != nil {
    errs.PrintToStdErrAndExit(fmt.Sprintf("error: %s", string(x.out)))
  } else {
    fmt.Println(fn)
  }
}

Any suggestion on optimizing the program?