|
OPeNDAP Hyrax Back End Server (BES)
Updated for version 3.8.3
|
Helper classes for using dirent.h, dir.h, stat.h, etc. More...
#include <DirectoryUtil.h>

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 ®exp) |
| 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... | |
Helper classes for using dirent.h, dir.h, stat.h, etc.
to make directory listings.
Definition at line 88 of file DirectoryUtil.h.
| agg_util::DirectoryUtil::DirectoryUtil | ( | ) |
Definition at line 173 of file DirectoryUtil.cc.
References setRootDir().

| agg_util::DirectoryUtil::~DirectoryUtil | ( | ) |
Definition at line 184 of file DirectoryUtil.cc.
References clearRegExp().

| 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().
|
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 "/".
Definition at line 490 of file DirectoryUtil.cc.
References BESKeys::get_value(), and TheBESKeys::TheKeys().
Referenced by ncml_module::ScanElement::getDatasetList().

| 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.
| path | the directory to list, non-recursive. |
| pRegularFiles | vector to add the regular (not directory) files to if not null. |
| pDirectories | vector 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().

| 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.
| path | top directory to begin recursive search |
| pRegularFiles | if not null, filled with all regular files in filesystem subtree. |
| pDirectories | if 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().

| void agg_util::DirectoryUtil::getListingOfRegularFilesRecursive | ( | const std::string & | path, |
| std::vector< FileInfo > & | rRegularFiles | ||
| ) |
Get recursive listing of all regular files in the directory subtree.
| path | top directory to search |
| rRegularFiles | where to place all the files. |
Definition at line 353 of file DirectoryUtil.cc.
References getListingForPathRecursive().
Referenced by ncml_module::ScanElement::getDatasetList().

| 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().
|
static |
Is there a "../" in path?
Definition at line 442 of file DirectoryUtil.cc.
Referenced by setRootDir().
|
static |
Definition at line 509 of file DirectoryUtil.cc.
|
static |
Print the list of files to the stream.
Definition at line 479 of file DirectoryUtil.cc.
Referenced by printFileInfoList().
|
static |
Just dump to the BESDebug channel _sDebugChannel for debugging.
Definition at line 471 of file DirectoryUtil.cc.
References BESDEBUG, and printFileInfoList().

|
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().
|
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.
| newestModTime | the 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().
| regexp | the regular expression to use. |
| this | will throw libdap::Error if there's a problem with compiling the regexp. |
Definition at line 232 of file DirectoryUtil.cc.
References clearRegExp().

| 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.
| suffix | suffix 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().
