libdigidocpp
digidoc::util::File Class Reference

#include <File.h>

Collaboration diagram for digidoc::util::File:
Collaboration graph

Static Public Member Functions

static std::string env (const std::string &varname)
static std::string cwd ()
static bool fileExists (const std::string &path)
static bool directoryExists (const std::string &path)
static f_string encodeName (const std::string &fileName)
static std::string decodeName (const f_string &localFileName)
static bool isRelative (const std::string &path)
static tm * modifiedTime (const std::string &path)
static std::string fileName (const std::string &path)
static std::string directory (const std::string &path)
static std::string path (const std::string &directory, const std::string &relativePath, bool unixStyle=false)
static std::string fullPathUrl (const std::string &fullDirectory, const std::string &relativeFilePath)
static std::string tempFileName ()
static std::string tempDirectory ()
static void createDirectory (const std::string &path) throw (IOException)
static std::string createTempDirectory () throw (IOException)
static unsigned long fileSize (const std::string &path) throw (IOException)
static std::vector< std::string > listFiles (const std::string &directory, bool relative=false, bool listEmptyDirectories=false, bool unixStyle=false) throw (IOException)
static void copyFile (const std::string &srcPath, const std::string &destPath, bool overwrite=true) throw (IOException)
static void moveFile (const std::string &srcPath, const std::string &destPath, bool overwrite=true) throw (IOException)
static void removeFile (const std::string &fname)
static void removeDirectory (const std::string &fname)
static void deleteTempFiles () throw (IOException)
static void removeDirectoryRecursively (const std::string &dname) throw (IOException)
static bool compareUri (const std::string &a, const std::string &b)
static std::string fromUri (const std::string &uri)
static std::string toUri (const std::string &path)
static FILE * fopen (const std::string &filename, const std::string &mode)

Static Public Attributes

static std::stack< std::string > tempFiles

Static Private Member Functions

static std::vector< std::string > getDirSubElements (const std::string &directory, bool relative, bool filesOnly, bool unixStyle) throw (IOException)
static std::string convertUTF8 (const std::string &str_in, bool to_UTF)

Detailed Description

Implements common file-system operations for current platform

Author
Janari Põld

Definition at line 42 of file File.h.

Member Function Documentation

bool digidoc::util::File::compareUri ( const std::string &  a,
const std::string &  b 
)
static

Definition at line 890 of file File.cpp.

References hexToUpper().

Referenced by digidoc::SignatureBES::checkReferencesToDocs().

Here is the call graph for this function:

Here is the caller graph for this function:

std::string digidoc::util::File::convertUTF8 ( const std::string &  str_in,
bool  to_UTF 
)
staticprivate

Helper method for converting from non-UTF-8 encoded strings to UTF-8. Supported LANG values for Linux: see /usr/share/i18n/SUPPORTED. Supported encodings for libiconv: see iconv –list .

Note! If non-ASCII characters are used we assume a proper LANG value!!!

Parameters
str_inThe string to be converted.
Returns
Returns the input string in UTF-8.

Definition at line 79 of file File.cpp.

void digidoc::util::File::copyFile ( const std::string &  srcPath,
const std::string &  destPath,
bool  overwrite = true 
) throw (IOException)
static

Copies file from source srcPath to destination destPath.

Parameters
srcPathsource full file path.
destPathdestination full file path.
overwritewhether to overwrite existing file.
Exceptions
IOExceptionexception is thrown if overwrite flag is set to false and destination file already exists. Or the file copy operation failed.

Definition at line 576 of file File.cpp.

References THROW_IOEXCEPTION.

Referenced by digidoc::Document::saveAs().

Here is the caller graph for this function:

void digidoc::util::File::createDirectory ( const std::string &  path) throw (IOException)
static

Creates directory recursively. Also access rights can be omitted. Defaults are 700 in unix.

Parameters
pathfull path of the directory created.
modedirectory access rights, optional parameter, default value 0700 (owner: rwx, group: —, others: —)
Exceptions
IOExceptionexception is thrown if the directory creation failed.

Definition at line 404 of file File.cpp.

References DEBUG, f_string, and THROW_IOEXCEPTION.

Referenced by digidoc::ZipSerializePrivate::extractCurrentFile(), and digidoc::XmlConfPrivate::serializeUserConf().

Here is the caller graph for this function:

std::string digidoc::util::File::createTempDirectory ( ) throw (IOException)
static

Creates temporary directory.

Returns
returns the created temporary directory.
Exceptions
IOExceptionthrows exception if the directory creation failed.
See Also
createDirectory(const std::string& path)

Definition at line 454 of file File.cpp.

Referenced by digidoc::ZipSerialize::extract(), and digidoc::DDoc::loadFile().

Here is the caller graph for this function:

std::string digidoc::util::File::cwd ( )
static

Definition at line 145 of file File.cpp.

Referenced by digidoc::XmlConf::getDefaultConfDir().

Here is the caller graph for this function:

std::string digidoc::util::File::decodeName ( const f_string localFileName)
static

Decodes path from std lib path

