backend/http: rename stat to decodeMetadata

This commit is contained in:
Arnie97 2022-11-08 13:36:22 +08:00 committed by Nick Craig-Wood
parent 6a5b7664f7
commit 36c37ffec1

View File

@ -591,11 +591,11 @@ func (o *Object) head(ctx context.Context) error {
if err != nil { if err != nil {
return fmt.Errorf("failed to stat: %w", err) return fmt.Errorf("failed to stat: %w", err)
} }
return o.stat(ctx, res) return o.decodeMetadata(ctx, res)
} }
// stat updates info fields in the Object according to HTTP response headers // decodeMetadata updates info fields in the Object according to HTTP response headers
func (o *Object) stat(ctx context.Context, res *http.Response) error { func (o *Object) decodeMetadata(ctx context.Context, res *http.Response) error {
t, err := http.ParseTime(res.Header.Get("Last-Modified")) t, err := http.ParseTime(res.Header.Get("Last-Modified"))
if err != nil { if err != nil {
t = timeUnset t = timeUnset
@ -649,11 +649,8 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.Read
if err != nil { if err != nil {
return nil, fmt.Errorf("Open failed: %w", err) return nil, fmt.Errorf("Open failed: %w", err)
} }
if err = o.decodeMetadata(ctx, res); err != nil {
if o.fs.opt.NoHead { return nil, fmt.Errorf("decodeMetadata failed: %w", err)
if err = o.stat(ctx, res); err != nil {
return nil, fmt.Errorf("Stat failed: %w", err)
}
} }
return res.Body, nil return res.Body, nil
} }