LLFIO  v2.00
llfio_v2_xxx::algorithm::contents_visitor Struct Reference

A visitor for the filesystem contents algorithm. More...

#include "contents.hpp"

Inheritance diagram for llfio_v2_xxx::algorithm::contents_visitor:
llfio_v2_xxx::algorithm::traverse_visitor

Classes

struct  _state_type
 
struct  contents_type
 Enumerated contents, and what parts of their stat_t is valid. More...
 

Public Member Functions

 contents_visitor ()=default
 Default construtor.
 
 contents_visitor (stat_t::want _metadata, bool _include_files=true, bool _include_directories=true, bool _include_symlinks=true)
 Construct an instance.
 
virtual result< void > post_enumeration (void *data, const directory_handle &dirh, directory_handle::buffers_type &contents, size_t depth) noexcept
 The default implementation accumulates the contents into thread local storage. At traverse end, all the thread local storages are coalesced into a single result, the member variable contents.
 
virtual result< size_t > finished (void *data, result< size_t > result) noexcept
 Called when a traversal finishes, this default implementation merges all the thread local results into contents, and deallocates the thread local results.
 
virtual result< directory_handledirectory_open_failed (void *data, result< void >::error_type &&error, const directory_handle &dirh, path_view leaf, size_t depth) noexcept
 Called when we failed to open a directory for enumeration. The default fails the traversal with that error. Return a default constructed instance to ignore the failure. More...
 
virtual result< bool > pre_enumeration (void *data, const directory_handle &dirh, size_t depth) noexcept
 Called to decide whether to enumerate a directory. More...
 
virtual result< void > stack_updated (void *data, size_t dirs_processed, size_t known_dirs_remaining, size_t depth_processed, size_t known_depth_remaining) noexcept
 Called whenever the traversed stack of directory hierarchy is updated. This can act as an estimated progress indicator, or to give an accurate progress indicator by matching it against a previous traversal. More...
 

Public Attributes

bool contents_include_files {true}
 Whether to include files in the contents.
 
bool contents_include_directories {true}
 Whether to include directories in the contents.
 
bool contents_include_symlinks {true}
 Whether to include symlinks in the contents.
 
stat_t::want contents_include_metadata {stat_t::want::none}
 What stat_t::want to include, if enumeration doesn't provide these, they will be additionally fetched.
 

Static Protected Member Functions

static std::shared_ptr< contents_type_thread_contents (_state_type *state) noexcept
 

Friends

result< contents_typecontents (const path_handle &dirh, contents_visitor *visitor, size_t threads, bool force_slow_path) noexcept
 Calculate the contents of everything within and under dirh. What is returned is unordered. More...
 

Detailed Description

A visitor for the filesystem contents algorithm.

Member Function Documentation

◆ directory_open_failed()

virtual result<directory_handle> llfio_v2_xxx::algorithm::traverse_visitor::directory_open_failed ( void *  data,
result< void >::error_type &&  error,
const directory_handle dirh,
path_view  leaf,
size_t  depth 
)
inlinevirtualnoexceptinherited

Called when we failed to open a directory for enumeration. The default fails the traversal with that error. Return a default constructed instance to ignore the failure.

Note
May be called from multiple kernel threads concurrently.

Reimplemented in llfio_v2_xxx::algorithm::summarize_visitor, and llfio_v2_xxx::algorithm::reduce_visitor.

54  {
55  (void) data;
56  (void) dirh;
57  (void) leaf;
58  (void) depth;
59  return failure(std::move(error));
60  }

◆ pre_enumeration()

virtual result<bool> llfio_v2_xxx::algorithm::traverse_visitor::pre_enumeration ( void *  data,
const directory_handle dirh,
size_t  depth 
)
inlinevirtualnoexceptinherited

Called to decide whether to enumerate a directory.

Note that it is more efficient to ignore the directory entry in post_enumeration() than to ignore it here, as a handle is opened for the directory before this callback. Equally, if you need that handle to inspect the directory e.g. to check if one is entering a different filesystem from the root, here is best.

The default returns true.

Note
May be called from multiple kernel threads concurrently.
75  {
76  (void) data;
77  (void) dirh;
78  (void) depth;
79  return true;
80  }

◆ stack_updated()

virtual result<void> llfio_v2_xxx::algorithm::traverse_visitor::stack_updated ( void *  data,
size_t  dirs_processed,
size_t  known_dirs_remaining,
size_t  depth_processed,
size_t  known_depth_remaining 
)
inlinevirtualnoexceptinherited

Called whenever the traversed stack of directory hierarchy is updated. This can act as an estimated progress indicator, or to give an accurate progress indicator by matching it against a previous traversal.

Parameters
dataThe third party data pointer passed to traverse().
dirs_processedThe total number of directories traversed so far.
known_dirs_remainingThe currently known number of directories awaiting traversal.
depth_processedHow many levels deep we have already completely traversed.
known_depth_remainingThe currently known number of levels we shall traverse.
Note
May be called from multiple kernel threads concurrently.
116  {
117  (void) data;
118  (void) dirs_processed;
119  (void) known_dirs_remaining;
120  (void) depth_processed;
121  (void) known_depth_remaining;
122  return success();
123  }

Friends And Related Function Documentation

◆ contents

result<contents_type> contents ( const path_handle dirh,
contents_visitor visitor = nullptr,
size_t  threads = 0,
bool  force_slow_path = false 
)
friend

Calculate the contents of everything within and under dirh. What is returned is unordered.

This is a very thin veneer over traverse() which came out of the fact that I kept writing "get me the contents" traversal visitors again and again, so eventually I just wrote a library edition. Its only "clever" bit is that it stores the contents in thread local storage, and merges the contents afterwards.

It is race free to concurrent relocations of dirh. It is entirely implemented in header-only code, as it is very simple.

225  {
226  contents_visitor default_visitor;
227  if(visitor == nullptr)
228  {
229  visitor = &default_visitor;
230  }
231  contents_visitor::_state_type state(dirh);
232  OUTCOME_TRY(auto &&dirhpath, dirh.current_path());
233  state.rootdirpathlen.store(dirhpath.native().size() + 1, std::memory_order_relaxed);
234  OUTCOME_TRY(traverse(dirh, visitor, threads, &state, force_slow_path));
235  return {std::move(state.contents)};
236  }
result< size_t > traverse(const path_handle &dirh, traverse_visitor *visitor, size_t threads=0, void *data=nullptr, bool force_slow_path=false) noexcept
Traverse everything within and under dirh.
contents_visitor()=default
Default construtor.

The documentation for this struct was generated from the following file: