Skip to content

Commit 6ec1a41

Browse files
committed
Check for required executables before desadulate does its work
1 parent e1a41dc commit 6ec1a41

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tools/desadulate/desadulate.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"io/ioutil"
1717
"log"
1818
"os"
19+
"os/exec"
1920
"path/filepath"
2021
"sort"
2122
"strings"
@@ -46,6 +47,17 @@ var allowedExtensions = []string{
4647

4748
// TODO: Fail if inpath === outpath?
4849

50+
func checkExecutables() {
51+
var err error
52+
commands := []string{"unrar", "unzip", "zip"}
53+
for _, cmd := range commands {
54+
_, err = exec.LookPath(cmd)
55+
if err != nil {
56+
log.Fatalf("Error: Cannot find executable '%s'\n", cmd)
57+
}
58+
}
59+
}
60+
4961
func parseCommandLineFlags() {
5062
flag.StringVar(&inpath, "i", "", "Base path of the input directory (required)")
5163
flag.StringVar(&infile, "f", "", "Path of the input file relative to the input directory (required)")
@@ -152,6 +164,7 @@ func getOutWriter() io.Writer {
152164
func main() {
153165
parseCommandLineFlags()
154166
resolveFilenames()
167+
checkExecutables()
155168

156169
if verboseMode {
157170
fmt.Printf("betterize: inpath is '%s'\n", inpath)

0 commit comments

Comments
 (0)