diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2021-03-20 22:42:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-20 22:42:41 +0100 |
commit | 0450482e6ebed8a379f2d43f0ee264ea0d130a31 (patch) | |
tree | 7e79a5827017295147bc8362f0dd138bd89b2064 /bridge/helper/helper.go | |
parent | ee5d9b43b54a3becf3cb4025198f24608d35500d (diff) | |
download | matterbridge-msglm-0450482e6ebed8a379f2d43f0ee264ea0d130a31.tar.gz matterbridge-msglm-0450482e6ebed8a379f2d43f0ee264ea0d130a31.tar.bz2 matterbridge-msglm-0450482e6ebed8a379f2d43f0ee264ea0d130a31.zip |
Make lottie_convert work on platforms without /dev/stdout (#1424)
Fixes #1423.
Diffstat (limited to 'bridge/helper/helper.go')
-rw-r--r-- | bridge/helper/helper.go | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/bridge/helper/helper.go b/bridge/helper/helper.go index 2d16dc93..0ad31457 100644 --- a/bridge/helper/helper.go +++ b/bridge/helper/helper.go @@ -248,35 +248,52 @@ func CanConvertTgsToX() error { // This relies on an external command, which is ugly, but works. func ConvertTgsToX(data *[]byte, outputFormat string, logger *logrus.Entry) error { // lottie can't handle input from a pipe, so write to a temporary file: - tmpFile, err := ioutil.TempFile(os.TempDir(), "matterbridge-lottie-*.tgs") + tmpInFile, err := ioutil.TempFile(os.TempDir(), "matterbridge-lottie-input-*.tgs") if err != nil { return err } - tmpFileName := tmpFile.Name() + tmpInFileName := tmpInFile.Name() defer func() { - if removeErr := os.Remove(tmpFileName); removeErr != nil { - logger.Errorf("Could not delete temporary file %s: %v", tmpFileName, removeErr) + if removeErr := os.Remove(tmpInFileName); removeErr != nil { + logger.Errorf("Could not delete temporary (input) file %s: %v", tmpInFileName, removeErr) + } + }() + // lottie can handle writing to a pipe, but there is no way to do that platform-independently. + // "/dev/stdout" won't work on Windows, and "-" upsets Cairo for some reason. So we need another file: + tmpOutFile, err := ioutil.TempFile(os.TempDir(), "matterbridge-lottie-output-*.data") + if err != nil { + return err + } + tmpOutFileName := tmpOutFile.Name() + defer func() { + if removeErr := os.Remove(tmpOutFileName); removeErr != nil { + logger.Errorf("Could not delete temporary (output) file %s: %v", tmpOutFileName, removeErr) } }() - if _, writeErr := tmpFile.Write(*data); writeErr != nil { + if _, writeErr := tmpInFile.Write(*data); writeErr != nil { return writeErr } // Must close before calling lottie to avoid data races: - if closeErr := tmpFile.Close(); closeErr != nil { + if closeErr := tmpInFile.Close(); closeErr != nil { return closeErr } // Call lottie to transform: - cmd := exec.Command("lottie_convert.py", "--input-format", "lottie", "--output-format", outputFormat, tmpFileName, "/dev/stdout") + cmd := exec.Command("lottie_convert.py", "--input-format", "lottie", "--output-format", outputFormat, tmpInFileName, tmpOutFileName) + cmd.Stdout = nil cmd.Stderr = nil // NB: lottie writes progress into to stderr in all cases. - stdout, stderr := cmd.Output() + _, stderr := cmd.Output() if stderr != nil { // 'stderr' already contains some parts of Stderr, because it was set to 'nil'. return stderr } + dataContents, err := ioutil.ReadFile(tmpOutFileName) + if err != nil { + return err + } - *data = stdout + *data = dataContents return nil } |