TSDuck v3.44-4556
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::FileTreeManager Class Reference

Manages a tree of files, save and cleanup. More...

#include <tsFileTreeManager.h>

Public Member Functions

 FileTreeManager (Report &report)
 Constructor.
 
bool cleanupOldFiles (const Time &current=Time::CurrentUTC())
 Force a cleanup of all files to delete.
 
bool saveFile (const ByteBlock &content, const UString &filename, UChar replacement='_', const Time &current=Time::CurrentUTC())
 Save a file into the file tree.
 
template<class Rep , class Period >
void setDeleteAfter (cn::duration< Rep, Period > age)
 Set the maximum retention time of saved files.
 
void setRootDirectory (const fs::path &root)
 Set the root directory of files to save and cleanup.
 

Detailed Description

Manages a tree of files, save and cleanup.

Constructor & Destructor Documentation

◆ FileTreeManager()

ts::FileTreeManager::FileTreeManager ( Report report)

Constructor.

Parameters
[in,out]reportWhere to report errors and messages.

Member Function Documentation

◆ setRootDirectory()

void ts::FileTreeManager::setRootDirectory ( const fs::path &  root)
inline

Set the root directory of files to save and cleanup.

If no root directory is specified, no file can be saved. By default, there is no initial root directory.

Parameters
[in]rootRoot directory.

◆ setDeleteAfter()

template<class Rep , class Period >
void ts::FileTreeManager::setDeleteAfter ( cn::duration< Rep, Period >  age)
inline

Set the maximum retention time of saved files.

Parameters
[in]ageThe maximum duration of a file, after being saved. When zero (the initial default), files are never deleted.

◆ cleanupOldFiles()

bool ts::FileTreeManager::cleanupOldFiles ( const Time current = Time::CurrentUTC())

Force a cleanup of all files to delete.

Parameters
[in]currentHypothetical current UTC time. By default, use the current UTC time. This parameter can be used to simulate a later time and force deletion of files.
Returns
True on success, false on error.

◆ saveFile()

bool ts::FileTreeManager::saveFile ( const ByteBlock content,
const UString filename,
UChar  replacement = '_',
const Time current = Time::CurrentUTC() 
)

Save a file into the file tree.

Parameters
[in]contentBinary content to save.
[in]filenameA relative path of the file to save. The path is sanitized first:
  • All invalid characters (for the current filesystem) are replaced with replacement.
  • All attempts to move upward in the file system hierarchy ("..") are removed.
  • If filename starts with an URI scheme, it is removed.
  • If the file path is absolute, it is relocated under the root directory of the file tree.
[in]replacementThe replacement character for invalid characters.
[in]currentHypothetical current UTC time. By default, use the current UTC time. This parameter can be used to simulate a later time and force deletion of files.
Returns
True on success, false on error.

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