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

* check error on hls cleanup

* rm HLS directories before creating new ones

* don't mask the variable

* mv cleanupDirectory() to utils

* add user-friendly error messages
This commit is contained in:
Meisam 2021-07-08 21:35:53 +02:00 committed by GitHub
parent 0e0199aa98
commit a13e1e75e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 12 deletions

View file

@ -114,22 +114,13 @@ func resetDirectories() {
log.Trace("Resetting file directories to a clean slate.") log.Trace("Resetting file directories to a clean slate.")
// Wipe the public, web-accessible hls data directory // Wipe the public, web-accessible hls data directory
os.RemoveAll(config.PublicHLSStoragePath) utils.CleanupDirectory(config.PublicHLSStoragePath)
os.RemoveAll(config.PrivateHLSStoragePath) utils.CleanupDirectory(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)
}
// Remove the previous thumbnail // Remove the previous thumbnail
logo := data.GetLogoPath() logo := data.GetLogoPath()
if utils.DoesFileExists(logo) { 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 { if err != nil {
log.Warnln(err) log.Warnln(err)
} }

View file

@ -9,6 +9,7 @@ import (
"github.com/owncast/owncast/config" "github.com/owncast/owncast/config"
"github.com/owncast/owncast/core/data" "github.com/owncast/owncast/core/data"
"github.com/owncast/owncast/utils"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -91,6 +92,9 @@ func handleTranscoderMessage(message string) {
func createVariantDirectories() { func createVariantDirectories() {
// Create private hls data dirs // Create private hls data dirs
utils.CleanupDirectory(config.PublicHLSStoragePath)
utils.CleanupDirectory(config.PrivateHLSStoragePath)
if len(data.GetStreamOutputVariants()) != 0 { if len(data.GetStreamOutputVariants()) != 0 {
for index := range data.GetStreamOutputVariants() { for index := range data.GetStreamOutputVariants() {
err := os.MkdirAll(path.Join(config.PrivateHLSStoragePath, strconv.Itoa(index)), 0777) err := os.MkdirAll(path.Join(config.PrivateHLSStoragePath, strconv.Itoa(index)), 0777)

View file

@ -226,3 +226,14 @@ func VerifyFFMpegPath(path string) error {
return nil 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)
}
}