blocxx
BLOCXX_NAMESPACE::FileSystem Namespace Reference

The purpose of the FileSystem class is to provide an abstraction layer over the platform dependant functionality related to a file system. More...

Namespaces

namespace  Path
 

Classes

struct  NullFactory
 

Typedefs

typedef GlobalPtr< FileSystemMockObject, NullFactoryFileSystemMockObject_t
 

Functions

BLOCXX_COMMON_API File openFile (const String &path)
 Open a file for read/write and return an File object that can be used for reading and writing.
 
BLOCXX_COMMON_API File createFile (const String &path)
 Create the file for the given name.
 
BLOCXX_COMMON_API File openOrCreateFile (const String &path)
 Opens or creates the file for the given name.
 
BLOCXX_COMMON_API File openForAppendOrCreateFile (const String &path)
 Opens the file for the given name to append data or create if it does not exist.
 
BLOCXX_COMMON_API File createAutoDeleteTempFile (const String &dir=String())
 Create a tempororary file that will be removed when the returned File object is closed.
 
BLOCXX_COMMON_API File createTempFile (String &filePath, const String &dir=String())
 Create a tempororary file in an optional directory.
 
BLOCXX_COMMON_API int changeFileOwner (const String &filename, const UserId &userId)
 Change the given file ownership.
 
BLOCXX_COMMON_API bool exists (const String &path)
 
BLOCXX_COMMON_API bool isExecutable (const String &path)
 Tests if a file is executable.
 
BLOCXX_COMMON_API bool canRead (const String &path)
 
BLOCXX_COMMON_API bool canWrite (const String &path)
 
BLOCXX_COMMON_API bool isLink (const String &path)
 Tests if a file is a symbolic link.
 
BLOCXX_COMMON_API bool isDirectory (const String &path)
 
BLOCXX_COMMON_API bool changeDirectory (const String &path)
 Change to the given directory.
 
BLOCXX_COMMON_API bool makeDirectory (const String &path, int mode=0777)
 Create a directory.
 
BLOCXX_COMMON_API bool getFileSize (const String &path, Int64 &size)
 Get the size of the file in bytes.
 
BLOCXX_COMMON_API UInt64 fileSize (FileHandle fh)
 Get the size of a file from the file handle.
 
BLOCXX_COMMON_API bool removeDirectory (const String &path)
 Remove the given directory.
 
BLOCXX_COMMON_API bool removeFile (const String &path)
 Remove the given file.
 
BLOCXX_COMMON_API bool getDirectoryContents (const String &path, StringArray &dirEntries)
 Get the names of the files (and directories) in the given directory.
 
BLOCXX_COMMON_API bool renameFile (const String &oldFileName, const String &newFileName)
 Rename the given file to the new name.
 
BLOCXX_COMMON_API size_t read (const FileHandle &hdl, void *bfr, size_t numberOfBytes, Int64 offset=-1L)
 Read data from file.
 
BLOCXX_COMMON_API size_t write (FileHandle hdl, const void *bfr, size_t numberOfBytes, Int64 offset=-1L)
 Write data to a file.
 
BLOCXX_COMMON_API Int64 seek (const FileHandle &hdl, Int64 offset, int whence)
 Seek to a given offset within the file.
 
BLOCXX_COMMON_API Int64 tell (const FileHandle &hdl)
 
BLOCXX_COMMON_API void rewind (const FileHandle &hdl)
 Position the file pointer associated with the given file handle to the beginning of the file.
 
BLOCXX_COMMON_API int close (const FileHandle &hdl)
 Close file handle.
 
BLOCXX_COMMON_API int flush (FileHandle &hdl)
 Flush any buffered data to the file if buffering supported.
 
BLOCXX_COMMON_API String getFileContents (const String &filename)
 Read and return the contents of a text file.
 
BLOCXX_COMMON_API StringArray getFileLines (const String &filename)
 Read and return the lines of a test file.
 
BLOCXX_COMMON_API String readSymbolicLink (const String &path)
 Read the value of a symbolic link.
 

Variables

