fix: don't delete server dir on cleanup if not empty

Part of coop-cloud/organising#325.
This commit is contained in:
2023-01-23 13:56:27 +01:00
parent a93786c6be
commit 27e0708ac7
3 changed files with 16 additions and 4 deletions

View File

@ -80,7 +80,19 @@ func cleanUp(domainName string) {
}
logrus.Warnf("cleaning up server directory for %s", domainName)
if err := os.RemoveAll(filepath.Join(config.SERVERS_DIR, domainName)); err != nil {
serverDir := filepath.Join(config.SERVERS_DIR, domainName)
files, err := config.GetAllFilesInDirectory(serverDir)
if err != nil {
logrus.Fatalf("unable to list files in %s: %s", serverDir, err)
}
if len(files) > 0 {
logrus.Warnf("aborting clean up of %s because it is not empty", serverDir)
return
}
if err := os.RemoveAll(serverDir); err != nil {
logrus.Fatal(err)
}
}