Ensure data dir is present

This commit is contained in:
Ben Sarmiento
2023-11-21 10:44:13 +01:00
parent cbf14e953f
commit f2922ea7b4
3 changed files with 22 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ package torrent
import (
"fmt"
"os"
"strings"
)
@@ -22,3 +23,15 @@ func isStreamable(filePath string) bool {
strings.HasSuffix(filePath, ".wmv") ||
strings.HasSuffix(filePath, ".m4v")
}
func ensureDir(dirName string) error {
if _, err := os.Stat(dirName); os.IsNotExist(err) {
err := os.Mkdir(dirName, 0755)
if err != nil {
return err
}
} else if err != nil {
return err
}
return nil
}