fs.cc File Reference

#include "config.h"
#include <iostream>
#include <fstream>
#include <cstring>
#include <cerrno>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
#include <dirent.h>
#include <fnmatch.h>
#include <stdio.h>
#include "asserts.h"
#include "error.h"
#include "estring.h"
#include "fs.h"
Include dependency graph for fs.cc:

Go to the source code of this file.

Defines

#define NAMELEN(dirent)   strlen((dirent)->d_name)
#define S_IFMT   (S_IFREG|S_IFCHR|S_IFBLK|S_IFIFO)
#define S_IAMB
#define S_IRWXU   (S_IRUSR|S_IWUSR|S_IXUSR)
#define S_IRWXG   (S_IRGRP|S_IWGRP|S_IXGRP)
#define S_IRWXO   (S_IROTH|S_IWOTH|S_IXOTH)
#define ACCESSPERMS   (S_IRWXU|S_IRWXG|S_IRWXO)

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_recursive_ (const std::string a_path)
 Recursively create a directory heirarchy.
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 ACCESSPERMS   (S_IRWXU|S_IRWXG|S_IRWXO)

Definition at line 142 of file fs.cc.

Referenced by mk_dir().

#define NAMELEN ( dirent   )     strlen((dirent)->d_name)

Definition at line 39 of file fs.cc.

#define S_IAMB
Value:
(S_ISUID|S_ISGID|S_ISVTX\
                |S_IRUSR|S_IWUSR|S_IXUSR\
                |S_IRGRP|S_IWGRP|S_IXGRP\
                |S_IROTH|S_IWOTH|S_IXOTH\
                )

Definition at line 73 of file fs.cc.

#define S_IFMT   (S_IFREG|S_IFCHR|S_IFBLK|S_IFIFO)

Definition at line 69 of file fs.cc.

#define S_IRWXG   (S_IRGRP|S_IWGRP|S_IXGRP)

Definition at line 134 of file fs.cc.

#define S_IRWXO   (S_IROTH|S_IWOTH|S_IXOTH)

Definition at line 138 of file fs.cc.

#define S_IRWXU   (S_IRUSR|S_IWUSR|S_IXUSR)

Definition at line 130 of file fs.cc.


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

void mk_dirhier_recursive_ ( const std::string  a_path  ) 

Recursively create a directory heirarchy.

Definition at line 662 of file fs.cc.

References exists(), mk_dir(), and TRY_nomem.

Referenced by 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 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, 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().

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Thu Sep 30 14:08:03 2010 for rvm by  doxygen 1.6.1