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:
parent
0e0199aa98
commit
a13e1e75e2
15
core/core.go
15
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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user