mirror of
https://github.com/nasa/fprime.git
synced 2025-12-10 00:44:37 -06:00
* Add FileSystem Interface * Add OS::FileSystem interface and implementations * static interface + global Os::init() * Add test harness * Implement Os::Directory interfaces and use it in FileSystem::readDirectory * Add Stub tests for Directory and FileSystem * wip: modify the interface from Michael feedback * wip: move functions around and rework interface a little more * Add Directory rule-based tests * Refactored Directory for open-create + WIP: FileSystem tests * Update state tracking mechanism in FileSystem test implementation + add RandomizedTesting * Replace bounded while-loop with for-loop * Code cleanup * fix typo * Rename FileTracker and code reorganization / clarification * Code style and add CWD rule * Clean up tester code * More cleanup * Add Posix tests to Os_ut_exe * Fix DpCatalog readDirectory usage * Appease CI checks * Spelling and CI warnings * Spelling + removing FppConstants include * Add review changes and todos * Add Directory::read(Fw::StringBase&) overload * Refactor copyFileData to iterate over copied size * Remove FppConstants.hpp include * Rework moveFile into rename/copy-remove * Add majestic comments * Add option to error if dir exist in Fs::createDirectory * spelling * include <algorithm> for std::find in tests * Fix leftover ::CREATE modes in comments and stub tests * Fix CmdSequencer test case * Fix memory leak in testing by conditioning the Open rule * Fix FileManager tests * Add Directory and FileSystem FPP type definitions; update CMakeLists and clean up comments * spelling * Reoder header guards * Implement changes from peer-review * read into StringBase with const_cast * Fix resetSer() call * Fix spelling * fix spelling again i guess * Fix DpCatalog unchecked return value
88 lines
3.2 KiB
C++
88 lines
3.2 KiB
C++
// ======================================================================
|
|
// \title Os/Posix/Directory.hpp
|
|
// \brief Posix definitions for Os::Directory
|
|
// ======================================================================
|
|
#ifndef OS_POSIX_DIRECTORY_HPP
|
|
#define OS_POSIX_DIRECTORY_HPP
|
|
#include <dirent.h>
|
|
#include <Os/Directory.hpp>
|
|
|
|
namespace Os {
|
|
namespace Posix {
|
|
namespace Directory {
|
|
|
|
struct PosixDirectoryHandle : public DirectoryHandle {
|
|
DIR* m_dir_descriptor = nullptr;
|
|
};
|
|
|
|
//! \brief Posix implementation of Os::Directory
|
|
//!
|
|
//! Posix implementation of `DirectoryInterface` for use as a delegate class handling error-only file operations.
|
|
class PosixDirectory : public DirectoryInterface {
|
|
public:
|
|
//! \brief constructor
|
|
PosixDirectory();
|
|
|
|
//! \brief destructor
|
|
~PosixDirectory() = default;
|
|
|
|
//! \brief return the underlying mutex handle (implementation specific)
|
|
//! \return internal mutex handle representation
|
|
DirectoryHandle* getHandle() override;
|
|
|
|
// ------------------------------------------------------------
|
|
// Implementation-specific Directory member functions
|
|
// ------------------------------------------------------------
|
|
|
|
//! \brief Open or create a directory
|
|
//!
|
|
//! Using the path provided, this function will open or create a directory.
|
|
//! Use OpenMode::READ to open an existing directory and error if the directory is not found
|
|
//! Use OpenMode::CREATE_IF_MISSING to open a directory, creating the directory if it doesn't exist
|
|
//! Use OpenMode::CREATE_EXCLUSIVE to open a directory, creating the directory and erroring if it already exists
|
|
//!
|
|
//! It is invalid to pass `nullptr` as the path.
|
|
//! It is invalid to supply `mode` as a non-enumerated value.
|
|
//!
|
|
//! \param path: path of directory to open
|
|
//! \param mode: enum (READ, CREATE_IF_MISSING, CREATE_EXCLUSIVE). See notes above for more information
|
|
//! \return status of the operation
|
|
Status open(const char* path, OpenMode mode) override;
|
|
|
|
//! \brief Check if Directory is open or not
|
|
//! \return true if Directory is open, false otherwise
|
|
bool isOpen();
|
|
|
|
//! \brief Rewind directory stream
|
|
//!
|
|
//! Each read operation moves the seek position forward. This function resets the seek position to the beginning.
|
|
//!
|
|
//! \return status of the operation
|
|
Status rewind() override;
|
|
|
|
//! \brief Get next filename from directory stream
|
|
//!
|
|
//! Writes at most buffSize characters of the file name to fileNameBuffer.
|
|
//! This function skips the current directory (.) and parent directory (..) entries.
|
|
//! Returns NO_MORE_FILES if there are no more files to read from the buffer.
|
|
//!
|
|
//! It is invalid to pass `nullptr` as fileNameBuffer.
|
|
//!
|
|
//! \param fileNameBuffer: buffer to store filename
|
|
//! \param buffSize: size of fileNameBuffer
|
|
//! \return status of the operation
|
|
Status read(char* fileNameBuffer, FwSizeType buffSize) override;
|
|
|
|
//! \brief Close directory
|
|
void close() override;
|
|
|
|
private:
|
|
//! Handle for PosixDirectory
|
|
PosixDirectoryHandle m_handle;
|
|
};
|
|
|
|
} // namespace Directory
|
|
} // namespace Posix
|
|
} // namespace Os
|
|
#endif // OS_POSIX_DIRECTORY_HPP
|