rvm  1.11
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Macros | Functions
fs.h File Reference
#include <iostream>
#include <string>
#include <vector>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <pwd.h>
#include <grp.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <signal.h>
#include <sys/statvfs.h>
#include <sys/vfs.h>
#include "types.h"
#include <string.h>
Include dependency graph for fs.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  filestatus
 Retrieve information about a file or directory. More...
 
class  subdirectory
 Retrieve a list of files in a subdirectory that match a given wildcard filename. More...
 
class  directory
 Retrieve a list of pathnames that match a given wildcard path. More...
 
class  filesystem
 Retrieve information about a filesystem. More...
 
class  simple_lock
 A simple locking mechanism. More...
 

Macros

#define STATFS   statfs
 

Functions

const std::string cwd (void)
 Return the current working directory. More...
 
const pid_t pid (void)
 Return the PID of this process. More...
 
const pid_t parent_pid (void)
 Return the PID of the parent process. More...
 
bool absolute_path (const std::string &a_path)
 Return true if the string looks like an absolute path. More...
 
bool relative_path (const std::string &a_path)
 Return true if the string looks like a relative path. More...
 
std::string reform_path (const std::string &a_path)
 Reformat a path to remove double slashes. More...
 
std::string permute_path (const std::string &a_path)
 Reformat a path to remove the begining and trailing slashes, and replace all other slashes with underscores. More...
 
std::string path_basename (const std::string &a_path)
 Return everything after the last slash from a path. More...
 
std::string path_dirname (const std::string &a_path)
 Return everything up to the last slash from a path. More...
 
std::string mk_absolute_path (const std::string a_path, const std::string a_rel_path)
 Make the path a_rel_path absolute with respect to a_path, where a_rel_path and a_path are directory names. More...
 
std::string mk_relative_path (const std::string a_path_to, const std::string a_path_from)
 Make the path a_path_to relative from a_path_from, where a_path_to and a_path_from are directory names. More...
 
bool exists (const std::string &a_path)
 Return true if the file or directory exists. More...
 
bool readable (const std::string &a_path)
 Return true if the file or directory exists and is readable. More...
 
bool writable (const std::string &a_path)
 Return true if the file or directory exists and is writable. More...
 
bool executable (const std::string &a_path)
 Return true if the file or directory exists and is executable. More...
 
void mk_dir (const std::string &a_path)
 Create a directory. More...
 
void rm_dir (const std::string a_path)
 Remove a directory. More...
 
void rm_file (const std::string a_path)
 Remove a file. More...
 
void mk_dirhier (const std::string a_path)
 Recursively create a directory heirarchy. More...
 
void rename_file (const std::string a_from, const std::string a_to)
 Rename a file or directory. More...
 
void mk_symlink (const std::string a_from, const std::string a_to)
 Create a symbolic link. More...
 
void mk_relative_symlink (const std::string a_from, const std::string a_to)
 Given a from and to path, create a relative symbolic link. More...
 
void rm_recursive (const std::string a_path)
 Recursively delete the contents of a directory. More...
 

Macro Definition Documentation

#define STATFS   statfs

Definition at line 62 of file fs.h.

Referenced by filesystem::path().

Function Documentation

bool absolute_path ( const std::string &  a_path)

Return true if the string looks like an absolute path.

Definition at line 186 of file fs.cc.

Referenced by relative_path().

const std::string cwd ( void  )

Return the current working directory.

Definition at line 148 of file fs.cc.

References ERROR, and TRY_nomem.

Referenced by test_cwd(), and test_filesystem().

bool executable ( const std::string &  a_path)

Return true if the file or directory exists and is executable.

Definition at line 437 of file fs.cc.

Referenced by global_parser::parse_vault(), and test_executable().

bool exists ( const std::string &  a_path)
std::string mk_absolute_path ( const std::string  a_path,
const std::string  a_rel_path 
)

Make the path a_rel_path absolute with respect to a_path, where a_rel_path and a_path are directory names.

Definition at line 282 of file fs.cc.

References ERROR, INTERNAL_ERROR, reform_path(), relative_path(), and TRY_nomem.

Here is the call graph for this function:

void mk_dir ( const std::string &  a_path)

Create a directory.

Definition at line 599 of file fs.cc.

References ACCESSPERMS, ERROR, and TRY_nomem.

Referenced by archive_manager::archive(), make_dir(), mk_dirhier_recursive_(), test_mk_dir(), test_rm_file(), and test_simple_lock().

void mk_dirhier ( const std::string  a_path)

Recursively create a directory heirarchy.

Definition at line 683 of file fs.cc.

References err_unknown, ERROR_INSTANCE, exists(), mk_dirhier_recursive_(), error::push_back(), and TRY_nomem.

Referenced by job_archiver::start(), and test_mk_dirhier().

