DUNE-DAQ
DUNE Trigger and Data Acquisition software
|
Wrapper for file operations. More...
#include <File.hpp>
Public Types | |
typedef std::vector< OksSystem::File > | file_list_t |
Public Member Functions | |
File (const std::string &name) | |
File (const char *name) | |
File (const File &other) | |
virtual | ~File () |
operator std::string () const throw () | |
operator const char * () const throw () | |
operator bool () const throw () | |
bool | equals (const File &other) const throw () |
compare two files */ | |
operator size_t () const | |
const std::string & | full_name () const throw () |
full name for file */ | |
const char * | c_full_name () const throw () |
std::string | short_name () const throw () |
short name for file */ | |
std::string | parent_name () const throw () |
path of directory containing file */ | |
std::string | extension () const throw () |
extension for file */ | |
int | depth () const throw () |
depth of the file */ | |
OksSystem::File | parent () const |
parent of the current file */ | |
OksSystem::File | child (const std::string &name) const |
named child of the current directory */ | |
OksSystem::File | temporary (const std::string &prefix) const |
bool | exists () const throw () |
does the file exist */ | |
mode_t | permissions () const |
permissions for the file */ | |
std::string | pretty_permissions () const |
pretty permissions for the file */ | |
size_t | size () const |
size of file */ | |
uid_t | owner_id () const |
owner id of file */ | |
User | owner () const |
owner of the file */ | |
gid_t | group () const |
group of file */ | |
bool | is_regular () const |
is the file a directory */ | |
bool | is_directory () const |
is the file a regular file */ | |
bool | is_fifo () const |
is the file a named pipe */ | |
std::string | file_type () const |
type of the file */ | |
file_list_t | directory () const |
list of file in directory */ | |
void | unlink () const |
deletes (unlinks) file */ | |
void | rmdir () const |
deletes directory */ | |
void | remove () const |
recursively delete files and directories */ | |
void | rename (const File &other) const |
rename or moves the file */ | |
void | permissions (mode_t permissions) const |
sets the type of the file */ | |
void | make_dir (mode_t permissions) const |
creates a directory */ | |
void | make_path (mode_t permissions) const |
creates a full path */ | |
void | make_fifo (mode_t permissions) const |
creates a FIFO (named pipe) */ | |
void | ensure_path (mode_t permissions) const |
creates the parent path */ | |
std::istream * | input () const |
returns an input stream from the file*/ | |
std::ostream * | output (bool append=false) const |
returns an output stream to the file*/ | |
Static Public Member Functions | |
static std::string | protocol (const std::string &url) throw () |
extracts the protocol part of an url */ | |
static std::string | extension (const std::string &url) throw () |
extracts the extension of a path or an url */ | |
static std::string | uri (const std::string &url) throw () |
extracts the local path of an url */ | |
static std::string | short_name (const std::string &url) throw () |
extracts the short file name of an url */ | |
static int | depth (const std::string &path) throw () |
calculates depth of a path */ | |
static std::string | first_line (const std::string &text) |
extracts the first line of a text */ | |
static File | from_url (const std::string &url) |
build a file out of an URL */ | |
static std::string | working_directory () |
current directory of process */ | |
static void | working_directory (const File &dir) |
set working directory of process */ | |
static std::string | expand_home (const std::string path) |
resolve home directory */ | |
static std::string | pretty_permissions (mode_t permissions) |
pretty prints permissions */ | |
static std::string | to_string (mode_t permissions) throw () |
converts permission to string */ | |
static std::string | pretty_open_flag (int flags) |
pretty prints open flags */ | |
static std::string | pretty_size (size_t size, bool cut_small) |
pretty prints a file size */ | |
Static Public Attributes | |
static const char *const | FILE_FLAG_STR = "-rwxS" |
column headers for display of permissions */ | |
static const char *const | FILE_PROTOCOL = "file" |
string for the file protocol */ | |
Protected Member Functions | |
void | set_name (const std::string &name) |
sets the name of the file */ | |
mode_t | get_mode () const |
get mode associated with file (permission + type) */ | |
Static Protected Member Functions | |
static int | unit (int u) |
calculates the value of a computer unit of order n (i.e KB,GB, etc */ | |
Protected Attributes | |
std::string | m_full_name |
full name (path) of the file */ | |
Static Protected Attributes | |
static const char *const | HUMAN_SIZE_STR [] = { "B", "KB", "MB", "GB" } |
strings for pretty printing file sizes */ | |
static const char *const | HUMAN_OPEN_STR [] = { "READ", "WRITE", "NOBLOCK", "APPEND", "CREATE", "TRUNCATE","EXCLUSIVE" } |
strings for pretty printing open flags */ | |
static const int | KILOBYTE = 1024 |
number of bytes in a kilobyte */ | |
static const char *const | FILE_COMMAND_PATH = "/usr/bin/file" |
Wrapper for file operations.
This class represents a file. it provides tools to manipulate files in a simple way. All methods throw ers issues in case of error. Internally, files are handled as canonical paths i.e with ./ ../ and symlinks resolved.
std::vector<OksSystem::File> OksSystem::File::file_list_t |
OksSystem::File::File | ( | const std::string & | name | ) |
Constructor
Definition at line 296 of file File.cpp.
OksSystem::File::File | ( | const char * | c_name | ) |
Constructor This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 304 of file File.cpp.
OksSystem::File::File | ( | const File & | other | ) |
const char * OksSystem::File::c_full_name | ( | ) | const | |||
throw | ( | ) |
Definition at line 412 of file File.cpp.
OksSystem::File OksSystem::File::child | ( | const std::string & | name | ) | const |
int OksSystem::File::depth | ( | ) | const | |||
throw | ( | ) |
|
static |
calculates depth of a path */
Calculates the depth of a file. This depth is the number of parent directories. Files in the root directory have depht of 0, other files have a depth of their parent's depth + 1
path | to analyze |
Definition at line 116 of file File.cpp.
OksSystem::File::file_list_t OksSystem::File::directory | ( | ) | const |
list of file in directory */
Builds a vector containing all the files contained in a directory
OksSystem::OpenFail | if the directory could not be openend |
OksSystem::CloseFail | if the directory cannot be closed |
Definition at line 614 of file File.cpp.
void OksSystem::File::ensure_path | ( | mode_t | perm | ) | const |
creates the parent path */
Makes sure that the path for a file exists This is done by calling make_path
on the parent directory
permissions | permissions used to create directories |
Definition at line 776 of file File.cpp.
bool OksSystem::File::equals | ( | const File & | other | ) | const | |
throw | ( | ) |
compare two files */
Comparison operator As path are canonicalized, we simply compare the full paths.
other | file to compare this file to |
bool OksSystem::File::exists | ( | ) | const | |||
throw | ( | ) |
does the file exist */
Checks if the file exists in the fileOksSystem
true
if the file exists, false otherwise ers::IOIssue | if an error occurs |
Definition at line 472 of file File.cpp.
|
static |
resolve home directory */
Expands a file containing a home directory reference (~user).
Definition at line 185 of file File.cpp.
std::string OksSystem::File::extension | ( | ) | const | |||
throw | ( | ) |
extension for file */
|
static |
std::string OksSystem::File::file_type | ( | ) | const |
type of the file */
Definition at line 600 of file File.cpp.
|
static |
extracts the first line of a text */
Extracts the first line of a text
text | the text to process |
Definition at line 139 of file File.cpp.
|
static |
const std::string & OksSystem::File::full_name | ( | ) | const | |||
throw | ( | ) |
full name for file */
|
protected |
get mode associated with file (permission + type) */
Extracts the mode information of the file. This is used to determine both the file type and the file permissions
OksSystem::FStatFail | if fstat fails |
Definition at line 485 of file File.cpp.
gid_t OksSystem::File::group | ( | ) | const |
std::istream * OksSystem::File::input | ( | ) | const |
returns an input stream from the file*/
Conversion into a input stream pointer This actually creates a new input stream that reads from the file.
ers::IOIssue | if an error occurs or the file does not exist |
Definition at line 815 of file File.cpp.
bool OksSystem::File::is_directory | ( | ) | const |
is the file a regular file */
Checks if the file a directory
true
if the file is a directory ers::IOIssue | if an error occurs or the file does not exist |
Definition at line 584 of file File.cpp.
bool OksSystem::File::is_fifo | ( | ) | const |
is the file a named pipe */
Checks if the file a named pipe (FIFO)
true
if the file is named pipe (FIFO) ers::IOIssue | if an error occurs or the file does not exist |
bool OksSystem::File::is_regular | ( | ) | const |
is the file a directory */
Checks if the file a regular file (i.e not a directory, named pipe or anything else).
true
if the file is regular ers::IOIssue | if an error occurs or the file does not exist |
void OksSystem::File::make_dir | ( | mode_t | perm | ) | const |
creates a directory */
Creates a directory The current object is taken as the name of the directory to create.
perm | the permissions to associate with the directory |
chmod
to match the permissions Definition at line 717 of file File.cpp.
void OksSystem::File::make_fifo | ( | mode_t | perm | ) | const |
creates a FIFO (named pipe) */
Creates a named pipe (FIFO)
perm | the permission to give the pipe |
Definition at line 786 of file File.cpp.
void OksSystem::File::make_path | ( | mode_t | perm | ) | const |
creates a full path */
Builds a full path. The current object is taken as the name of a directory to create. This method creates all the parent directories as needed
permissions | the permissions to associate with the directory |
permissions
ORed with 0700. This is needed to ensure we can actually write into the directories we create. Definition at line 761 of file File.cpp.
OksSystem::File::operator bool | ( | ) | const | |||
throw | ( | ) |
OksSystem::File::operator const char * | ( | ) | const | |||
throw | ( | ) |
OksSystem::File::operator size_t | ( | ) | const |
OksSystem::File::operator std::string | ( | ) | const | |||
throw | ( | ) |
std::ostream * OksSystem::File::output | ( | bool | append = false | ) | const |
returns an output stream to the file*/
Conversion into an output stream pointer This actually creates a new output stream that writes to the file.
append | is the file opened in append mode |
ers::IOIssue | if an error occurs |
OksSystem::User OksSystem::File::owner | ( | ) | const |
uid_t OksSystem::File::owner_id | ( | ) | const |
OksSystem::File OksSystem::File::parent | ( | ) | const |
parent of the current file */
Definition at line 446 of file File.cpp.
std::string OksSystem::File::parent_name | ( | ) | const | |||
throw | ( | ) |
mode_t OksSystem::File::permissions | ( | ) | const |
void OksSystem::File::permissions | ( | mode_t | perm | ) | const |
|
static |
pretty prints open flags */
Builds a prettyfied version of flags used by the open
OksSystem call
flags | as passed to open |
Definition at line 227 of file File.cpp.
std::string OksSystem::File::pretty_permissions | ( | ) | const |
pretty permissions for the file */
ers::IOIssue | if an error occurs or the file does not exist |
Definition at line 509 of file File.cpp.
|
static |
pretty prints permissions */
Builds a prettyfied version of permissions. This should look similar to what ls
returns with the -l flag
permissions | the permission to beautify |
Definition at line 205 of file File.cpp.
|
static |
pretty prints a file size */
Builds a human readable textual description of a file size. The file size is expressed in Gigabytes (GB), Megabytes (MB) and Kilobytes (KB) and Bytes (B).
size | the size of the file |
cut_small | should the display only contain the highest quantity? For example if a file is 1 gigabyte and 20 bytes, if cut_small is true , then the 20 bytes are ignored. |
Definition at line 271 of file File.cpp.
|
static |
extracts the protocol part of an url */
Extracts the protocol part of an url. The protocol part is everything until the colon (:)
url | an url |
Definition at line 66 of file File.cpp.
void OksSystem::File::remove | ( | ) | const |
recursively delete files and directories */
Recursively delete files and directories. If the file is a directory, all its child are deleted recursively.
OksSystem::UnlinkFail | if unlink fails |
Definition at line 665 of file File.cpp.
void OksSystem::File::rename | ( | const File & | other | ) | const |
rename or moves the file */
Renames or moves a file.
new_name | the new name of the file |
ers::IOIssue | if an error occurs or the file does not exist |
Definition at line 686 of file File.cpp.
void OksSystem::File::rmdir | ( | ) | const |
|
protected |
sets the name of the file */
Sets the name for a file. The path name is first expanded and the canonlicalized. Expension means the following
The path is then made canonical, this implies removing all ./ and ../ sequences, and resolving all symbolic links.
name | the name of the file |
Definition at line 380 of file File.cpp.
std::string OksSystem::File::short_name | ( | ) | const | |||
throw | ( | ) |
short name for file */
Definition at line 419 of file File.cpp.
|
static |
size_t OksSystem::File::size | ( | ) | const |
OksSystem::File OksSystem::File::temporary | ( | const std::string & | prefix | ) | const |
Definition at line 455 of file File.cpp.
|
static |
converts permission to string */
Converts permissions into a string
permissions | the permissions |
Definition at line 518 of file File.cpp.
|
staticprotected |
calculates the value of a computer unit of order n (i.e KB,GB, etc */
Definition at line 256 of file File.cpp.
void OksSystem::File::unlink | ( | ) | const |
|
static |
extracts the local path of an url */
Extacts the uri part of an url. The uri of an url is everything except the protocol part In the case of file
or http
urls, the uri is the local path
url | an url |
Definition at line 101 of file File.cpp.
|
static |
current directory of process */
Definition at line 160 of file File.cpp.
|
static |
set working directory of process */
|
staticprotected |
|
static |
|
static |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
protected |