finished host FS impl
fsfw/fsfw/pipeline/pr-development This commit looks good Details

This commit is contained in:
Robin Müller 2022-08-11 09:32:18 +02:00
parent aca8b53a59
commit 20eee2c469
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
5 changed files with 73 additions and 21 deletions

View File

@ -34,18 +34,23 @@ class HasFileSystemIF {
//! [EXPORT] : P1: Can be file system specific error code
static constexpr ReturnValue_t GENERIC_FILE_ERROR = MAKE_RETURN_CODE(0);
static constexpr ReturnValue_t GENERIC_DIR_ERROR = MAKE_RETURN_CODE(1);
static constexpr ReturnValue_t GENERIC_RENAME_ERROR = MAKE_RETURN_CODE(3);
//! [EXPORT] : File system is currently busy
static constexpr ReturnValue_t IS_BUSY = MAKE_RETURN_CODE(1);
static constexpr ReturnValue_t IS_BUSY = MAKE_RETURN_CODE(4);
//! [EXPORT] : Invalid parameters like file name or repository path
static constexpr ReturnValue_t INVALID_PARAMETERS = MAKE_RETURN_CODE(2);
static constexpr ReturnValue_t INVALID_PARAMETERS = MAKE_RETURN_CODE(5);
static constexpr ReturnValue_t FILE_DOES_NOT_EXIST = MAKE_RETURN_CODE(5);
static constexpr ReturnValue_t FILE_ALREADY_EXISTS = MAKE_RETURN_CODE(6);
static constexpr ReturnValue_t FILE_LOCKED = MAKE_RETURN_CODE(7);
static constexpr ReturnValue_t FILE_DOES_NOT_EXIST = MAKE_RETURN_CODE(7);
static constexpr ReturnValue_t FILE_ALREADY_EXISTS = MAKE_RETURN_CODE(8);
static constexpr ReturnValue_t NOT_A_FILE = MAKE_RETURN_CODE(9);
static constexpr ReturnValue_t FILE_LOCKED = MAKE_RETURN_CODE(10);
static constexpr ReturnValue_t DIRECTORY_DOES_NOT_EXIST = MAKE_RETURN_CODE(10);
static constexpr ReturnValue_t DIRECTORY_ALREADY_EXISTS = MAKE_RETURN_CODE(11);
static constexpr ReturnValue_t DIRECTORY_NOT_EMPTY = MAKE_RETURN_CODE(12);
static constexpr ReturnValue_t DIRECTORY_DOES_NOT_EXIST = MAKE_RETURN_CODE(15);
static constexpr ReturnValue_t DIRECTORY_ALREADY_EXISTS = MAKE_RETURN_CODE(16);
static constexpr ReturnValue_t NOT_A_DIRECTORY = MAKE_RETURN_CODE(17);
static constexpr ReturnValue_t DIRECTORY_NOT_EMPTY = MAKE_RETURN_CODE(18);
//! [EXPORT] : P1: Sequence number missing
static constexpr ReturnValue_t SEQUENCE_PACKET_MISSING_WRITE = MAKE_RETURN_CODE(15);
@ -139,9 +144,9 @@ class HasFileSystemIF {
}
virtual ReturnValue_t renameFile(const char* oldPath, char* newPath) {
return renameFile(oldPath, newPath, nullptr);
return rename(oldPath, newPath, nullptr);
}
virtual ReturnValue_t renameFile(const char* oldPath, char* newPath, FileSystemArgsIF* args) = 0;
virtual ReturnValue_t rename(const char* oldPath, char* newPath, FileSystemArgsIF* args) = 0;
};
#endif /* FSFW_MEMORY_HASFILESYSTEMIF_H_ */

View File

@ -80,20 +80,68 @@ ReturnValue_t HostFilesystem::removeFile(const char *path_, FileSystemArgsIF *ar
}
return HasFileSystemIF::GENERIC_FILE_ERROR;
}
ReturnValue_t HostFilesystem::createDirectory(FilesystemParams params, bool createParentDirs) {
if (params.path == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
path dirPath(params.path);
if (createParentDirs) {
create_directories(dirPath, errorCode);
if (exists(dirPath)) {
return HasFileSystemIF::DIRECTORY_ALREADY_EXISTS;
}
return 0;
if (is_regular_file(dirPath)) {
return HasFileSystemIF::NOT_A_DIRECTORY;
}
if (createParentDirs) {
if (create_directories(dirPath, errorCode)) {
return HasReturnvaluesIF::RETURN_OK;
}
return HasFileSystemIF::GENERIC_DIR_ERROR;
}
if (create_directory(dirPath, errorCode)) {
return HasReturnvaluesIF::RETURN_OK;
}
return HasFileSystemIF::GENERIC_DIR_ERROR;
}
ReturnValue_t HostFilesystem::removeDirectory(FilesystemParams params, bool deleteRecurively) {
return 0;
if (params.path == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
path dirPath(params.path);
if (not exists(dirPath)) {
return HasFileSystemIF::DIRECTORY_DOES_NOT_EXIST;
}
if (is_regular_file(dirPath)) {
return HasFileSystemIF::NOT_A_DIRECTORY;
}
if (deleteRecurively) {
if (remove_all(dirPath, errorCode)) {
return HasReturnvaluesIF::RETURN_OK;
}
} else {
if (remove(dirPath, errorCode)) {
return HasReturnvaluesIF::RETURN_OK;
}
}
// Error handling
if (errorCode == std::errc::directory_not_empty) {
return HasFileSystemIF::DIRECTORY_NOT_EMPTY;
}
return HasFileSystemIF::GENERIC_DIR_ERROR;
}
ReturnValue_t HostFilesystem::renameFile(const char *oldPath, char *newPath,
FileSystemArgsIF *args) {
return 0;
ReturnValue_t HostFilesystem::rename(const char *oldPath_, char *newPath_, FileSystemArgsIF *args) {
if (oldPath_ == nullptr or newPath_ == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
path oldPath(oldPath_);
path newPath(newPath_);
errorCode.clear();
std::filesystem::rename(oldPath, newPath, errorCode);
if (errorCode) {
return HasFileSystemIF::GENERIC_RENAME_ERROR;
}
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -15,7 +15,7 @@ class HostFilesystem : public HasFileSystemIF {
ReturnValue_t removeFile(const char *path, FileSystemArgsIF *args) override;
ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) override;
ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override;
ReturnValue_t renameFile(const char *oldPath, char *newPath, FileSystemArgsIF *args) override;
ReturnValue_t rename(const char *oldPath, char *newPath, FileSystemArgsIF *args) override;
std::error_code errorCode;

View File

@ -64,8 +64,7 @@ ReturnValue_t FilesystemMock::removeDirectory(FilesystemParams params, bool dele
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t FilesystemMock::renameFile(const char *oldPath, char *newPath,
FileSystemArgsIF *args) {
ReturnValue_t FilesystemMock::rename(const char *oldPath, char *newPath, FileSystemArgsIF *args) {
renameQueue.push(RenameInfo(oldPath, newPath));
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -60,7 +60,7 @@ class FilesystemMock : public HasFileSystemIF {
ReturnValue_t removeFile(const char *path, FileSystemArgsIF *args) override;
ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) override;
ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override;
ReturnValue_t renameFile(const char *oldPath, char *newPath, FileSystemArgsIF *args) override;
ReturnValue_t rename(const char *oldPath, char *newPath, FileSystemArgsIF *args) override;
void reset();