Mantis App v0.2.8
Loading...
Searching...
No Matches
mantis::FileUnit Class Reference

Handle file management for record type files. More...

#include <fileunit.h>

Public Member Functions

 FileUnit ()=default
 
void createDir (const std::string &table) const
 Create a directory matching passed in table name.
 
void renameDir (const std::string &old_name, const std::string &new_name) const
 Rename existing directory if found or create it if not found.
 
void deleteDir (const std::string &table) const
 Delete table directory and its contents.
 
std::string dirPath (const std::string &table, bool create_if_missing=false) const
 Fetch directory path string for a given table.
 
std::string filePath (const std::string &table, const std::string &filename) const
 Fetch absolute path to where file is or would be for a given table and filename.
 
std::optional< std::string > getFilePath (const std::string &table, const std::string &filename) const
 Fetch filename absolute path only if the file exists, else, return empty response.
 
bool removeFile (const std::string &table, const std::string &filename) const
 Remove existing file given the table and filename.
 

Detailed Description

Handle file management for record type files.

These files are the usual file assets stored in either file or files filed type. The idea here being, the file is stored on disk and the name saved to the database.

The class should handle:

  • Creating & deleting folders
  • Creating & deleting file resources as needed.
  • Updating folder names when tables are renamed
  • Deleting folder contents for dropped

Constructor & Destructor Documentation

◆ FileUnit()

mantis::FileUnit::FileUnit ( )
default

Member Function Documentation

◆ createDir()

void mantis::FileUnit::createDir ( const std::string &  table) const

Create a directory matching passed in table name.

Parameters
tableTable name to created directory for

◆ deleteDir()

void mantis::FileUnit::deleteDir ( const std::string &  table) const

Delete table directory and its contents.

Parameters
tableTable name

◆ dirPath()

std::string mantis::FileUnit::dirPath ( const std::string &  table,
bool  create_if_missing = false 
) const

Fetch directory path string for a given table.

Parameters
tableTable name
create_if_missingBool status to know whether to create directory if missing
Returns
Absolute path to a directory for the passed in table

◆ filePath()

std::string mantis::FileUnit::filePath ( const std::string &  table,
const std::string &  filename 
) const

Fetch absolute path to where file is or would be for a given table and filename.

Parameters
tableTable name
filenameFile name
Returns
Absolute path to the given filename and table name.

◆ getFilePath()

std::optional< std::string > mantis::FileUnit::getFilePath ( const std::string &  table,
const std::string &  filename 
) const

Fetch filename absolute path only if the file exists, else, return empty response.

Parameters
tableTable name
filenameFIle name
Returns
Absolute filepath or none if filename does not exist in the table directory.
See also
filePath() above.

◆ removeFile()

bool mantis::FileUnit::removeFile ( const std::string &  table,
const std::string &  filename 
) const

Remove existing file given the table and filename.

Parameters
tableTable name
filenameFile name
Returns
Status whether file deletion succeeded.

◆ renameDir()

void mantis::FileUnit::renameDir ( const std::string &  old_name,
const std::string &  new_name 
) const

Rename existing directory if found or create it if not found.

Parameters
old_nameOld table name
new_nameNew table name

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