Easy access class to the filesystem. More...
#include <filesystem.h>

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) |
| string * | pwdize (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) |
| value * | getinfo (const string &) |
| bool | cd (const string &dir) |
| value * | dir (const string &path="") |
| value * | ls (const string &path="", bool longformat=true, bool showhidden=false) |
| string * | getresource (const string &pat, const string &rsrc, const string &idx="") |
| string & | pwd (void) |
| string * | load (const string &_vpath) |
| bool | save (const string &_vpath, const string &_data) |
| bool | save (const string &p, const string &d, flag::savetype tp) |
| string * | transr (const string &_vpath) |
| string * | transw (const string &_vpath) |
Public Attributes | |
| value | pathvol |
Protected Member Functions | |
| bool | cdrelative (const string &) |
| string * | findread (const statstring &, const string &) |
| string * | findwrite (const statstring &, const string &) |
| value * | getpaths (const statstring &) |
| bool | maywrite (const string &) |
| bool | mayread (const string &) |
Protected Attributes | |
| int | _umask |
| perthread< string > | _cwd |
| gid_t * | _groups |
| int | _groupcnt |
Easy access class to the filesystem.
Programs can use a global instance of this class called 'fs'. Automatically resolves alias paths.
| bool filesystem::cd | ( | const string & | dir | ) |
Change current directory.
| dir | Relative path to the new directory. |
References _cwd, isdir(), and string::strchr().

Change object's group ownership.
| path | The grace path. | |
| group | The group name. |
References chown(), value::count(), getinfo(), string::str(), string::strlen(), transw(), and systemclass::userdb.

| bool filesystem::chmod | ( | const string & | path, | |
| int | perms | |||
| ) |
Change mode flags for a filesystem object.
| path | The path to the object. | |
| perms | The access permissions. |
References string::str(), and transw().

| bool filesystem::chown | ( | const string & | path, | |
| uid_t | userid, | |||
| gid_t | groupid | |||
| ) |
Change object's ownership and group ownership.
| 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().

Change object's ownership and group ownership.
| path | The grace path. | |
| user | The owner's name. | |
| group | The group name. |
References chown(), value::count(), systemclass::userdbFunctions::getpwnam(), and systemclass::userdb.

Change object's ownership.
| 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().

| bool filesystem::chroot | ( | const string & | p | ) |
Change the filesystem root.
| p | The filesystem path to chroot to. |
References string::str().

Copy a file on the filesystem.
| 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().

| bool filesystem::exists | ( | const string & | path | ) |
Check if a filesystem object exists.
| path | Relative or absolute path to the file. |
References string::cutat(), and pwdize().
Referenced by daemon::checkpid(), httpdfileshare::httpdfileshare(), fswatch::list(), configdb< appclass >::load(), httpdfileshare::run(), httpdscriptparser::run(), and httpd::sendfile().

Get full information about a file.
The value object contains the following keys:
| p | Path of the file. |
References systemclass::userdbFunctions::getpwuid(), string::printf(), pwdize(), string::str(), string::strlen(), transr(), and systemclass::userdb.
Referenced by chgrp(), chown(), fswatch::list(), and httpdfileshare::run().

| string * filesystem::getresource | ( | const string & | pat, | |
| const string & | rsrc, | |||
| const string & | idx = "" | |||
| ) |
Load a resource object associated with a filesystem object.
| pat | Path to the filesystem object. | |
| rsrc | Resource name. | |
| idx | Optional resource index. |
References string::cutat(), load(), string::str(), string::strcat(), string::strchr(), and string::strlen().

| bool filesystem::isdir | ( | const string & | path | ) |
Check if a filesystem object is a directory.
| path | Relative or absolute path to the file. |
References pwdize(), string::str(), string::strlen(), and transr().
Referenced by cd(), and httpdfileshare::run().

Load a file.
Returns a pointer to a newly allocated string object.
| _vpath | Relative or absolute path of the file. |
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().

| 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.
| path | Path to investigate. | |
| longformat | True if long format should be returned. | |
| showhidden | True if 'hidden' files should be listed. |
References string::copyafter(), string::copyuntil(), dir(), string::printf(), pwd(), pwdize(), string::str(), string::strchr(), and string::strstr().
Referenced by dir(), and fswatch::list().

| bool filesystem::mkdir | ( | const string & | dir | ) |
Create a directory.
| dir | Relative or absolute path for the directory. |
References _umask, string::cutat(), pwdize(), string::str(), string::strchr(), and string::strlen().

Move/rename a filesystem object.
| pold | The old path. | |
| pnew | The new path. |
References string::cutat(), pwdize(), string::strchr(), and string::strlen().
Referenced by logthread::run().

| string & filesystem::pwd | ( | void | ) |
Get current directory path.
References _cwd, and perthread< kind >::get().
Referenced by cgi::cgi(), ls(), and pwdize().

Convert a relative or aliaspath to an absolute path.
| str | The relative/alias path. |
References string::printf(), pwd(), string::str(), and string::strchr().
Referenced by exists(), getinfo(), isdir(), ls(), mkdir(), mv(), rm(), transr(), and transw().

| bool filesystem::rm | ( | const string & | path | ) |
Remove a filesystem object.
| path | Relative or absolute path to the file. |
References string::cutat(), pwdize(), string::str(), string::strchr(), and string::strlen().
Referenced by cp().

Save a string object into a file.
References file::close(), file::openwrite(), file::puts(), and string::strlen().
Referenced by daemon::checkpid(), smtpd::deliver(), value::saveshox(), value::savexml(), and daemon::~daemon().

| unsigned int filesystem::size | ( | const string & | path | ) |
Size up a filesystem object.
| path | Path to the object. |
References string::str(), and transr().
Referenced by httpdfileshare::run(), and httpd::sendfile().

Translate a relative/aliaspath to open a file for reading.
Returns a string containing the translated absolute Unix path.
| _vpath | Relative or alias 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().

Translate a relative/aliaspath to open a file for writing.
Returns a string containing the translated absolute Unix path.
| _vpath | Relative or alias 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().

| void filesystem::umask | ( | int | msk | ) |
1.6.1