bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
agg_util::DirectoryUtil Class Reference

#include <DirectoryUtil.h>

Collaboration diagram for agg_util::DirectoryUtil:
Collaboration graph

Public Member Functions

void clearRegExp ()
 
void getListingForPath (const std::string &path, std::vector< FileInfo > *pRegularFiles, std::vector< FileInfo > *pDirectories)
 
void getListingForPathRecursive (const std::string &path, std::vector< FileInfo > *pRegularFiles, std::vector< FileInfo > *pDirectories)
 
void getListingOfRegularFilesRecursive (const std::string &path, std::vector< FileInfo > &rRegularFiles)
 
const std::string & getRootDir () const
 
void setFilterModTimeOlderThan (time_t newestModTime)
 
void setFilterRegExp (const std::string &regexp)
 
void setFilterSuffix (const std::string &suffix)
 
void setRootDir (const std::string &rootDir, bool allowRelativePaths=false, bool allowSymLinks=false)
 

Static Public Member Functions

static std::string getBESRootDir ()
 
static bool hasRelativePath (const std::string &path)
 
static bool matchesSuffix (const std::string &filename, const std::string &suffix)
 
static void printFileInfoList (const std::vector< FileInfo > &listing)
 
static void printFileInfoList (std::ostream &os, const std::vector< FileInfo > &listing)
 
static void removePrecedingSlashes (std::string &path)
 
static void removeTrailingSlashes (std::string &path)
 

Detailed Description

Helper classes for using dirent.h, dir.h, stat.h, etc. to make directory listings.

Definition at line 83 of file DirectoryUtil.h.

Constructor & Destructor Documentation

◆ DirectoryUtil()

agg_util::DirectoryUtil::DirectoryUtil ( )

Definition at line 158 of file DirectoryUtil.cc.

◆ ~DirectoryUtil()

agg_util::DirectoryUtil::~DirectoryUtil ( )

Definition at line 166 of file DirectoryUtil.cc.

Member Function Documentation

◆ clearRegExp()

void agg_util::DirectoryUtil::clearRegExp ( )

Remove any filter using a regular expression.

Definition at line 218 of file DirectoryUtil.cc.

◆ getBESRootDir()

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 423 of file DirectoryUtil.cc.

◆ getListingForPath()

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 230 of file DirectoryUtil.cc.

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

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 279 of file DirectoryUtil.cc.

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

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

Definition at line 312 of file DirectoryUtil.cc.

◆ getRootDir()

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

get the current root dir

Definition at line 173 of file DirectoryUtil.cc.

◆ hasRelativePath()

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

Is there a "../" in path?

Definition at line 386 of file DirectoryUtil.cc.

◆ matchesSuffix()

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

Definition at line 437 of file DirectoryUtil.cc.

◆ printFileInfoList() [1/2]

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

Just dump to the BESDebug channel _sDebugChannel for debugging

Definition at line 409 of file DirectoryUtil.cc.

◆ printFileInfoList() [2/2]

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 416 of file DirectoryUtil.cc.

◆ removePrecedingSlashes()

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

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

Definition at line 401 of file DirectoryUtil.cc.

◆ removeTrailingSlashes()

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

mutate to remove all trailing "/"

Definition at line 391 of file DirectoryUtil.cc.

◆ setFilterModTimeOlderThan()

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 224 of file DirectoryUtil.cc.

◆ setFilterRegExp()

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 210 of file DirectoryUtil.cc.

◆ setFilterSuffix()

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 205 of file DirectoryUtil.cc.

◆ setRootDir()

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

Makes sure the directory exists and is readable or throws an parse exception. 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 183 of file DirectoryUtil.cc.


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