This commit is contained in:
@@ -76,19 +76,29 @@ func (a *App) handleCreatePool(w http.ResponseWriter, r *http.Request) {
|
||||
req.Options = make(map[string]string)
|
||||
}
|
||||
|
||||
if err := a.zfs.CreatePool(req.Name, req.VDEVs, req.Options); err != nil {
|
||||
err := a.zfs.CreatePool(req.Name, req.VDEVs, req.Options)
|
||||
|
||||
// Always check if pool exists, even if creation reported an error
|
||||
// Sometimes pool is created despite errors (e.g., mountpoint issues)
|
||||
pool, getErr := a.zfs.GetPool(req.Name)
|
||||
if getErr == nil {
|
||||
// Pool exists - return success even if creation reported an error
|
||||
if err != nil {
|
||||
log.Printf("create pool reported error but pool exists: %v", err)
|
||||
}
|
||||
writeJSON(w, http.StatusCreated, pool)
|
||||
return
|
||||
}
|
||||
|
||||
// Pool doesn't exist - return the error
|
||||
if err != nil {
|
||||
log.Printf("create pool error: %v", err)
|
||||
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
pool, err := a.zfs.GetPool(req.Name)
|
||||
if err != nil {
|
||||
writeJSON(w, http.StatusCreated, map[string]string{"message": "pool created", "name": req.Name})
|
||||
return
|
||||
}
|
||||
|
||||
writeJSON(w, http.StatusCreated, pool)
|
||||
// No error but pool doesn't exist (shouldn't happen, but handle it)
|
||||
writeJSON(w, http.StatusCreated, map[string]string{"message": "pool created", "name": req.Name})
|
||||
}
|
||||
|
||||
func (a *App) handleGetPool(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user