Here is the call graph for this function:

std::string mk_relative_path ( const std::string  a_path_to,
const std::string  a_path_from 
)

Make the path a_path_to relative from a_path_from, where a_path_to and a_path_from are directory names.

Definition at line 314 of file fs.cc.

References reform_path(), and TRY_nomem.

Referenced by job_archiver::mf_do_chores(), mk_relative_symlink(), and test_mk_relative_path().

Here is the call graph for this function:

void mk_relative_symlink ( const std::string  a_from,
const std::string  a_to 
)

Given a from and to path, create a relative symbolic link.

Definition at line 770 of file fs.cc.

References err_unknown, ERROR_INSTANCE, mk_relative_path(), mk_symlink(), path_basename(), path_dirname(), error::push_back(), reform_path(), and TRY_nomem.

Referenced by catalog_manager::catalog(), and test_mk_relative_symlink().

Here is the call graph for this function:

void mk_symlink ( const std::string  a_from,
const std::string  a_to 
)

Create a symbolic link.

Definition at line 754 of file fs.cc.

References ERROR, and TRY_nomem.

Referenced by mk_relative_symlink(), and test_mk_symlink().

const pid_t parent_pid ( void  )

Return the PID of the parent process.

Definition at line 174 of file fs.cc.

References ERROR, and pid().

Here is the call graph for this function:

std::string path_basename ( const std::string &  a_path)

Return everything after the last slash from a path.

Definition at line 247 of file fs.cc.

References TRY_nomem.

Referenced by mk_relative_symlink().

std::string path_dirname ( const std::string &  a_path)

Return everything up to the last slash from a path.

Definition at line 264 of file fs.cc.

References TRY_nomem.

Referenced by mk_relative_symlink().

std::string permute_path ( const std::string &  a_path)

Reformat a path to remove the begining and trailing slashes, and replace all other slashes with underscores.

Definition at line 224 of file fs.cc.

References reform_path(), and TRY_nomem.

Referenced by job::generate_archive_path(), job::generate_job_id(), and test_permute_path().

Here is the call graph for this function:

const pid_t pid ( void  )

Return the PID of this process.

Definition at line 162 of file fs.cc.

References ERROR, and pid().

Referenced by execute::child_exited(), execute::child_running(), simple_lock::is_locked(), simple_lock::lock(), simple_lock::locked_by(), execute::my_pid(), parent_pid(), pid(), stamp(), test(), and test_simple_lock().

Here is the call graph for this function:

bool readable ( const std::string &  a_path)

Return true if the file or directory exists and is readable.

Definition at line 417 of file fs.cc.

Referenced by global_parser::parse_vault(), and test_readable().

std::string reform_path ( const std::string &  a_path)
bool relative_path ( const std::string &  a_path)

Return true if the string looks like a relative path.

Definition at line 195 of file fs.cc.

References absolute_path().

Referenced by job_archiver::mf_do_chores(), and mk_absolute_path().

Here is the call graph for this function:

void rename_file ( const std::string  a_from,
const std::string  a_to 
)

Rename a file or directory.

Definition at line 709 of file fs.cc.

References ERROR, exists(), INTERNAL_ERROR, TRY_nomem, and writable().

Referenced by archive_manager::archive(), and vault_manager::delete_oldest_archive().

Here is the call graph for this function:

void rm_dir ( const std::string  a_path)

Remove a directory.

Definition at line 612 of file fs.cc.

References ERROR, ERROR_INSTANCE, exists(), error::push_back(), TRY_nomem, and writable().

Referenced by rm_recursive(), test_rm_dir(), and test_rm_file().

Here is the call graph for this function:

void rm_file ( const std::string  a_path)

Remove a file.

Definition at line 637 of file fs.cc.

References ERROR, ERROR_INSTANCE, exists(), error::push_back(), TRY_nomem, and writable().

Referenced by vault_manager::delete_oldest_archive(), rm_recursive(), test_rm_file(), and simple_lock::unlock().

Here is the call graph for this function:

void rm_recursive ( const std::string  a_path)

Recursively delete the contents of a directory.

Definition at line 1414 of file fs.cc.

References ERROR, exists(), filestatus::path(), subdirectory::path(), rm_dir(), rm_file(), rm_recursive(), TRY, TRY_nomem, and writable().

Referenced by vault_manager::delete_oldest_archive(), catalog_manager::erase(), rm_recursive(), and test_rm_recursive().

Here is the call graph for this function:

bool writable ( const std::string &  a_path)

Return true if the file or directory exists and is writable.

Definition at line 427 of file fs.cc.

Referenced by archive_manager::archive(), job_archiver::mf_do_chores(), global_parser::parse_vault(), rename_file(), rm_dir(), rm_file(), rm_recursive(), and test_writable().