Parameters
localFileNamepath
Returns
decoded path

Definition at line 243 of file File.cpp.

Referenced by decodeParameter(), digidoc::BDoc::parseManifestAndLoadFiles(), and digidoc::XmlConfPrivate::XmlConfPrivate().

Here is the caller graph for this function:

void digidoc::util::File::deleteTempFiles ( ) throw (IOException)
static

Tries to delete all temporary files and directories whose names were handled out with tempFileName, tempDirectory and createTempDirectory. The deletion of directories is recursive.

Definition at line 834 of file File.cpp.

Referenced by digidoc::terminate().

Here is the caller graph for this function:

std::string digidoc::util::File::directory ( const std::string &  path)
static

Parses file path and returns directory from file full path.

Parameters
pathfull path of the file.
Returns
returns directory part of the file full path.

Definition at line 326 of file File.cpp.

References PATH_DELIMITER.

Referenced by digidoc::ZipSerializePrivate::extractCurrentFile(), digidoc::XmlConf::getDefaultConfDir(), and digidoc::XmlConf::getUserConfDir().

Here is the caller graph for this function:

bool digidoc::util::File::directoryExists ( const std::string &  path)
static

Checks whether directory exists and is type of directory.

Parameters
pathpath to the directory, which existence is checked.
Returns
returns true if the directory is a directory and it exists.

Definition at line 273 of file File.cpp.

References f_stat, f_statbuf, and f_string.

Referenced by digidoc::DirectoryX509CertStore::loadCerts(), and digidoc::XmlConfPrivate::serializeUserConf().

Here is the caller graph for this function:

std::string digidoc::util::File::encodeName ( const std::string &  fileName)
static
std::string digidoc::util::File::env ( const std::string &  varname)
static

Definition at line 159 of file File.cpp.

References f_string.

Referenced by digidoc::XmlConfPrivate::XmlConfPrivate().

Here is the caller graph for this function:

bool digidoc::util::File::fileExists ( const std::string &  path)
static

Checks whether file exists and is type of file.

Parameters
pathpath to the file, which existence is checked.
Returns
returns true if the file is a file and it exists.

Definition at line 253 of file File.cpp.

References f_stat, f_statbuf, and f_string.

Referenced by digidoc::BDoc::addDocument(), digidoc::BDoc::parseManifestAndLoadFiles(), digidoc::XmlConf::setOCSP(), digidoc::XmlConfPrivate::setUserConf(), and digidoc::XmlConf::XmlConf().

Here is the caller graph for this function:

std::string digidoc::util::File::fileName ( const std::string &  path)
static

Parses file path and returns file name from file full path.

Parameters
pathfull path of the file.
Returns
returns file name from the file full path in UTF-8.

Definition at line 314 of file File.cpp.

Referenced by digidoc::BDoc::parseManifestAndLoadFiles().

Here is the caller graph for this function:

unsigned long digidoc::util::File::fileSize ( const std::string &  path) throw (IOException)
static

Checks that file is a file and it exists, if the file exists returns its size in bytes.

Parameters
pathfull path of the file.
Returns
size of the file in bytes.
Exceptions
IOExceptionthrows exception if the file does not exists.

Definition at line 468 of file File.cpp.

References f_stat, f_statbuf, f_string, and THROW_IOEXCEPTION.

Referenced by digidoc::Document::getSize().

Here is the caller graph for this function:

FILE * digidoc::util::File::fopen ( const std::string &  filename,
const std::string &  mode 
)
static

Definition at line 750 of file File.cpp.

References f_fopen.

Referenced by digidoc::ZipSerializePrivate::extractCurrentFile(), and digidoc::ZipSerialize::save().

Here is the caller graph for this function:

std::string digidoc::util::File::fromUri ( const std::string &  uri)
static

Definition at line 895 of file File.cpp.

References i.

std::string digidoc::util::File::fullPathUrl ( const std::string &  fullDirectory,
const std::string &  relativeFilePath 
)
static

Constructs the full file path in the format "file:///fullpath" in URI encoding.

Parameters
fullDirectoryfull directory path to the relativeFilePath
relativeFilePathfile name to be appended to the full path
Returns
full file path in the format "file:///fullpath" in URI encoding.

Definition at line 763 of file File.cpp.

References toUri().

Referenced by digidoc::XmlConf::getDsigXsdPath(), digidoc::XmlConf::getManifestXsdPath(), and digidoc::XmlConf::getXadesXsdPath().

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector< std::string > digidoc::util::File::getDirSubElements ( const std::string &  directory,
bool  relative,
bool  filesOnly,
bool  unixStyle 
) throw (IOException)
staticprivate

Lists files or sub directories in directory. If flag filesOnly is set to true returns ONLY files, otherwise returns ONLY directories.

Parameters
directoryfull path of the directory.
relativeshould the returned file list be relative to the directory.
filesOnlyif set to true, returns only files, otherwise returns only directories.
unixStyleshould the returned file path entries in the file list use the unix style path separators.
Exceptions
IOExceptionthrows exception if the directory listing failed.

