aboutsummaryrefslogtreecommitdiffstats
path: root/config/general.go
diff options
context:
space:
mode:
authorJens Grassel <jens@wegtam.com>2024-07-13 09:22:40 +0200
committerRobin Jarry <robin@jarry.cc>2024-07-15 22:39:12 +0200
commitd2e2a3e290f98005e9715a7e752cd273fb4205a7 (patch)
treea2332085fd28bf7cb6efca94fc3821cf659db683 /config/general.go
parent5f8620445ed9686af8b2570e0d5860ef3b5ae4ff (diff)
downloadaerc-d2e2a3e290f98005e9715a7e752cd273fb4205a7.tar.gz
log: create directories if necessary
If a log file is configured via `log-file` and the parent directory does not exist then aerc exits with an error message on startup. Check if the directory for the log file exists and create it if necessary using sensible permissions (0700). Errors occurring while creating the directory structure are returned and printed out. Changelog-fixed: Startup error if `log-file` directory does not exist. Signed-off-by: Jens Grassel <jens@wegtam.com> Reviewed-by: Moritz Poldrack <moritz@poldrack.dev> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'config/general.go')
-rw-r--r--config/general.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/config/general.go b/config/general.go
index 6fd37dcf..e90deffe 100644
--- a/config/general.go
+++ b/config/general.go
@@ -3,6 +3,7 @@ package config
import (
"fmt"
"os"
+ "path/filepath"
"git.sr.ht/~rjarry/aerc/lib/log"
"git.sr.ht/~rjarry/aerc/lib/xdg"
@@ -39,6 +40,10 @@ func parseGeneral(file *ini.File) error {
} else if General.LogFile != "" {
var err error
path := xdg.ExpandHome(General.LogFile)
+ err = os.MkdirAll(filepath.Dir(path), 0o700)
+ if err != nil {
+ return fmt.Errorf("log-file: %w", err)
+ }
logFile, err = os.OpenFile(path,
os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o600)
if err != nil {