Refactored directory cleanup function to remove contents instead of recreating directory.
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@@ -302,14 +303,18 @@ 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. 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 {
|
entries, err := ioutil.ReadDir(path)
|
||||||
log.Fatalln("Unable to remove directory. Please check the ownership and permissions", err)
|
if err != nil {
|
||||||
|
log.Fatalln("Unable to read contents of directory. Please check the ownership and permissions", err)
|
||||||
}
|
}
|
||||||
if err := os.MkdirAll(path, 0o750); err != nil {
|
for _, entry := range entries {
|
||||||
log.Fatalln("Unable to create directory. Please check the ownership and permissions", err)
|
entryPath := filepath.Join(path, entry.Name())
|
||||||
|
if err := os.RemoveAll(entryPath); err != nil {
|
||||||
|
log.Fatalln("Unable to remove directory. Please check the ownership and permissions", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user