fix: single conversion at a time

See the notes for a full explanation, but basically
Kobo is making simultaneous requests and the
files were conflicting because there were 2 being
downloaded / converted at the same time which
resulted in unreliable behavior.

The solution is to protect the conversion
section to allow a single conversion to complete
before allowing the next one to start.
This commit is contained in:
Evan Buss
2024-07-14 19:56:00 +00:00
parent 56cb81bbb4
commit be78d83bd6
3 changed files with 44 additions and 8 deletions

View File

@@ -2,7 +2,6 @@ package convert
import (
"os/exec"
"path/filepath"
"strings"
"sync"
)
@@ -26,8 +25,7 @@ func (kc *KepubConverter) Convert(input string) (string, error) {
kc.mutex.Lock()
defer kc.mutex.Unlock()
dir := filepath.Dir(input)
kepubFile := filepath.Join(dir, strings.Replace(filepath.Base(input), ".epub", ".kepub.epub", 1))
kepubFile := strings.Replace(input, ".epub", ".kepub.epub", 1)
cmd := exec.Command("kepubify", "-v", "-u", "-o", kepubFile, input)
if err := cmd.Run(); err != nil {