fix: report mount not found only when all instances return 404

This commit is contained in:
Gabriel20xx committed 2026-10-08 11:28:14 +00:00
1 parent c7a3796f26
commit a14187a621
2 files changed
+93 -2

No files matched your search

+24 -2
View File
@@ -14,6 +14,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
@@ -264,9 +265,19 @@ func (c *Client) ProxyMount(w http.ResponseWriter, r *http.Request, project, mou
c.Proxy(w, r, path)
}
// ErrMountNotFound is returned by ListMountFiles when every CarrierNode
// instance that answered said the directory does not exist and none failed
// some other way. It is a definitive "not there", unlike an unreachable
// instance or an error response, where the directory may well exist but could
// not be checked - callers can use errors.Is to tell the two apart.
var ErrMountNotFound = errors.New("carriernode mount directory not found")
// ListMountFiles lists the direct children of a project/type mount directory.
// An empty relative path lists the mount root. The CarrierNode endpoint
// returns both files and directories so callers can build directory browsers.
// When no instance can list the directory, the error wraps ErrMountNotFound
// only if every instance answered 404; any unreachable instance or other
// failure yields a plain error instead, since the directory may live there.
func (c *Client) ListMountFiles(ctx context.Context, project, mountType, relative string) ([]MountFileEntry, error) {
candidates := c.candidateBaseURLs(ctx)
if len(candidates) == 0 {
@@ -286,6 +297,7 @@ func (c *Client) ListMountFiles(ctx context.Context, project, mountType, relativ
var entries []MountFileEntry
var lastErr error
loaded := false
missing := false
for _, baseURL := range candidates {
request, err := c.newRequest(ctx, baseURL, http.MethodGet, path, nil)
if err != nil {
@@ -297,6 +309,11 @@ func (c *Client) ListMountFiles(ctx context.Context, project, mountType, relativ
lastErr = err
continue
}
if response.StatusCode == http.StatusNotFound {
response.Body.Close()
missing = true
continue
}
if response.StatusCode != http.StatusOK {
response.Body.Close()
lastErr = fmt.Errorf("carriernode mount listing failed: %s", response.Status)
@@ -314,8 +331,13 @@ func (c *Client) ListMountFiles(ctx context.Context, project, mountType, relativ
loaded = true
entries = append(entries, payload.Files...)
}
if !loaded && lastErr != nil {
return nil, lastErr
if !loaded {
if lastErr != nil {
return nil, lastErr
}
if missing {
return nil, ErrMountNotFound
}
}
unique := make([]MountFileEntry, 0, len(entries))
seen := make(map[string]struct{}, len(entries))