Skip to content

Commit

Permalink
Better error checks in config initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
anfragment committed Apr 1, 2024
1 parent 3702196 commit 93c92c9
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ func init() {
log.Fatalf("failed to get config dir: %v", err)
}
stat, err := os.Stat(ConfigDir)
if err != nil {
if os.IsNotExist(err) {
if err := os.MkdirAll(ConfigDir, 0755); err != nil {
log.Fatalf("failed to create config dir: %v", err)
}
stat, err = os.Stat(ConfigDir)
} else {
log.Fatalf("failed to stat config dir: %v", err)
if os.IsNotExist(err) {
if err := os.MkdirAll(ConfigDir, 0755); err != nil {
log.Fatalf("failed to create config dir: %v", err)
}
stat, err = os.Stat(ConfigDir)
}
if err != nil {
log.Fatalf("failed to stat config dir: %v", err)
}
if !stat.IsDir() {
log.Fatalf("config dir is not a directory: %s", ConfigDir)
Expand All @@ -74,15 +73,14 @@ func init() {
log.Fatalf("failed to get data dir: %v", err)
}
stat, err = os.Stat(DataDir)
if err != nil {
if os.IsNotExist(err) {
if err := os.MkdirAll(DataDir, 0755); err != nil {
log.Fatalf("failed to create data dir: %v", err)
}
stat, err = os.Stat(DataDir)
} else {
log.Fatalf("failed to stat data dir: %v", err)
if os.IsNotExist(err) {
if err := os.MkdirAll(DataDir, 0755); err != nil {
log.Fatalf("failed to create data dir: %v", err)
}
stat, err = os.Stat(DataDir)
}
if err != nil {
log.Fatalf("failed to stat data dir: %v", err)
}
if !stat.IsDir() {
log.Fatalf("data dir is not a directory: %s", DataDir)
Expand Down

0 comments on commit 93c92c9

Please sign in to comment.