wrench::LogicalFileSystem

class LogicalFileSystem

A class that implements a weak file system abstraction.

Public Functions

explicit LogicalFileSystem(const std::string &hostname, StorageService *storage_service, std::string mount_point = DEV_NULL)

Constructor.

Parameters
  • hostname – the host on which the file system is located

  • storage_service – the storage service this file system is for

  • mount_point – the mount point, defaults to /dev/null

void createDirectory(const std::string &absolute_path)

Create a new directory.

Parameters

absolute_path – the directory’s absolute path

Throws

std::invalid_argument

bool doesDirectoryExist(const std::string &absolute_path)

Checks whether a directory exists.

Parameters

absolute_path – the directory’s absolute path

Returns

true if the directory exists

double getFreeSpace()

Get the file system’s free space.

Returns

the free space in bytes

double getTotalCapacity()

Get the total capacity.

Returns

the total capacity

bool hasEnoughFreeSpace(double bytes)

Checks whether there is enough space to store some number of bytes.

Parameters

bytes – a number of bytes

Returns

true if the number of bytes can fit

void init()

Initializes the Logical File System (must be called before any other operation on this file system)

bool isDirectoryEmpty(const std::string &absolute_path)

Checks whether a directory is empty.

Parameters

absolute_path – the directory’s absolute path

Throws

std::invalid_argument

Returns

true if the directory is empty

bool isFileInDirectory(std::shared_ptr<DataFile> file, const std::string &absolute_path)

Checks whether a file is in a directory.

Parameters
  • file – the file

  • absolute_path – the directory’s absolute path

Throws

std::invalid_argument

Returns

true if the file is present

std::set<std::shared_ptr<DataFile>> listFilesInDirectory(const std::string &absolute_path)

Get the files in a directory as a set.

Parameters

absolute_path – the directory’s absolute path

Throws

std::invalid_argument

Returns

a set of files

void removeAllFilesInDirectory(const std::string &absolute_path)

Remove all files in a directory.

Parameters

absolute_path – the directory’s absolute path

Throws

std::invalid_argument

void removeEmptyDirectory(const std::string &absolute_path)

Remove an empty directory.

Parameters

absolute_path – the directory’s absolute path

Throws

std::invalid_argument

void removeFileFromDirectory(std::shared_ptr<DataFile> file, const std::string &absolute_path)

Remove a file in a directory.

Parameters
  • file – the file to remove

  • absolute_path – the directory’s absolute path

Throws

std::invalid_argument

void reserveSpace(const std::shared_ptr<DataFile> &file, std::string absolute_path)

Reserve space for a file that will be stored.

Parameters
  • file – the file

  • absolute_path – the path where it will be written

Throws

std::invalid_argument

void storeFileInDirectory(std::shared_ptr<DataFile> file, const std::string &absolute_path)

Store file in directory.

Parameters
  • file – the file to store

  • absolute_path – the directory’s absolute path (at the mount point)

Throws

std::invalid_argument

void unreserveSpace(const std::shared_ptr<DataFile> &file, std::string absolute_path)

Unreserve space that was saved for a file (likely a failed transfer)

Parameters
  • file – the file

  • absolute_path – the path where it would have been written

Throws

std::invalid_argument

Public Static Attributes

static const std::string DEV_NULL = "/dev/null"

A constant that signifies /dev/null, when the actual location/path/mountpoint/etc. is unknown.