OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
agg_util::DirectoryUtil Class Reference

Helper classes for using dirent.h, dir.h, stat.h, etc. More...

#include <DirectoryUtil.h>

Collaboration diagram for agg_util::DirectoryUtil:
Collaboration graph

Public Member Functions

void clearRegExp ()
 Remove any filter using a regular expression. More...
 
 DirectoryUtil ()
 
void getListingForPath (const std::string &path, std::vector< FileInfo > *pRegularFiles, std::vector< FileInfo > *pDirectories)
 Get a listing of all the regular files and directories in the given path, which is assumed relative to getRootDir(). More...
 
void getListingForPathRecursive (const std::string &path, std::vector< FileInfo > *pRegularFiles, std::vector< FileInfo > *pDirectories)
 Get the listing for the path recursing into every directory found until it bottoms out. More...
 
void getListingOfRegularFilesRecursive (const std::string &path, std::vector< FileInfo > &rRegularFiles)
 Get recursive listing of all regular files in the directory subtree. More...
 
const std::string & getRootDir () const
 get the current root dir More...
 
void setFilterModTimeOlderThan (time_t newestModTime)
 Set a filter on the modification time of the files to be returned in a listing. More...
 
void setFilterRegExp (const std::string &regexp)
 Set a (GNU style) regular expression to be used to match against the full filename (relative path under root) and filter only those that match in the listings. More...
 
void setFilterSuffix (const std::string &suffix)
 Set the filter to be used for the nexy getListingForPath() call. More...
 
void setRootDir (const std::string &rootDir, bool allowRelativePaths=false, bool allowSymLinks=false)
 Makes sure the directory exists and is readable or throws an exception exception. More...
 
 ~DirectoryUtil ()
 

Static Public Member Functions

static std::string getBESRootDir ()
 Gets the BES root directory by checking the bes.conf settings for BES. More...
 
static bool hasRelativePath (const std::string &path)
 Is there a "../" in path? More...
 
static bool matchesSuffix (const std::string &filename, const std::string &suffix)
 
static void printFileInfoList (std::ostream &os, const std::vector< FileInfo > &listing)
 Print the list of files to the stream. More...
 
static void printFileInfoList (const std::vector< FileInfo > &listing)
 Just dump to the BESDebug channel _sDebugChannel for debugging. More...
 
static void removePrecedingSlashes (std::string &path)
 mutate to remove and preceding (in the front) "/" More...
 
static void removeTrailingSlashes (std::string &path)
 mutate to remove all trailing "/" More...
 

Detailed Description

Helper classes for using dirent.h, dir.h, stat.h, etc.

to make directory listings.

Definition at line 88 of file DirectoryUtil.h.

Constructor & Destructor Documentation

agg_util::DirectoryUtil::DirectoryUtil ( )

Definition at line 173 of file DirectoryUtil.cc.

References setRootDir().

Here is the call graph for this function:

agg_util::DirectoryUtil::~DirectoryUtil ( )

Definition at line 184 of file DirectoryUtil.cc.

References clearRegExp().

Here is the call graph for this function:

Member Function Documentation

void agg_util::DirectoryUtil::clearRegExp ( )

Remove any filter using a regular expression.

Definition at line 242 of file DirectoryUtil.cc.

Referenced by setFilterRegExp(), and ~DirectoryUtil().

std::string agg_util::DirectoryUtil::getBESRootDir ( )
static

Gets the BES root directory by checking the bes.conf settings for BES.

Returns: value for key == "BES.Catalog.catalog.RootDirectory" if it exists, else the value for "BES.Data.RootDirectory" if that doesn't exist either, simply returns the filesystem root "/".

Returns
the root path

Definition at line 490 of file DirectoryUtil.cc.

References BESKeys::get_value(), and TheBESKeys::TheKeys().

Referenced by ncml_module::ScanElement::getDatasetList().

Here is the call graph for this function:

void agg_util::DirectoryUtil::getListingForPath ( const std::string &  path,
std::vector< FileInfo > *  pRegularFiles,
std::vector< FileInfo > *  pDirectories 
)

Get a listing of all the regular files and directories in the given path, which is assumed relative to getRootDir().

Entries are placed into one of two vectors if not null. This allows just regular files to be gotten, or just subdirectories, or both.

Note
these can be the SAME pointer, with FileInfo.isDir specifying which are which.
Any file starting with a dot ('.') is ignored! This include ".." and "." dirs.
symbolic links in path ARE followed now (though the root dir may not contain them) TODO consider adding a flag to filter out symlinks...
Parameters
paththe directory to list, non-recursive.
pRegularFilesvector to add the regular (not directory) files to if not null.
pDirectoriesvector to add the directories found in path if not null.

Definition at line 255 of file DirectoryUtil.cc.

References BESDEBUG, agg_util::FileInfo::getFullPath(), getRootDir(), and removePrecedingSlashes().

Referenced by ncml_module::ScanElement::getDatasetList(), and getListingForPathRecursive().

Here is the call graph for this function:

void agg_util::DirectoryUtil::getListingForPathRecursive ( const std::string &  path,
std::vector< FileInfo > *  pRegularFiles,
std::vector< FileInfo > *  pDirectories 
)

