filesystem Class Reference

Easy access class to the filesystem. More...

#include <filesystem.h>

Collaboration diagram for filesystem:
Collaboration graph
[legend]

List of all members.

Public Member Functions

bool exists (const string &path)
bool isdir (const string &path)
bool rm (const string &path)
bool mkdir (const string &dir)
bool chroot (const string &p)
bool mv (const string &pold, const string &pnew)
bool cp (const string &pold, const string &pnew)
bool chmod (const string &path, int perms)
stringpwdize (const string &str)
void umask (int msk)
bool chown (const string &path, const string &user)
bool chown (const string &path, const string &user, const string &group)
bool chown (const string &path, uid_t userid, gid_t groupid)
bool chgrp (const string &path, const string &group)
unsigned int size (const string &path)
valuegetinfo (const string &)
bool cd (const string &dir)
valuedir (const string &path="")
valuels (const string &path="", bool longformat=true, bool showhidden=false)
stringgetresource (const string &pat, const string &rsrc, const string &idx="")
stringpwd (void)
stringload (const string &_vpath)
bool save (const string &_vpath, const string &_data)
bool save (const string &p, const string &d, flag::savetype tp)
stringtransr (const string &_vpath)
stringtransw (const string &_vpath)

Public Attributes

value pathvol

Protected Member Functions

bool cdrelative (const string &)
stringfindread (const statstring &, const string &)
stringfindwrite (const statstring &, const string &)
valuegetpaths (const statstring &)
bool maywrite (const string &)
bool mayread (const string &)

Protected Attributes

int _umask
perthread< string_cwd
gid_t * _groups
int _groupcnt

Detailed Description

Easy access class to the filesystem.

Programs can use a global instance of this class called 'fs'. Automatically resolves alias paths.


Member Function Documentation

bool filesystem::cd ( const string dir  ) 

Change current directory.

Parameters:
dir Relative path to the new directory.
Returns:
Status, true if succeeded.

References _cwd, isdir(), and string::strchr().

Here is the call graph for this function:

bool filesystem::chgrp ( const string path,
const string group 
)

Change object's group ownership.

Parameters:
path The grace path.
group The group name.

References chown(), value::count(), getinfo(), string::str(), string::strlen(), transw(), and systemclass::userdb.

Here is the call graph for this function:

bool filesystem::chmod ( const string path,
int  perms 
)

Change mode flags for a filesystem object.

Parameters:
path The path to the object.
perms The access permissions.

References string::str(), and transw().

Here is the call graph for this function:

bool filesystem::chown ( const string path,
uid_t  userid,
gid_t  groupid 
)

Change object's ownership and group ownership.

Parameters:
path The grace path.
userid The unix userid of the new owner.
groupid The unix groupid of the new owner.

References chown(), string::str(), string::strlen(), and transw().

Here is the call graph for this function:

bool filesystem::chown ( const string path,
const string user,
const string group 
)

Change object's ownership and group ownership.

Parameters:
path The grace path.
user The owner's name.
group The group name.

References chown(), value::count(), systemclass::userdbFunctions::getpwnam(), and systemclass::userdb.

Here is the call graph for this function:

bool filesystem::chown ( const string path,
const string user 
)

Change object's ownership.

Parameters:
path The grace path.
user The owner's name.

References value::count(), getinfo(), systemclass::userdbFunctions::getpwnam(), string::str(), string::strlen(), transw(), and systemclass::userdb.

Referenced by chgrp(), chown(), and daemon::writepid().

Here is the call graph for this function:

bool filesystem::chroot ( const string p  ) 

Change the filesystem root.

Parameters:
p The filesystem path to chroot to.
Returns:
Status, true if the root was succesfully changed.

References string::str().

Here is the call graph for this function:

bool filesystem::cp ( const string pold,
const string pnew 
)

Copy a file on the filesystem.

Parameters:
pold The old path.
pnew The new path.

References file::close(), file::eof(), file::openread(), file::openwrite(), file::puts(), file::read(), rm(), string::strlen(), transr(), and transw().

Here is the call graph for this function:

bool filesystem::exists ( const string path  ) 

Check if a filesystem object exists.

Parameters:
path Relative or absolute path to the file.
Returns:
Status, true if the filesystem object exists.

References string::cutat(), and pwdize().

Referenced by daemon::checkpid(), httpdfileshare::httpdfileshare(), fswatch::list(), configdb< appclass >::load(), httpdfileshare::run(), httpdscriptparser::run(), and httpd::sendfile().

Here is the call graph for this function:

value * filesystem::getinfo ( const string _path  ) 

Get full information about a file.

The value object contains the following keys:

  • path Full path.
  • inode Filesystem inode number.
  • nlink Number of links.
  • type Filetype (see fsfiletype).
  • link In case of a softlink, the link target.
  • mode Permission bits.
  • fuid File owner.
  • fgid File group.
  • user Resolved username for the owner.
  • group Resolved group name for the group.
  • size File size.
  • atime,mtime,ctime Access times.
  • mime (explicit mimetype).
    Parameters:
    p Path of the file.
    Returns:
    New value object.

References systemclass::userdbFunctions::getpwuid(), string::printf(), pwdize(), string::str(), string::strlen(), transr(), and systemclass::userdb.

Referenced by chgrp(), chown(), fswatch::list(), and httpdfileshare::run().

Here is the call graph for this function:

