mirror of
https://github.com/owncast/owncast.git
synced 2024-12-23 01:31:10 +03:00
33 lines
619 B
Go
33 lines
619 B
Go
|
package ffmpeg
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
//VerifyFFMpegPath verifies that the path exists, is a file, and is executable
|
||
|
func VerifyFFMpegPath(path string) error {
|
||
|
stat, err := os.Stat(path)
|
||
|
|
||
|
if os.IsNotExist(err) {
|
||
|
return errors.New("ffmpeg path does not exist")
|
||
|
}
|
||
|
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("error while verifying the ffmpeg path: %s", err.Error())
|
||
|
}
|
||
|
|
||
|
if stat.IsDir() {
|
||
|
return errors.New("ffmpeg path can not be a folder")
|
||
|
}
|
||
|
|
||
|
mode := stat.Mode()
|
||
|
//source: https://stackoverflow.com/a/60128480
|
||
|
if mode&0111 == 0 {
|
||
|
return errors.New("ffmpeg path is not executable")
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|