Definition at line 652 of file File.cpp.

References FALSE, INVALID_HANDLE_VALUE, and THROW_IOEXCEPTION.

bool digidoc::util::File::isRelative ( const std::string &  path)
static

Returns true if the path is relative

Returns
returns true if the path is relative

Definition at line 489 of file File.cpp.

References f_string.

Referenced by digidoc::XmlConf::getCertStorePath().

Here is the caller graph for this function:

std::vector< std::string > digidoc::util::File::listFiles ( const std::string &  directory,
bool  relative = false,
bool  listEmptyDirectories = false,
bool  unixStyle = false 
) throw (IOException)
static

Returns list of files (and empty directories, if listEmptyDirectories is set) found in the directory directory.

Parameters
directoryfull path of the directory.
relativeshould the returned file list be relative to the directory. Default value is false, meaning returned file listing has full file paths.
listEmptyDirectoriesshould the returned file list contain also empty directories. Default value is false, meaning no empty directories are returned.
unixStyleshould the returned file path entries in the file list use the unix style path separators. Default value is false, meaning operating system specific path separators are used.
Exceptions
IOExceptionthrows exception if the directory listing failed.

Definition at line 519 of file File.cpp.

References PATH_DELIMITER.

Referenced by digidoc::DirectoryX509CertStore::loadCerts(), and digidoc::BDoc::parseManifestAndLoadFiles().

Here is the caller graph for this function:

tm * digidoc::util::File::modifiedTime ( const std::string &  path)
static

Returns last modified time

Parameters
pathpath which modified time will be checked.
Returns
returns given path modified time.

Definition at line 300 of file File.cpp.

References f_stat, f_statbuf, and f_string.

Referenced by digidoc::ZipSerialize::save().

Here is the caller graph for this function:

void digidoc::util::File::moveFile ( const std::string &  srcPath,
const std::string &  destPath,
bool  overwrite = true 
) throw (IOException)
static

Moves file from source srcPath to destination destPath.

Parameters
srcPathsource full file path.
destPathdestination full file path.
overwritewhether to overwrite existing file.
Exceptions
IOExceptionexception is thrown if overwrite flag is set to false and destination file already exists. Or the file move operation failed.

Definition at line 612 of file File.cpp.

References f_remove, f_rename, f_string, THROW_IOEXCEPTION, and WARN.

Referenced by digidoc::ZipSerialize::save().

Here is the caller graph for this function:

std::string digidoc::util::File::path ( const std::string &  directory,
const std::string &  relativePath,
bool  unixStyle = false 
)
static

Creates full path from directory name and relative path.

Parameters
directorydirectory path.
relativePathrelative path.
unixStylewhen set to true returns path with unix path separators, otherwise returns with operating system specific path separators. Default value is false.
Returns
returns full path.

Definition at line 343 of file File.cpp.

References PATH_DELIMITER.

Referenced by digidoc::DDocLibrary::DDocLibrary(), digidoc::ZipSerializePrivate::extractCurrentFile(), digidoc::XmlConf::getCertStorePath(), digidoc::DDoc::loadFile(), digidoc::BDoc::parseManifestAndLoadFiles(), digidoc::XmlConfPrivate::read(), digidoc::BDoc::readMimetype(), and digidoc::XmlConfPrivate::serializeUserConf().

Here is the caller graph for this function:

void digidoc::util::File::removeDirectory ( const std::string &  dname)
static

Deletes the directory named dname. The directory must be empty.

Parameters
fnamefull file or directory fname.

Definition at line 792 of file File.cpp.

References f_string, and WARN.

void digidoc::util::File::removeDirectoryRecursively ( const std::string &  dname) throw (IOException)
static

Tries to delete this directory along with its contents, recursively.

Parameters
dnamefull directory name

Definition at line 808 of file File.cpp.

References DEBUG.

void digidoc::util::File::removeFile ( const std::string &  fname)
static

Deletes the filesystem object named fname. Mysteriously fails to delete empty directories on Windows, so use removeDirectory instead.

Parameters
fnamefull file or directory fname.

Definition at line 780 of file File.cpp.

References f_remove, f_string, and WARN.

std::string digidoc::util::File::tempDirectory ( )
static
Returns
returns temporary directory name.

Definition at line 392 of file File.cpp.

References PATH_DELIMITER.

std::string digidoc::util::File::tempFileName ( )
static
std::string digidoc::util::File::toUri ( const std::string &  path)
static

Helper method for converting strings with non-ascii characters to the URI format (HH for each non-ascii character).

Not converting: (From RFC 2396 "URI Generic Syntax") reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | "," mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"

Parameters
str_inthe string to be converted
Returns
the string converted to the URI format

Definition at line 856 of file File.cpp.

References i.

Referenced by digidoc::SignatureBES::checkReferencesToDocs(), fullPathUrl(), and digidoc::SignatureBES::prepareSignedInfo().

Here is the caller graph for this function:

Member Data Documentation

std::stack< std::string > digidoc::util::File::tempFiles
static

Definition at line 70 of file File.h.


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