FileSystemMockObject_t g_fileSystemMockObject = { 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 
GlobalString COMPONENT_NAME = { "blocxx", 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 

Detailed Description

The purpose of the FileSystem class is to provide an abstraction layer over the platform dependant functionality related to a file system.

Typedef Documentation

◆ FileSystemMockObject_t

Function Documentation

◆ canRead()

bool BLOCXX_NAMESPACE::FileSystem::canRead ( const String & path)
Returns
true if the file exists and can be read

Definition at line 601 of file PosixFileSystem.cpp.

References _ACCESS, BLOCXX_NAMESPACE::String::c_str(), and g_fileSystemMockObject.

◆ canWrite()

bool BLOCXX_NAMESPACE::FileSystem::canWrite ( const String & path)
Returns
true if the file exists and can be written

Definition at line 611 of file PosixFileSystem.cpp.

References _ACCESS, BLOCXX_NAMESPACE::String::c_str(), and g_fileSystemMockObject.

◆ changeDirectory()

bool BLOCXX_NAMESPACE::FileSystem::changeDirectory ( const String & path)

Change to the given directory.

Parameters
pathThe directory to change to
Returns
true if the operation succeeds. Otherwise false.

Definition at line 662 of file PosixFileSystem.cpp.

References _CHDIR, BLOCXX_NAMESPACE::String::c_str(), and g_fileSystemMockObject.

◆ changeFileOwner()

int BLOCXX_NAMESPACE::FileSystem::changeFileOwner ( const String & filename,
const UserId & userId )

Change the given file ownership.

Parameters
filenameThe name of the file to change ownership on.
userIdThe user id to change ownership to
Returns
0 on success. Otherwise -1

Definition at line 244 of file PosixFileSystem.cpp.

References BLOCXX_NAMESPACE::String::c_str().

◆ close()

int BLOCXX_NAMESPACE::FileSystem::close ( const FileHandle & hdl)

Close file handle.

Parameters
hdlThe file handle to close.
Returns
0 on success. Otherwise -1.

Definition at line 983 of file PosixFileSystem.cpp.

References g_fileSystemMockObject.

◆ createAutoDeleteTempFile()

File BLOCXX_NAMESPACE::FileSystem::createAutoDeleteTempFile ( const String & dir = String())

Create a tempororary file that will be removed when the returned File object is closed.

Parameters
dirThe directory to create the temporary file in.
Returns
On success a File object that can be used for reading and writing. Otherwise a null File object. The underlying file represented by this File object will be deleted when the file is closed.

Definition at line 390 of file PosixFileSystem.cpp.

References BLOCXX_LOG_ERROR, BLOCXX_NAMESPACE::String::c_str(), COMPONENT_NAME, BLOCXX_NAMESPACE::String::empty(), BLOCXX_NAMESPACE::String::endsWith(), g_fileSystemMockObject, BLOCXX_NAMESPACE::AutoPtrVec< X >::get(), BLOCXX_NAMESPACE::String::length(), and BLOCXX_NAMESPACE::SafeCString::strcpy_check().

Referenced by BLOCXX_NAMESPACE::TempFileBuffer::buffer_to_device().

◆ createFile()

File BLOCXX_NAMESPACE::FileSystem::createFile ( const String & path)

Create the file for the given name.

Parameters
pathThe name of the file to create.
Returns
On success an File object that can be used for reading and writing. Otherwise a NULL File object. If the file exists, a NULL File object will be returned.

Definition at line 275 of file PosixFileSystem.cpp.

References BLOCXX_NAMESPACE::String::c_str(), and g_fileSystemMockObject.

◆ createTempFile()

File BLOCXX_NAMESPACE::FileSystem::createTempFile ( String & filePath,
const String & dir = String() )

Create a tempororary file in an optional directory.

Parameters
filePathOutput parameter that will contain the name of the temporary file on return. It is the responsibility of the caller to delete this file when it is no longer needed.
dirThe directory to create the temporary file in.
Returns
On success a File object that can be used for reading and writing. Otherwise a null File object. The underlying file represented by this File object will still remain on the file system after it is closed. The caller is responsible for removing it.

Definition at line 345 of file PosixFileSystem.cpp.

References BLOCXX_NAMESPACE::String::c_str(), BLOCXX_NAMESPACE::String::empty(), BLOCXX_NAMESPACE::String::endsWith(), BLOCXX_NAMESPACE::String::erase(), g_fileSystemMockObject, BLOCXX_NAMESPACE::AutoPtrVec< X >::get(), BLOCXX_NAMESPACE::String::length(), and BLOCXX_NAMESPACE::SafeCString::strcpy_check().

Referenced by BLOCXX_NAMESPACE::TempFileBuffer::buffer_to_device().

◆ exists()

bool BLOCXX_NAMESPACE::FileSystem::exists ( const String & path)
Returns
true if the file exists (and false otherwise).

Definition at line 577 of file PosixFileSystem.cpp.

References _ACCESS, BLOCXX_NAMESPACE::String::c_str(), and g_fileSystemMockObject.

Referenced by BLOCXX_NAMESPACE::ServerSocketImpl::doListenUDS(), and BLOCXX_NAMESPACE::FileAppender::doProcessLogMessage().

◆ fileSize()

UInt64 BLOCXX_NAMESPACE::FileSystem::fileSize ( FileHandle fh)

Get the size of a file from the file handle.

Parameters
fhHandle of the desired file.
Returns
The size of the file.

Definition at line 937 of file PosixFileSystem.cpp.

References BLOCXX_THROW_ERRNO_MSG, and g_fileSystemMockObject.

◆ flush()

int BLOCXX_NAMESPACE::FileSystem::flush ( FileHandle & hdl)

Flush any buffered data to the file if buffering supported.

Parameters
hdlThe file handle to flush the buffer on.

Definition at line 997 of file PosixFileSystem.cpp.

References g_fileSystemMockObject.

◆ getDirectoryContents()

bool BLOCXX_NAMESPACE::FileSystem::getDirectoryContents ( const String & path,
StringArray & dirEntries )

Get the names of the files (and directories) in the given directory.

Parameters
pathThe name of the directory to get the contents of.
dirEntriesThe directory contents will be placed in this array.
Returns
true if the operation succeeds. Otherwise false.

Definition at line 726 of file PosixFileSystem.cpp.

References BLOCXX_NAMESPACE::Array< T >::append(), BLOCXX_FILENAME_SEPARATOR, BLOCXX_NAMESPACE::String::c_str(), BLOCXX_NAMESPACE::Array< T >::clear(), BLOCXX_NAMESPACE::String::endsWith(), and g_fileSystemMockObject.

◆ getFileContents()

String BLOCXX_NAMESPACE::FileSystem::getFileContents ( const String & filename)

Read and return the contents of a text file.

If the file contains a null character ('\0') then only previous data will be returned.

Parameters
filenameThe name of the file to read
Exceptions
FileSystemExceptionif the file doesn't exist or reading fails for any reason.

Definition at line 1010 of file PosixFileSystem.cpp.

References BLOCXX_THROW, BLOCXX_NAMESPACE::String::c_str(), g_fileSystemMockObject, and BLOCXX_NAMESPACE::OStringStream::toString().

Referenced by getFileLines().

◆ getFileLines()

StringArray BLOCXX_NAMESPACE::FileSystem::getFileLines ( const String & filename)

Read and return the lines of a test file.

If the file contains a null character ('\0') then only previous data will be returned.

Parameters
filenameThe name of the file to read
Exceptions
FileSystemExceptionif the file doesn't exist or reading fails for any reason.

Definition at line 1027 of file PosixFileSystem.cpp.

References g_fileSystemMockObject, getFileContents(), and BLOCXX_NAMESPACE::String::tokenize().

◆ getFileSize()

bool BLOCXX_NAMESPACE::FileSystem::getFileSize ( const String & path,
Int64 & size )

Get the size of the file in bytes.

Parameters
pathThe name of the file to get the size for.
sizePut the size of the file in this variable.
Returns
true if the operation succeeds. Otherwise false.

Definition at line 682 of file PosixFileSystem.cpp.

References BLOCXX_NAMESPACE::String::c_str(), and g_fileSystemMockObject.

◆ isDirectory()

bool BLOCXX_NAMESPACE::FileSystem::isDirectory ( const String & path)
Returns
true if file exists and is a directory

Definition at line 638 of file PosixFileSystem.cpp.

References BLOCXX_NAMESPACE::String::c_str(), and g_fileSystemMockObject.

◆ isExecutable()

bool BLOCXX_NAMESPACE::FileSystem::isExecutable ( const String & path)

Tests if a file is executable.

This method is not available on platforms that do not have support for executable file attributes

Returns
true if the file exists and is executable (and false otherwise).

Definition at line 589 of file PosixFileSystem.cpp.

References _ACCESS, BLOCXX_NAMESPACE::String::c_str(), and g_fileSystemMockObject.

◆ isLink()

bool BLOCXX_NAMESPACE::FileSystem::isLink ( const String & path)

Tests if a file is a symbolic link.

This method is not available on platforms that do not have support for symbolic links

Returns
true if file exists and is a symbolic link

Definition at line 622 of file PosixFileSystem.cpp.

References BLOCXX_NAMESPACE::String::c_str(), and g_fileSystemMockObject.

◆ makeDirectory()

bool BLOCXX_NAMESPACE::FileSystem::makeDirectory ( const String & path,
int mode = 0777 )

Create a directory.

Parameters
pathThe name of the directory to create.
modespecifies the permissions to use.
Returns
true if the operation succeeds. Otherwise false.

Definition at line 672 of file PosixFileSystem.cpp.

References _MKDIR, BLOCXX_NAMESPACE::String::c_str(), and g_fileSystemMockObject.

◆ openFile()

File BLOCXX_NAMESPACE::FileSystem::openFile ( const String & path)

Open a file for read/write and return an File object that can be used for reading and writing.

Definition at line 256 of file PosixFileSystem.cpp.

References BLOCXX_NAMESPACE::String::c_str(), and g_fileSystemMockObject.

Referenced by BLOCXX_NAMESPACE::TempFileEnumerationImplBase::readSize().

◆ openForAppendOrCreateFile()

File BLOCXX_NAMESPACE::FileSystem::openForAppendOrCreateFile ( const String & path)

Opens the file for the given name to append data or create if it does not exist.

Parameters
pathThe name of the file to create.
Returns
On success an File object that can be used for reading and writing. Otherwise a null File object.

Definition at line 318 of file PosixFileSystem.cpp.

References BLOCXX_NAMESPACE::String::c_str(), and g_fileSystemMockObject.

Referenced by BLOCXX_NAMESPACE::MultiProcessFileAppender::doProcessLogMessage(), and BLOCXX_NAMESPACE::MultiProcessFileAppender::MultiProcessFileAppender().

◆ openOrCreateFile()

File BLOCXX_NAMESPACE::FileSystem::openOrCreateFile ( const String & path)

Opens or creates the file for the given name.

Parameters
pathThe name of the file to create.
Returns
On success an File object that can be used for reading and writing. Otherwise a null File object.

Definition at line 299 of file PosixFileSystem.cpp.

References BLOCXX_NAMESPACE::String::c_str(), and g_fileSystemMockObject.

Referenced by BLOCXX_NAMESPACE::ServerSocketImpl::doListenUDS(), and BLOCXX_NAMESPACE::MultiProcessFileAppender::MultiProcessFileAppender().

◆ read()

size_t BLOCXX_NAMESPACE::FileSystem::read ( const FileHandle & hdl,
void * bfr,
size_t numberOfBytes,
Int64 offset = -1L )

Read data from file.

Parameters
hdlThe file handle to perform the read operation on.
bfrThe location where the read operation will place what is read.
numberOfBytesThe number of bytes to read.
offsetThe offset to seek to in the file before the read operation is done. -1 will use the current offset.
Returns
The number of bytes read. If EOF or an error occurs, a short count or size_t(-1) is returned.

Definition at line 786 of file PosixFileSystem.cpp.

References BLOCXX_THROW, and g_fileSystemMockObject.

◆ readSymbolicLink()

String BLOCXX_NAMESPACE::FileSystem::readSymbolicLink ( const String & path)

Read the value of a symbolic link.

Parameters
pathPath to the symbolic link
Returns
The target of the symbolic link
Exceptions
FileSystemExceptionENOTDIR, ENOENT, EACCES, ELOOP, EINVAL, EIO, EFAULT, ENOMEM

Definition at line 1037 of file PosixFileSystem.cpp.

References BLOCXX_THROW_ERRNO_MSG, BLOCXX_NAMESPACE::String::c_str(), g_fileSystemMockObject, MAXPATHLEN, and BLOCXX_NAMESPACE::FileSystem::Path::realPath().

◆ removeDirectory()

bool BLOCXX_NAMESPACE::FileSystem::removeDirectory ( const String & path)

Remove the given directory.

Parameters
pathThe name of the directory to remove
Returns
true if the operation succeeds. Otherwise false.

Definition at line 706 of file PosixFileSystem.cpp.

References _RMDIR, BLOCXX_NAMESPACE::String::c_str(), and g_fileSystemMockObject.

◆ removeFile()

bool BLOCXX_NAMESPACE::FileSystem::removeFile ( const String & path)

◆ renameFile()

bool BLOCXX_NAMESPACE::FileSystem::renameFile ( const String & oldFileName,
const String & newFileName )

Rename the given file to the new name.

Parameters
oldFileNameThe name of the file to rename
newFileNameThe new name for the oldFileName
Returns
true if the operation succeeds. Otherwise false.

Definition at line 775 of file PosixFileSystem.cpp.

References BLOCXX_NAMESPACE::String::c_str(), and g_fileSystemMockObject.

Referenced by BLOCXX_NAMESPACE::FileAppender::doProcessLogMessage(), and BLOCXX_NAMESPACE::MultiProcessFileAppender::doProcessLogMessage().

◆ rewind()

void BLOCXX_NAMESPACE::FileSystem::rewind ( const FileHandle & hdl)

Position the file pointer associated with the given file handle to the beginning of the file.

Parameters
hdlThe file handle to use in the rewind operation.

Definition at line 969 of file PosixFileSystem.cpp.

References g_fileSystemMockObject.

◆ seek()

Int64 BLOCXX_NAMESPACE::FileSystem::seek ( const FileHandle & hdl,
Int64 offset,
int whence )

Seek to a given offset within the file.

Parameters
hdlThe file handle to use in the seek operation.
offsetThe offset to seek to relative to the whence parm.
whenceCan be one of the follwing values: SEEK_SET - Seek relative to the beginning of the file. SEEK_CUR - Seek relative to the current position. SEEK_END - Seek relative to the end of the file (bwd).
Returns
The the current location in the file relative to the beginning of the file on success. Other -1.

Definition at line 878 of file PosixFileSystem.cpp.

References BLOCXX_THROW, and g_fileSystemMockObject.

◆ tell()

Int64 BLOCXX_NAMESPACE::FileSystem::tell ( const FileHandle & hdl)
Parameters
hdlThe file handle to use in the tell operation.
Returns
The current position in the file relative to the beginning of the file on success. Otherwise -1.

Definition at line 915 of file PosixFileSystem.cpp.

References g_fileSystemMockObject.

◆ write()

size_t BLOCXX_NAMESPACE::FileSystem::write ( FileHandle hdl,
const void * bfr,
size_t numberOfBytes,
Int64 offset = -1L )

Write data to a file.

Parameters
hdlThe file handle to perform the write operation on.
bfrThe locaction to get the contents to write.
numberOfBytesThe number of bytes to write.
offsetThe offset to seek to in the file before the write operation is done. -1 will use the current offset.
Returns
The number of bytes written. If an error occurs, a short count or size_t(-1) is returned.

Definition at line 832 of file PosixFileSystem.cpp.

References BLOCXX_THROW, and g_fileSystemMockObject.

Variable Documentation

◆ COMPONENT_NAME

GlobalString BLOCXX_NAMESPACE::FileSystem::COMPONENT_NAME = { "blocxx", 0, {0, PTHREAD_MUTEX_INITIALIZER} }

Definition at line 239 of file PosixFileSystem.cpp.

Referenced by createAutoDeleteTempFile().

◆ g_fileSystemMockObject