string * filesystem::getresource ( const string pat,
const string rsrc,
const string idx = "" 
)

Load a resource object associated with a filesystem object.

Parameters:
pat Path to the filesystem object.
rsrc Resource name.
idx Optional resource index.
Returns:
New string object with the resource data.

References string::cutat(), load(), string::str(), string::strcat(), string::strchr(), and string::strlen().

Here is the call graph for this function:

bool filesystem::isdir ( const string path  ) 

Check if a filesystem object is a directory.

Parameters:
path Relative or absolute path to the file.
Returns:
Status, true if the object is a directory.

References pwdize(), string::str(), string::strlen(), and transr().

Referenced by cd(), and httpdfileshare::run().

Here is the call graph for this function:

string * filesystem::load ( const string _vpath  ) 

Load a file.

Returns a pointer to a newly allocated string object.

Parameters:
_vpath Relative or absolute path of the file.
Returns:
New string object with the file contents.

References file::close(), file::eof(), file::openread(), and file::read().

Referenced by daemon::checkpid(), getresource(), value::loadshox(), value::loadxml(), httpdscriptparser::run(), httpdvhost::run(), and httpdbasicauth::run().

Here is the call graph for this function:

value * filesystem::ls ( const string path = "",
bool  longformat = true,
bool  showhidden = false 
)

Lists the entries of the current or provided directory.

The short format returns just a named list with nodes only having a 'path' key. The long format follows the form of the filesystem::info method.

Parameters:
path Path to investigate.
longformat True if long format should be returned.
showhidden True if 'hidden' files should be listed.
Returns:
New value object.

References string::copyafter(), string::copyuntil(), dir(), string::printf(), pwd(), pwdize(), string::str(), string::strchr(), and string::strstr().

Referenced by dir(), and fswatch::list().

Here is the call graph for this function:

bool filesystem::mkdir ( const string dir  ) 

Create a directory.

Parameters:
dir Relative or absolute path for the directory.
Returns:
Status, true if the directory was created.

References _umask, string::cutat(), pwdize(), string::str(), string::strchr(), and string::strlen().

Here is the call graph for this function:

bool filesystem::mv ( const string pold,
const string pnew 
)

Move/rename a filesystem object.

Parameters:
pold The old path.
pnew The new path.
Returns:
Status, true if the object was moved.

References string::cutat(), pwdize(), string::strchr(), and string::strlen().

Referenced by logthread::run().

Here is the call graph for this function:

string & filesystem::pwd ( void   ) 

Get current directory path.

Returns:
Reference to the path variable.

References _cwd, and perthread< kind >::get().

Referenced by cgi::cgi(), ls(), and pwdize().

Here is the call graph for this function:

string * filesystem::pwdize ( const string str  ) 

Convert a relative or aliaspath to an absolute path.

Parameters:
str The relative/alias path.
Returns:
New string object with the absolute path.

References string::printf(), pwd(), string::str(), and string::strchr().

Referenced by exists(), getinfo(), isdir(), ls(), mkdir(), mv(), rm(), transr(), and transw().

Here is the call graph for this function:

bool filesystem::rm ( const string path  ) 

Remove a filesystem object.

Parameters:
path Relative or absolute path to the file.
Returns:
Status, true if the file was succesfully deleted.

References string::cutat(), pwdize(), string::str(), string::strchr(), and string::strlen().

Referenced by cp().

Here is the call graph for this function:

bool filesystem::save ( const string _vpath,
const string _data 
)

Save a string object into a file.

Parameters:
_vpath Relative or absolute path for the file.
_data The string to be saved.
Returns:
Status, true if succesfully saved.

References file::close(), file::openwrite(), file::puts(), and string::strlen().

Referenced by daemon::checkpid(), smtpd::deliver(), value::saveshox(), value::savexml(), and daemon::~daemon().

Here is the call graph for this function:

unsigned int filesystem::size ( const string path  ) 

Size up a filesystem object.

Parameters:
path Path to the object.
Returns:
Size in bytes.

References string::str(), and transr().

Referenced by httpdfileshare::run(), and httpd::sendfile().

Here is the call graph for this function:

string* filesystem::transr ( const string _vpath  )  [inline]

Translate a relative/aliaspath to open a file for reading.

Returns a string containing the translated absolute Unix path.

Parameters:
_vpath Relative or alias path.
Returns:
New string object with translated full path.

References string::left(), string::mid(), pwdize(), and string::strchr().

Referenced by daemon::checkpid(), cp(), getinfo(), isdir(), file::openread(), httpdfileshare::run(), size(), tcpsocket::uconnect(), daemon::writepid(), and daemon::~daemon().

Here is the call graph for this function:

string* filesystem::transw ( const string _vpath  )  [inline]

Translate a relative/aliaspath to open a file for writing.

Returns a string containing the translated absolute Unix path.

Parameters:
_vpath Relative or alias path.
Returns:
New string object with translated full path.

References string::left(), string::mid(), pwdize(), and string::strchr().

Referenced by chgrp(), chmod(), chown(), cp(), tcplistener::listento(), file::openappend(), file::openwrite(), and daemon::writepid().

Here is the call graph for this function:

void filesystem::umask ( int  msk  ) 

Set filesystem mask.

Parameters:
msk The mask.

References _umask.


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

Generated on Sun Feb 28 10:35:47 2010 for GRACE by  doxygen 1.6.1