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 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...

Defines

#define STATFS   statfs

Functions

const std::string cwd (void)
 Return the current working directory.
const pid_t pid (void)
 Return the PID of this process.
const pid_t parent_pid (void)
 Return the PID of the parent process.
bool absolute_path (const std::string &a_path)
 Return true if the string looks like an absolute path.
bool relative_path (const std::string &a_path)
 Return true if the string looks like a relative path.
std::string reform_path (const std::string &a_path)
 Reformat a path to remove double slashes.
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.
std::string path_basename (const std::string &a_path)
 Return everything after the last slash from a path.
std::string path_dirname (const std::string &a_path)
 Return everything up to the last slash from 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.
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.
bool exists (const std::string &a_path)
 Return true if the file or directory exists.
bool readable (const std::string &a_path)
 Return true if the file or directory exists and is readable.
bool writable (const std::string &a_path)
 Return true if the file or directory exists and is writable.
bool executable (const std::string &a_path)
 Return true if the file or directory exists and is executable.
void mk_dir (const std::string &a_path)
 Create a directory.
void rm_dir (const std::string a_path)
 Remove a directory.
void rm_file (const std::string a_path)
 Remove a file.
void mk_dirhier (const std::string a_path)
 Recursively create a directory heirarchy.
void rename_file (const std::string a_from, const std::string a_to)
 Rename a file or directory.
void mk_symlink (const std::string a_from, const std::string a_to)
 Create a symbolic link.
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.
void rm_recursive (const std::string a_path)
 Recursively delete the contents of a directory.


Define 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  ) 

Return true if the file or directory exists.

Definition at line 385 of file fs.cc.

Referenced by archive_manager::archive(), report_manager::file_report(), log_manager::init(), simple_lock::locked_by(), job_archiver::mf_do_chores(), mk_dirhier(), mk_dirhier_recursive_(), directory::path(), rename_file(), rm_dir(), rm_file(), rm_recursive(), test_executable(), test_exists(), test_filestatus(), test_mk_dir(), test_mk_dirhier(), test_mk_relative_symlink(), test_mk_symlink(), test_rm_dir(), test_rm_file(), test_rm_recursive(), test_rvm(), test_simple_lock(), and simple_lock::unlock().

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::mf_do_chores(), 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 764 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 748 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 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  ) 

Reformat a path to remove double slashes.

Definition at line 205 of file fs.cc.

References TRY_nomem.

Referenced by catalog_manager::catalog(), catalog_manager::erase(), job::generate_archive_path(), job::generate_job_id(), job_archiver::mf_do_chores(), mk_absolute_path(), mk_relative_path(), mk_relative_symlink(), filestatus::path(), directory::path(), filesystem::path(), permute_path(), test_inodes(), and test_reform_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, and TRY_nomem.

Referenced by archive_manager::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 1408 of file fs.cc.

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

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 job_archiver::mf_do_chores(), global_parser::parse_vault(), rm_dir(), rm_file(), and test_writable().


Generated on Tue Jul 1 12:09:47 2008 for rvm by  doxygen 1.5.1