Maat C++ Documentation
Public Types | Public Member Functions | Friends | List of all members
maat::env::FileSystem Class Reference

Public Types

using snapshot_t = int
 

Public Member Functions

 FileSystem (OS system)
 Create a new filesystem for OS 'system'.
 
physical_file_t get_file (const std::string &path, bool follow_symlink=true)
 Get a file in the file system. More...
 
physical_file_t get_file_by_handle (filehandle_t handle)
 Convenience function to get a physical file by handle. More...
 
bool create_file (const std::string &path, bool create_path=false)
 Create a file specified by its absolute path. Returns 'true' on success and 'false' on failure. More...
 
bool delete_file (const std::string &path, bool weak=true)
 Delete a file Returns 'true' on success and 'false' on failure. More...
 
bool file_exists (const std::string &path)
 Check if a file exists in the filesystem.
 
bool create_symlink (const std::string &link, const std::string &pointed_file, bool create_path=false)
 Create a symbolic link. More...
 
filehandle_t new_fa (const std::string &path)
 Create a new file accessor. More...
 
FileAccessorget_fa_by_handle (filehandle_t handle)
 Get a file accessor by handle.
 
void delete_fa (filehandle_t handle, bool weak=true)
 Delete a file accessor. More...
 
bool create_dir (const std::string &path)
 Create a directory in the filesystem. Returns 'true' on success, 'false' on failure.
 
directory_t get_dir (const std::string &path)
 Get directory by absolute path. This function doesn't check wheter the dir was deleted or not!
 
bool delete_dir (const std::string &path, bool weak=true)
 Delete a directory. More...
 
std::string path_from_fspath (const fspath_t &path)
 
fspath_t fspath_from_path (const std::string &path)
 
fspath_t fspath_from_path_relative_to (std::string rel_path, fspath_t path_base)
 
std::string path_from_relative_path (std::string rel_path, std::string path_base)
 
std::string pointed_path_from_symlink (std::string symlink_file)
 
bool is_relative_path (const std::string &path)
 
node_status_t get_node_status (const std::string &path)
 
std::string get_stdin_for_pid (int pid)
 Return the stdin file for process with PID 'pid'.
 
std::string get_stdout_for_pid (int pid)
 Return the stdout file for process with PID 'pid'.
 
std::string get_stderr_for_pid (int pid)
 Return the stderr file for process with PID 'pid'.
 
snapshot_t take_snapshot ()
 Take a snapshot of the filesystem.
 
void restore_snapshot (snapshot_t snapshot, bool remove=false)
 Restore a snapshot of the filesystem.
 
void restore_last_snapshot (bool remove=false)
 Restore latests snapshot.
 

Friends

class EnvEmulator
 
class LinuxEmulator
 
std::ostream & operator<< (std::ostream &os, const FileSystem &fs)
 

Member Function Documentation

◆ create_file()

bool maat::env::FileSystem::create_file ( const std::string &  path,
bool  create_path = false 
)

Create a file specified by its absolute path. Returns 'true' on success and 'false' on failure.

Parameters
pathAbsolute path of the file
create_pathIf set to 'true', any missing directories in 'link' will be automatically created

◆ create_symlink()

bool maat::env::FileSystem::create_symlink ( const std::string &  link,
const std::string &  pointed_file,
bool  create_path = false 
)

Create a symbolic link.

Parameters
linkThe absolute path of the symbolic link
pointed_fileThe file pointed to by the symbolic link
create_pathIf set to 'true', any missing directories in 'link' will be automatically created

◆ delete_dir()

bool maat::env::FileSystem::delete_dir ( const std::string &  path,
bool  weak = true 
)

Delete a directory.

Parameters
pathAbsolute path of the directory
weakIf set to 'true', the directory is virtually deleted from the emulated filesystem, but its contents are preserved internally and will be restored if a snapshot rewinds back to before the deletion. If set to 'false' the file object is completely deleted internally

◆ delete_fa()

void maat::env::FileSystem::delete_fa ( filehandle_t  handle,
bool  weak = true 
)

Delete a file accessor.

Parameters
handleUnique handle of the file accessor to delete
weakIf set to 'true', the file accessor is virtually deleted , but its contents are preserved internally and will be restored if a snapshot rewinds back to before the deletion. If set to 'false' the object is completely deleted internally

◆ delete_file()

bool maat::env::FileSystem::delete_file ( const std::string &  path,
bool  weak = true 
)

Delete a file Returns 'true' on success and 'false' on failure.

Parameters
pathAbsolute path of the file
weakIf set to 'true', the file is virtually deleted from the emulated filesystem, but its contents are preserved internally and will be restored if a snapshot rewinds back to before the deletion. If set to 'false' the file object is completely deleted internally

◆ get_file()

physical_file_t maat::env::FileSystem::get_file ( const std::string &  path,
bool  follow_symlink = true 
)

Get a file in the file system.

Parameters
pathAbsolute path of the file
follow_symlinkIf set to 'true', resolve potential symbolic links to get the actual file

◆ get_file_by_handle()

physical_file_t maat::env::FileSystem::get_file_by_handle ( filehandle_t  handle)

Convenience function to get a physical file by handle.

Parameters
handleThe handle of the file

◆ new_fa()

filehandle_t maat::env::FileSystem::new_fa ( const std::string &  path)

Create a new file accessor.

Parameters
pathAbsolute path of the file to access


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