LLFIO
v2.00
|
Adapts any construct()
-able implementation to cache its parent directory handle in a process wide cache.
More...
#include "cached_parent.hpp"
Public Types | |
using | adapted_handle_type = T |
The handle type being adapted. | |
using | path_type = typename T::path_type |
using | path_view_type = typename T::path_view_type |
Public Member Functions | |
cached_parent_handle_adapter (const cached_parent_handle_adapter &)=default | |
cached_parent_handle_adapter (cached_parent_handle_adapter &&)=default | |
cached_parent_handle_adapter & | operator= (const cached_parent_handle_adapter &)=default |
cached_parent_handle_adapter & | operator= (cached_parent_handle_adapter &&o) noexcept |
cached_parent_handle_adapter (adapted_handle_type &&o, const path_handle &base, path_view path) | |
virtual result< path_type > | current_path () const noexcept override |
virtual result< void > | close () noexcept override |
virtual native_handle_type | release () noexcept override |
virtual result< path_handle > | parent_path_handle (deadline=std::chrono::seconds(30)) const noexcept override |
virtual result< void > | relink (const path_handle &base, path_view_type newpath, bool atomic_replace=true, deadline d=std::chrono::seconds(30)) noexcept override |
virtual result< void > | unlink (deadline d=std::chrono::seconds(30)) noexcept override |
Protected Attributes | |
detail::cached_path_handle_ptr | _sph |
filesystem::path | _leafname |
Adapts any construct()
-able implementation to cache its parent directory handle in a process wide cache.
For some use cases where one is calling parent_path_handle()
or code which calls that function very frequently e.g. calling relink()
or unlink()
a lot on many files with the same parent directory, having to constantly fetch the current path, open the parent directory and verify inodes becomes unhelpfully inefficient. This adapter keeps a process-wide hash table of directory handles shared between all instances of this adapter, thus making calling parent_path_handle()
almost zero cost.
This adapter is of especial use on platforms which do not reliably implement per-fd path tracking for regular files (Apple MacOS, FreeBSD) as current_path()
is reimplemented to use the current path of the shared parent directory instead. One loses race freedom within the contained directory, but that is the case on POSIX anyway.
This adapter is also of use on platforms which do not implement path tracking for open handles at all (e.g. Linux without /proc
mounted) as the process-wide cache of directory handles retains the path of the directory handle at the time of creation. Third party changes to the part of the filesystem you are working upon will result in the inability to do race free unlinking etc, but if no third party changes are encountered it ought to work well.