// Lists the directory required calling the user function on each item found
//
// If the user fn ever returns true then it early exits with found = true
Lists the directory required calling the user function on each item found

If the user fn ever returns true then it early exits with found = true
// Lists the directory required calling the user function on each item found // // If the user fn ever returns true then it early exits with found = true
func (f *Fs) listAll(dir string, directoriesOnly bool, filesOnly bool, depth string, fn listAllFn) (found bool, err error) {
	opts := rest.Opts{
		Method: "PROPFIND",
		Path:   f.dirPath(dir), 
		ExtraHeaders: map[string]string{
			"Depth": depth,
		},
	}
	var result api.Multistatus
	var resp *http.Response
	err = f.pacer.Call(func() (bool, error) {
		resp, err = f.srv.CallXML(&opts, nil, &result)
		return shouldRetry(resp, err)
	})
	if err != nil {
		if apiErr, ok := err.(*api.Error); ok {
			if apiErr.StatusCode == http.StatusNotFound {
				if f.retryWithZeroDepth && depth != "0" {
					return f.listAll(dir, directoriesOnly, filesOnly, "0", fn)
				}
				return found, fs.ErrorDirNotFound
			}
		}
		return found, errors.Wrap(err, "couldn't list files")
	}
	baseURL, err := rest.URLJoin(f.endpoint, opts.Path)
	if err != nil {
		return false, errors.Wrap(err, "couldn't join URL")
	}
	for i := range result.Responses {
		item := &result.Responses[i]
		isDir := itemIsDir(item)
		u, err := rest.URLJoin(baseURL, item.Href)
		if err != nil {
			fs.Errorf(nil, "URL Join failed for %q and %q: %v", baseURL, item.Href, err)
			continue
		}
		if isDir {
			u.Path = addSlash(u.Path)
		}
		if !strings.HasPrefix(u.Path, baseURL.Path) {
			fs.Debugf(nil, "Item with unknown path received: %q, %q", u.Path, baseURL.Path)
			continue
		}
		remote := path.Join(dir, u.Path[len(baseURL.Path):])
		if strings.HasSuffix(remote, "/") {
			remote = remote[:len(remote)-1]
		}
		if remote == dir {
			continue
		}
		if !item.Props.StatusOK() {
			fs.Debugf(remote, "Ignoring item with bad status %q", item.Props.Status)
			continue
		}
		if isDir {
			if filesOnly {
				continue
			}
		} else {
			if directoriesOnly {
				continue
			}
		}
		if fn(remote, isDir, &item.Props) {
			found = true
			break
		}
	}
	return
}
func ( f * Fs ) listAll ( dir string , directoriesOnly bool , filesOnly bool , depth string , fn listAllFn ) ( found bool , err error ) { opts := rest . Opts { Method : " " , Path : f . dirPath ( dir ) , ExtraHeaders : map [ string ] string { " " : depth , } , } var result api . Multistatus var resp * http . Response err = f . pacer . Call ( func ( ) ( bool , error ) { resp , err = f . srv . CallXML ( & opts , nil , & result ) return shouldRetry ( resp , err ) } ) if err != nil { if apiErr , ok := err . ( * api . Error ) ; ok { if apiErr . StatusCode == http . StatusNotFound { if f . retryWithZeroDepth && depth != " " { return f . listAll ( dir , directoriesOnly , filesOnly , " " , fn ) } return found , fs . ErrorDirNotFound } } return found , errors . Wrap ( err , " " ) } baseURL , err := rest . URLJoin ( f . endpoint , opts . Path ) if err != nil { return false , errors . Wrap ( err , " " ) } for i := range result . Responses { item := & result . Responses [ i ] isDir := itemIsDir ( item ) u , err := rest . URLJoin ( baseURL , item . Href ) if err != nil { fs . Errorf ( nil , " " , baseURL , item . Href , err ) continue } if isDir { u . Path = addSlash ( u . Path ) } if ! strings . HasPrefix ( u . Path , baseURL . Path ) { fs . Debugf ( nil , " " , u . Path , baseURL . Path ) continue } remote := path . Join ( dir , u . Path [ len ( baseURL . Path ) : ] ) if strings . HasSuffix ( remote , " " ) { remote = remote [ : len ( remote ) - 1 ] } if remote == dir { continue } if ! item . Props . StatusOK ( ) { fs . Debugf ( remote , " " , item . Props . Status ) continue } if isDir { if filesOnly { continue } } else { if directoriesOnly { continue } } if fn ( remote , isDir , & item . Props ) { found = true break } } return }
Lists the directory required calling the user function on each item found
Lists the directory required calling the user function on each item found
// FIXME Should not start with / // does not exist //fmt.Printf("result = %#v", &result) // Find name // Make sure directories end with a / // the listing contains info about itself which we ignore // Check OK // 	item.Name = restoreReservedChars(item.Name)