FileSystem Class Reference

FileSystem provides some static utility methods for manipulating the OS file system. More...

#include <FileSystem.h>

List of all members.

Static Public Member Functions

static void remove (char const *filename)
static bool setFileAttributes (char const *filename, bool readOnly=1)
static bool doesFileExist (char const *filename)
static void getDiskFreeSpace (char const *path, FileSize &availableSpace)
 Determines how much free space is available in a file system.


Detailed Description

FileSystem provides some static utility methods for manipulating the OS file system.

Definition at line 33 of file FileSystem.h.


Member Function Documentation

void FileSystem::remove ( char const *  filename  )  [static]

Definition at line 51 of file FileSystem.cpp.

References doesFileExist(), and setFileAttributes().

Referenced by Database::deleteLogs(), SegmentFactory::newTempDeviceSegment(), RandomAccessFileDeviceTest::openDevice(), CacheTestBase::openDevice(), and BackupRestoreTest::testBackupCleanup().

00052 {
00053     if (doesFileExist(fileName)) {
00054         setFileAttributes(fileName,0);
00055         if (::unlink(fileName)) {
00056             std::ostringstream oss;
00057             oss << "Failed to remove file " << fileName;
00058             throw SysCallExcn(oss.str());
00059         }
00060     }
00061 }

bool FileSystem::setFileAttributes ( char const *  filename,
bool  readOnly = 1 
) [static]

Definition at line 68 of file FileSystem.cpp.

Referenced by remove().

00069 {
00070     mode_t mode = S_IRUSR;
00071     if (!readOnly) {
00072         mode |= S_IWUSR;
00073     }
00074     return ::chmod(filename,mode) ? 0 : 1;
00075 }

bool FileSystem::doesFileExist ( char const *  filename  )  [static]

Definition at line 63 of file FileSystem.cpp.

Referenced by Database::createTempSegment(), Database::init(), remove(), SegPageBackupRestoreDevice::setCompressionProgramPathname(), and RandomAccessFileDeviceTest::testDeviceCreation().

00064 {
00065     return !::access(filename,0);
00066 }

void FileSystem::getDiskFreeSpace ( char const *  path,
FileSize availableSpace 
) [static]

Determines how much free space is available in a file system.

Parameters:
path the pathname of any file within the file system
availableSpace returns the number of free bytes available in the file system

Definition at line 77 of file FileSystem.cpp.

Referenced by Database::initiateBackup(), and BackupRestoreTest::testBackupCleanup().

00078 {
00079 #ifdef __MSVC__
00080     throw FennelExcn(FennelResource::instance().unsupportedOperation("statvfs"));
00081 #else
00082     struct statvfs buf;
00083     int rc = statvfs(path, &buf);
00084     if (rc == -1) {
00085         throw SysCallExcn("statvfs call failed");
00086     }
00087     availableSpace = buf.f_bsize * buf.f_bavail;
00088 #endif
00089 }


The documentation for this class was generated from the following files:
Generated on Mon Jun 22 04:00:32 2009 for Fennel by  doxygen 1.5.1