mirror of
https://github.com/owncast/owncast.git
synced 2024-11-21 12:18:02 +03:00
Adjust CleanupDirectory function to support tmpfs mounts. (#3818)
* Refactored directory cleanup function to remove contents instead of recreating directory. * Fixed regression by ensuring directory cleanup creates directory if it does not exist. * Modified errors in directory cleanup function to provide more information. * Resolved use of deprecated package in directory cleanup function. * Reformatted directory cleanup function.
This commit is contained in:
parent
db1f64ee45
commit
3fc127ba34
1 changed files with 12 additions and 5 deletions
|
@ -302,14 +302,21 @@ func VerifyFFMpegPath(path string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CleanupDirectory removes the directory and makes it fresh again. Throws fatal error on failure.
|
// CleanupDirectory removes all contents within the directory, or creates it if it does not exist. Throws fatal error on failure.
|
||||||
func CleanupDirectory(path string) {
|
func CleanupDirectory(path string) {
|
||||||
log.Traceln("Cleaning", path)
|
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, 0o750); err != nil {
|
if err := os.MkdirAll(path, 0o750); err != nil {
|
||||||
log.Fatalln("Unable to create directory. Please check the ownership and permissions", err)
|
log.Fatalf("Unable to create '%s'. Please check the ownership and permissions: %s\n", path, err)
|
||||||
|
}
|
||||||
|
entries, err := os.ReadDir(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Unable to read contents of '%s'. Please check the ownership and permissions: %s\n", path, err)
|
||||||
|
}
|
||||||
|
for _, entry := range entries {
|
||||||
|
entryPath := filepath.Join(path, entry.Name())
|
||||||
|
if err := os.RemoveAll(entryPath); err != nil {
|
||||||
|
log.Fatalf("Unable to remove file or directory contained in '%s'. Please check the ownership and permissions: %s\n", path, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue