mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-16 14:27:01 +00:00
chasquid-util: Fix creating the directory on user-add
`chasquid-util user-add` is meant to create the domain directory if it doesn't exist; however there's a bug that makes this not happen, and instead the command fails with: Error writing database: open <path>: no such file or directory This patch fixes the issue and adds a test to ensure we don't have any regressions on this behaviour. Thanks to raspbeguy (https://github.com/raspbeguy) for reporting this issue (on IRC).
This commit is contained in:
@@ -4,7 +4,9 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@@ -126,19 +128,22 @@ func userDBFromArgs(create bool) (string, string, *userdb.DB) {
|
||||
Fatalf("Domain missing, username should be of the form 'user@domain'")
|
||||
}
|
||||
|
||||
db, err := userdb.Load(userDBForDomain(domain))
|
||||
if err != nil {
|
||||
if create && os.IsNotExist(err) {
|
||||
if create {
|
||||
dbDir := filepath.Dir(userDBForDomain(domain))
|
||||
if _, err := os.Stat(dbDir); errors.Is(err, fs.ErrNotExist) {
|
||||
fmt.Println("Creating database")
|
||||
err = os.MkdirAll(filepath.Dir(userDBForDomain(domain)), 0755)
|
||||
err = os.MkdirAll(dbDir, 0755)
|
||||
if err != nil {
|
||||
Fatalf("Error creating database dir: %v", err)
|
||||
}
|
||||
} else {
|
||||
Fatalf("Error loading database: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
db, err := userdb.Load(userDBForDomain(domain))
|
||||
if err != nil {
|
||||
Fatalf("Error loading database: %v", err)
|
||||
}
|
||||
|
||||
user, err = normalize.User(user)
|
||||
if err != nil {
|
||||
Fatalf("Error normalizing user: %v", err)
|
||||
|
||||
@@ -25,13 +25,15 @@ function check_userdb() {
|
||||
|
||||
|
||||
rm -rf .config/
|
||||
mkdir -p .config/domains/domain/ .data/domaininfo
|
||||
mkdir -p .config/ .data/domaininfo
|
||||
echo 'data_dir: ".data"' >> .config/chasquid.conf
|
||||
|
||||
if ! r print-config > /dev/null; then
|
||||
fail print-config
|
||||
fi
|
||||
|
||||
# We intentionally run this when the domain directory doesn't exist, as we
|
||||
# want to confirm it creates it.
|
||||
if ! r user-add interactive@domain --password=passwd > /dev/null; then
|
||||
fail user-add
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user