Get the listing for the path recursing into every directory found until it bottoms out.

NOTE: a symlink loop will cause an exception.

See also
getListingForPath()
Parameters
pathtop directory to begin recursive search
pRegularFilesif not null, filled with all regular files in filesystem subtree.
pDirectoriesif not null, filled in with all directories in filesystem subtree.

Definition at line 313 of file DirectoryUtil.cc.

References BESDEBUG, getListingForPath(), and removeTrailingSlashes().

Referenced by getListingOfRegularFilesRecursive().

Here is the call graph for this function:

void agg_util::DirectoryUtil::getListingOfRegularFilesRecursive ( const std::string &  path,
std::vector< FileInfo > &  rRegularFiles 
)

Get recursive listing of all regular files in the directory subtree.

See also
getListingForPathRecursive()
Parameters
pathtop directory to search
rRegularFileswhere to place all the files.

Definition at line 353 of file DirectoryUtil.cc.

References getListingForPathRecursive().

Referenced by ncml_module::ScanElement::getDatasetList().

Here is the call graph for this function:

const std::string & agg_util::DirectoryUtil::getRootDir ( ) const

get the current root dir

Definition at line 191 of file DirectoryUtil.cc.

Referenced by ncml_module::ScanElement::getDatasetList(), and getListingForPath().

bool agg_util::DirectoryUtil::hasRelativePath ( const std::string &  path)
static

Is there a "../" in path?

Definition at line 442 of file DirectoryUtil.cc.

Referenced by setRootDir().

bool agg_util::DirectoryUtil::matchesSuffix ( const std::string &  filename,
const std::string &  suffix 
)
static

Definition at line 509 of file DirectoryUtil.cc.

void agg_util::DirectoryUtil::printFileInfoList ( std::ostream &  os,
const std::vector< FileInfo > &  listing 
)
static

Print the list of files to the stream.

Definition at line 479 of file DirectoryUtil.cc.

Referenced by printFileInfoList().

void agg_util::DirectoryUtil::printFileInfoList ( const std::vector< FileInfo > &  listing)
static

Just dump to the BESDebug channel _sDebugChannel for debugging.

Definition at line 471 of file DirectoryUtil.cc.

References BESDEBUG, and printFileInfoList().

Here is the call graph for this function:

void agg_util::DirectoryUtil::removePrecedingSlashes ( std::string &  path)
static

mutate to remove and preceding (in the front) "/"

Definition at line 461 of file DirectoryUtil.cc.

Referenced by agg_util::FileInfo::FileInfo(), and getListingForPath().

void agg_util::DirectoryUtil::removeTrailingSlashes ( std::string &  path)
static

mutate to remove all trailing "/"

Definition at line 448 of file DirectoryUtil.cc.

Referenced by agg_util::FileInfo::FileInfo(), getListingForPathRecursive(), and setRootDir().

void agg_util::DirectoryUtil::setFilterModTimeOlderThan ( time_t  newestModTime)

Set a filter on the modification time of the files to be returned in a listing.

Any returned file will have a modification date older than newestModTime.

Parameters
newestModTimethe cutoff modification time for inclusion of files.

Definition at line 248 of file DirectoryUtil.cc.

void agg_util::DirectoryUtil::setFilterRegExp ( const std::string &  regexp)

Set a (GNU style) regular expression to be used to match against the full filename (relative path under root) and filter only those that match in the listings.

setFilterRegExp("") is the same as clearRegExp().

Note
If the filter suffix has been set as well, then BOTH of these must match for a file to be in the listing.
Parameters
regexpthe regular expression to use.
Exceptions
thiswill throw libdap::Error if there's a problem with compiling the regexp.

Definition at line 232 of file DirectoryUtil.cc.

References clearRegExp().

Here is the call graph for this function:

void agg_util::DirectoryUtil::setFilterSuffix ( const std::string &  suffix)

Set the filter to be used for the nexy getListingForPath() call.

Only files that end in suffix will be returned.

Parameters
suffixsuffix string to filter returned files against

Definition at line 226 of file DirectoryUtil.cc.

void agg_util::DirectoryUtil::setRootDir ( const std::string &  origRootDir,
bool  allowRelativePaths = false,
bool  allowSymLinks = false 
)

Makes sure the directory exists and is readable or throws an exception exception.

Makes sure the directory exists and is readable or throws an parse exception.

Removes any trailing slashes unless the root is "/" (default). If !allowRelativePaths, then: Throws a BESForbiddenError if there is a "../" in the path somewhere. If !allowSymLinks and one is encountered, Throws a BESNotForbiddenError exception. If the root path cannot be found, throws BESNotFoundError.

Removes any trailing slashes unless the root is "/" (default). If noRelativePaths, then: Throws a parse exception if there is a "../" in the path somewhere.

Definition at line 202 of file DirectoryUtil.cc.

References BESUtil::check_path(), hasRelativePath(), and removeTrailingSlashes().

Referenced by DirectoryUtil(), and ncml_module::ScanElement::getDatasetList().

Here is the call graph for this function:


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