MCPcopy
hub / github.com/rclone/rclone / readMetaDataForPath

Method readMetaDataForPath

backend/webdav/webdav.go:344–393  ·  view source on GitHub ↗

readMetaDataForPath reads the metadata from the path

(ctx context.Context, path string)

Source from the content-addressed store, hash-verified

342
343// readMetaDataForPath reads the metadata from the path
344func (f *Fs) readMetaDataForPath(ctx context.Context, path string) (info *api.Prop, err error) {
345 // FIXME how do we read back additional properties?
346 opts := rest.Opts{
347 Method: "PROPFIND",
348 Path: f.filePath(path),
349 ExtraHeaders: map[string]string{
350 "Depth": "0",
351 },
352 CheckRedirect: rest.PreserveMethodRedirectFn,
353 }
354 if f.hasOCMD5 || f.hasOCSHA1 {
355 opts.Body = bytes.NewBuffer(owncloudProps)
356 } else if f.useStandardProps {
357 opts.Body = bytes.NewBuffer(standardProps)
358 }
359 // Note: According to WebDAV RFC 4918, empty PROPFIND body defaults to allprop
360 var result api.Multistatus
361 var resp *http.Response
362 err = f.pacer.Call(func() (bool, error) {
363 resp, err = f.srv.CallXML(ctx, &opts, nil, &result)
364 return f.shouldRetry(ctx, resp, err)
365 })
366 if apiErr, ok := err.(*api.Error); ok {
367 // does not exist
368 switch apiErr.StatusCode {
369 case http.StatusNotFound:
370 return nil, fs.ErrorObjectNotFound
371 case http.StatusMovedPermanently, http.StatusFound, http.StatusSeeOther:
372 // Some sort of redirect - go doesn't deal with these properly (it resets
373 // the method to GET). However we can assume that if it was redirected the
374 // object was not found.
375 return nil, fs.ErrorObjectNotFound
376 }
377 }
378 if err != nil {
379 return nil, fmt.Errorf("read metadata failed: %w", err)
380 }
381 if len(result.Responses) < 1 {
382 return nil, fs.ErrorObjectNotFound
383 }
384 item := result.Responses[0]
385 // status code 425 is accepted here as well
386 if !(item.Props.StatusOK() || item.Props.Code() == 425) {
387 return nil, fs.ErrorObjectNotFound
388 }
389 if itemIsDir(&item) {
390 return nil, fs.ErrorIsDir
391 }
392 return &item.Props, nil
393}
394
395// errorHandler parses a non 2xx error response into an error
396func errorHandler(resp *http.Response) error {

Callers 2

purgeCheckMethod · 0.95
readMetaDataMethod · 0.45

Calls 8

filePathMethod · 0.95
shouldRetryMethod · 0.95
itemIsDirFunction · 0.85
CallXMLMethod · 0.80
StatusOKMethod · 0.80
CodeMethod · 0.80
CallMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected