Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

proper cleanup and permission check for the hls directory (#1167)

Meisam6db4766f0795
diff --git a/core/core.go b/core/core.go
index e0e8a2f98c..2bd5672d1c 100644
--- a/core/core.go
+++ b/core/core.go
@@ -114,22 +114,13 @@ func resetDirectories() {
log.Trace("Resetting file directories to a clean slate.")
// Wipe the public, web-accessible hls data directory
- os.RemoveAll(config.PublicHLSStoragePath)
- os.RemoveAll(config.PrivateHLSStoragePath)
- err := os.MkdirAll(config.PublicHLSStoragePath, 0777)
- if err != nil {
- log.Fatalln(err)
- }
-
- err = os.MkdirAll(config.PrivateHLSStoragePath, 0777)
- if err != nil {
- log.Fatalln(err)
- }
+ utils.CleanupDirectory(config.PublicHLSStoragePath)
+ utils.CleanupDirectory(config.PrivateHLSStoragePath)
// Remove the previous thumbnail
logo := data.GetLogoPath()
if utils.DoesFileExists(logo) {
- err = utils.Copy(path.Join("data", logo), filepath.Join(config.WebRoot, "thumbnail.jpg"))
+ err := utils.Copy(path.Join("data", logo), filepath.Join(config.WebRoot, "thumbnail.jpg"))
if err != nil {
log.Warnln(err)
}
diff --git a/core/transcoder/utils.go b/core/transcoder/utils.go
index dc5d7ffbbf..06376a8353 100644
--- a/core/transcoder/utils.go
+++ b/core/transcoder/utils.go
@@ -9,6 +9,7 @@ import (
"github.com/owncast/owncast/config"
"github.com/owncast/owncast/core/data"
+ "github.com/owncast/owncast/utils"
log "github.com/sirupsen/logrus"
)
@@ -91,6 +92,9 @@ func handleTranscoderMessage(message string) {
func createVariantDirectories() {
// Create private hls data dirs
+ utils.CleanupDirectory(config.PublicHLSStoragePath)
+ utils.CleanupDirectory(config.PrivateHLSStoragePath)
+
if len(data.GetStreamOutputVariants()) != 0 {
for index := range data.GetStreamOutputVariants() {
err := os.MkdirAll(path.Join(config.PrivateHLSStoragePath, strconv.Itoa(index)), 0777)
diff --git a/utils/utils.go b/utils/utils.go
index b0f3a992ef..5eecfd06cf 100644
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -226,3 +226,14 @@ func VerifyFFMpegPath(path string) error {
return nil
}
+
+// Removes the directory and makes it again. Throws fatal error on failure.
+func CleanupDirectory(path string) {
+ log.Traceln("Cleaning", path)
+ if err := os.RemoveAll(path); err != nil {
+ log.Fatalln("Unable to remove directory. Please check the ownership and permissions", err)
+ }
+ if err := os.MkdirAll(path, 0777); err != nil {
+ log.Fatalln("Unable to create directory. Please check the ownership and permissions", err)
+ }
+}
\ No newline at end of file