25 throw(
INTERNAL_ERROR(0,
"Attempt to allocate multiple vault managers"));
63 configuration_manager::vaults_type::const_iterator vi;
70 TRY_nomem(es =
"Could not select a vault");
81 subdirectory::iterator sdi;
84 for (sdi = subdir.begin(); sdi != subdir.end(); sdi++) {
88 TRY_nomem(lstr =
"Existing archive directory found in vault: \"");
101 TRY_nomem(es =
"Could not lock vault: \"");
106 TRY_nomem(es =
"Vault is locked by PID: ");
120 TRY_nomem(lstr =
"Existing archive directory found in vault: \"");
133 TRY_nomem(es =
"Could not lock vault: \"");
138 TRY_nomem(es =
"Vault is locked by PID: ");
156 std::pair<std::string,std::string> youngest;
165 subdirectory::iterator sdi;
175 TRY_nomem(lstr =
"Skipping locked vault: \"");
185 for (sdi = subdir.begin(); sdi != subdir.end(); sdi++) {
186 if ((youngest.first < *sdi) || (youngest.first.size() == 0)) {
194 if (youngest.second.size() == 0) {
204 if (*vi == youngest.second) {
216 std::pair<std::string,filesystem::size_type> most_space;
243 if (errno == ENOMEM) {
265 subdirectory::iterator sdi;
275 sdi = subdir.begin();
276 while (sdi != subdir.end()) {
277 if (!
is_timestamp((*sdi).substr(0,(*sdi).find(
".incomplete"))))
280 sdi = subdir.begin();
340 logger.
write(
"*** ERROR: Overflow error detected in vault_manager::usage() while calculating percent blocks used\n");
345 logger.
write(
"*** ERROR: Unknown error detected in vault_manager::usage() while calculating percent blocks used\n");
360 logger.
write(
"*** ERROR: Overflow error detected in vault_manager::usage() while calculating percent inodes used\n");
365 logger.
write(
"*** ERROR: Unknown error detected in vault_manager::usage() while calculating percent inodes used\n");
373 a_blocks = blocks.
value();
374 a_inodes = inodes.
value();
391 usage(free_blocks, free_inodes);
397 if (value && a_report) {
398 TRY_nomem(lstr =
"Vault overflow detected: ");
406 static_cast<uint16
>(100)));
410 static_cast<uint16
>(100)));
442 std::string delete_dir;
445 uint16 free_blocks, free_inodes;
447 subdirectory::const_iterator ilf;
460 (archive_list.size() == 0)
462 (archive_list.size() == 1)
463 && (archive_list[0] == ts || archive_list[0] == tsi)
467 TRY_nomem(es =
"Vault has insufficient space: \"");
475 if (oldest == ts || oldest == tsi) {
476 TRY_nomem(lstr =
"Oldest is actually archive in use: \"");
478 TRY_nomem(lstr +=
"\" Skipping to next archive...\n");
483 if (oldest.find(
".incomplete") != std::string::npos) {
484 TRY_nomem(lstr =
"WARNING: Oldest archive found is incomplete.\n");
488 TRY_nomem(lstr =
"Deleting oldest archive: \"");
505 if (delete_dir.find(
".deleting") == std::string::npos)
506 delete_dir +=
".deleting";
514 TRY_nomem(es =
"Delete command returned non-zero exit value: \"");
519 cmdline += delete_dir;
521 if (system(cmdline.c_str()) != 0)
526 TRY_nomem(lstr =
"Deletion complete, duration: ");
531 usage(free_blocks, free_inodes);
552 logger.
write(
"Searching for old log files to delete...\n");
556 for (ilf = logfile_list.begin(); ilf != logfile_list.end(); ilf++) {
569 es =
"*** ERROR: Could not remove log file: ";
581 es =
"*** ERROR: Unknown error detected in vault_manager::delete_oldest_archive() while deleting old log file: ";
593 wildcard +=
".relink*";
595 for (ilf = logfile_list.begin(); ilf != logfile_list.end(); ilf++) {
608 es =
"*** ERROR: Could not remove relink file: ";
620 es =
"*** ERROR: Unknown error detected in vault_manager::delete_oldest_archive() while deleting old relink file: ";
635 logger.
write(
"Searching for old report files to delete...\n");
637 wildcard +=
".report*";
639 for (ilf = logfile_list.begin(); ilf != logfile_list.end(); ilf++) {
652 es =
"*** ERROR: Could not remove report file: ";
664 es =
"*** ERROR: Unknown error detected in vault_manager::delete_oldest_archive() while deleting old log file: ";
706 if (!
overflow() && !a_assume_overflow)
715 TRY_nomem(es =
"Vault has insufficient space: \"");
726 a_assume_overflow =
false;
730 throw(
ERROR(0,
"Vault has insufficient space"));
734 if (!
overflow() && !a_assume_overflow)
740 while (
overflow() || a_assume_overflow) {
743 a_assume_overflow =
false;
Safely manipulate numbers without worryiung about over/underflow error.
Retrieve information about a filesystem.
const size_type total_inodes(void) const
Return the filesystem's total number of inodes, if supported by the filesystem, otherwise the result ...
void clear(void)
Clear the vault manager.
log_manager logger
The global log manager.
void init(void)
Initialize the vault manager.
const uint16 & vault_overflow_blocks(void) const
Return the vault-overflow-blocks.
An extended string class.
void path(const std::string &a_path)
Retrieve information about the filesystem on which the given path resides.
void usage(uint16 &a_blocks, uint16 &a_inodes) const
Return the percent of used blocks and used inodes in the selected vault.
const bool initialized(void) const
Return the initialized status of the vault manager.
const bool err_deleted_archives(void) const
Return whether or not there was an error deleting archives.
const std::vector< std::string > & deleted_archives(void) const
Return a list of deleted archives.
const T value(void) const
Return the value.
const bool delete_old_log_files(void) const
Return the value of delete-old-log-files.
void push_back(const error_instance &a_e)
std::string percent_string(const T &a_complete, const T &a_total)
Given a count complete and a count total, calculate a percentage.
static const T max_limit()
A small set of numeric limits routines, since gcc prior to 3.x doesn't have numeric_limits.
void write(const std::string &a_str, const uint16 a_indention=0, const configuration_manager::logging_type a_logging_level=configuration_manager::logging_manager, const pid_t a_pid=pid())
Write a string to the log file.
const class timestamp & timestamp(void) const
Return the timestamp of this instance of rvm.
const std::string & log_dir(void) const
Return the log-dir path.
const bool delete_old_report_files(void) const
Return the value of delete-old-report-files.
const uint16 & vault_overflow_inodes(void) const
Return the vault-overflow-inodes.
const vaults_type & vaults(void) const
Return the vaults.
const selection_type & vault_selection_behavior(void) const
Return the vault-selection-behavior.
Select, monitor, and prepare vaults.
void lockfile(const std::string &a_lockfile)
Set the lockfile path.
std::vector< std::string > m_deleted_archives
void assign(value_type a_value)
std::string m_selected_vault
report_manager reporter
The global report manager.
void select(void)
Select a vault.
const subdirectory get_archive_list(void)
Return a list of archive directories in the selected vault.
void start(void)
Start (or restart) the timer.
const type & path(const std::string a_path, const std::string a_filter="*")
Return a vector of strings of a list of files in a subdirectory.
const std::string vault(void) const
Return the path to the selected vault.
const pid_type locked_by(void) const
Get the PID of the locking process.
const size_type free_inodes(void) const
Return the filesystem's total number of free inodes, if supported by the filesystem, otherwise the result is system-dependent, but usually 0.
void rm_recursive(const std::string a_path)
Recursively delete the contents of a directory.
void prepare(bool a_assume_overflow=false)
Prepare the selected vault.
#define INTERNAL_ERROR(e, s)
configuration_manager config
The global configuration manager instance.
bool is_timestamp(const std::string &a_s)
Return true if the string is a valid timestamp.
void clear(void)
Clear the simple_lock object.
vault_report & vault(void)
Return the vault reporter object.
const size_type free_blocks(void) const
Return the filesystem's number of free blocks.
const std::string duration(void) const
Generate a duration string.
void add_report(const vault_stats_report &a_class)
Add a vault report to the list.
#define ERROR_INSTANCE(s)
void rm_file(const std::string a_path)
Remove a file.
void delete_oldest_archive(void)
Find the oldest archive in the vault and delete it.
const std::string str(void) const
Generate a string.
const bool overflow(bool a_report=false)
Test to see if a vault has exceeded it's overflow threshold.
const std::string & delete_command_path(void) const
Return the delete-command-path.
void rename_file(const std::string a_from, const std::string a_to)
Rename a file or directory.
const overflow_type & vault_overflow_behavior(void) const
Return the vault-overflow-behavior.
const bool vault_locking(void) const
Return the vault-locking selection.
void stop(void)
Stop the timer.
Retrieve a list of files in a subdirectory that match a given wildcard filename.
const std::string str(const std::string a_prefix="") const
const size_type total_blocks(void) const
Return the filesystem's total number of blocks.
const bool is_locked(void) const
Find out whether or not the lock is in place.
const bool selected(void) const
Return whether or not a vault has been selected yet.
vault_manager vaulter
The global vault manager.