MySQL  8.0.28
Source Code Documentation
mysqlrouter::AutoCleaner Class Reference

Automatic cleanup on scope exit utility class. More...

#include <auto_cleaner.h>

Public Member Functions

void add_file_delete (const std::string &file)
void add_directory_delete (const std::string &d, bool recursive=false)
void add_file_revert (const std::string &file)
void add_file_revert (const std::string &file, const std::string &backup_file)
void add_cleanup_callback (std::function< void()> callback) noexcept
void clear_cleanup_callbacks () noexcept
void remove (const std::string &file) noexcept
void clear ()
 AutoCleaner ()=default
 ~AutoCleaner ()
 AutoCleaner (AutoCleaner &&other) noexcept=default
AutoCleaneroperator= (AutoCleaner &&other)=default
 AutoCleaner (const AutoCleaner &)=delete
AutoCleaneroperator= (const AutoCleaner &)=delete

Private Types

enum  Type { Directory , DirectoryRecursive , File , FileBackup }

Private Attributes

std::vector< std::pair< std::string, std::pair< Type, std::string > > > files_
std::vector< std::function< void()> > callbacks_

Detailed Description

Automatic cleanup on scope exit utility class.

Automatic cleanup takes place on AutoCleaner object destruction. It allows to:

  • cleanup files
  • remove directories (non-recursive and recursive)
  • revert files from auto-managed backup file
  • revert files from a user provided backup file
  • call user provided callbacks Callbacks are called in order they were added into AutoCleaner. Files and directories are being deleted in a reverse order in which they were added to the AutoCleaner. If automatic cleanup fails (file or directory could not be deleted, failed to revert a file) a proper error is being logged and AutoCleaner continues with the next cleanup steps.

AutoCleaner allows to clear its state so that no action will be taken on scope exit (auto generated backup files will be cleaned up in such case).

Adding an action (cleanup, revert) is done once per file. It is not possible to add a second action for the same file (such add call will fail, initial action will not be affected). Adding a revert file action may fail if initial or backup files could not be opened.

Member Enumeration Documentation

◆ Type


Constructor & Destructor Documentation

◆ AutoCleaner() [1/3]

mysqlrouter::AutoCleaner::AutoCleaner ( )

◆ ~AutoCleaner()

mysqlrouter::AutoCleaner::~AutoCleaner ( )

◆ AutoCleaner() [2/3]

mysqlrouter::AutoCleaner::AutoCleaner ( AutoCleaner &&  other)

◆ AutoCleaner() [3/3]

mysqlrouter::AutoCleaner::AutoCleaner ( const AutoCleaner )

Member Function Documentation

◆ add_cleanup_callback()

void mysqlrouter::AutoCleaner::add_cleanup_callback ( std::function< void()>  callback)

◆ add_directory_delete()

void mysqlrouter::AutoCleaner::add_directory_delete ( const std::string &  d,
bool  recursive = false 

◆ add_file_delete()

void mysqlrouter::AutoCleaner::add_file_delete ( const std::string &  file)

◆ add_file_revert() [1/2]

void mysqlrouter::AutoCleaner::add_file_revert ( const std::string &  file)

◆ add_file_revert() [2/2]

void mysqlrouter::AutoCleaner::add_file_revert ( const std::string &  file,
const std::string &  backup_file 

◆ clear()

void mysqlrouter::AutoCleaner::clear ( )

◆ clear_cleanup_callbacks()

void mysqlrouter::AutoCleaner::clear_cleanup_callbacks ( )

◆ operator=() [1/2]

AutoCleaner& mysqlrouter::AutoCleaner::operator= ( AutoCleaner &&  other)

◆ operator=() [2/2]

AutoCleaner& mysqlrouter::AutoCleaner::operator= ( const AutoCleaner )

◆ remove()

void mysqlrouter::AutoCleaner::remove ( const std::string &  file)

Member Data Documentation

◆ callbacks_

std::vector<std::function<void()> > mysqlrouter::AutoCleaner::callbacks_

◆ files_

std::vector<std::pair<std::string, std::pair<Type, std::string> > > mysqlrouter::AutoCleaner::files_

The documentation for this class was generated from the following files: