From 26e4445189b676eaee11840e5a9d0ede25cf3896 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 8 Mar 2023 14:47:03 +0100 Subject: [PATCH] exceptionless host filesystem --- src/fsfw_hal/host/HostFilesystem.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/fsfw_hal/host/HostFilesystem.cpp b/src/fsfw_hal/host/HostFilesystem.cpp index d430d0f0..315ba422 100644 --- a/src/fsfw_hal/host/HostFilesystem.cpp +++ b/src/fsfw_hal/host/HostFilesystem.cpp @@ -15,7 +15,8 @@ ReturnValue_t HostFilesystem::writeToFile(FileOpParams params, const uint8_t *da return returnvalue::FAILED; } path path(params.path()); - if (not exists(path)) { + std::error_code e; + if (not exists(path, e)) { return HasFileSystemIF::FILE_DOES_NOT_EXIST; } // This is equivalent to "r+" mode, which is what we need here. Only using ::out would truncate @@ -35,7 +36,8 @@ ReturnValue_t HostFilesystem::readFromFile(FileOpParams params, uint8_t **buffer return returnvalue::FAILED; } path path(params.path()); - if (not exists(path)) { + std::error_code e; + if (not exists(path, e)) { return HasFileSystemIF::FILE_DOES_NOT_EXIST; } ifstream file(path); @@ -59,7 +61,8 @@ ReturnValue_t HostFilesystem::createFile(FilesystemParams params, const uint8_t return returnvalue::FAILED; } path path(params.path); - if (exists(path)) { + std::error_code e; + if (exists(path, e)) { return HasFileSystemIF::FILE_ALREADY_EXISTS; } ofstream file(path); @@ -74,7 +77,8 @@ ReturnValue_t HostFilesystem::removeFile(const char *path_, FileSystemArgsIF *ar return returnvalue::FAILED; } path path(path_); - if (not exists(path)) { + std::error_code e; + if (not exists(path, e)) { return HasFileSystemIF::FILE_DOES_NOT_EXIST; } if (remove(path, errorCode)) { @@ -89,7 +93,8 @@ ReturnValue_t HostFilesystem::createDirectory(FilesystemParams params, bool crea } path dirPath(params.path); - if (exists(dirPath)) { + std::error_code e; + if (exists(dirPath, e)) { return HasFileSystemIF::DIRECTORY_ALREADY_EXISTS; } @@ -110,7 +115,8 @@ ReturnValue_t HostFilesystem::removeDirectory(FilesystemParams params, bool dele return returnvalue::FAILED; } path dirPath(params.path); - if (not exists(dirPath)) { + std::error_code e; + if (not exists(dirPath, e)) { return HasFileSystemIF::DIRECTORY_DOES_NOT_EXIST; } if (is_regular_file(dirPath)) { @@ -149,12 +155,14 @@ ReturnValue_t HostFilesystem::rename(const char *oldPath_, const char *newPath_, bool HostFilesystem::fileExists(FilesystemParams params) { path path(params.path); - return filesystem::exists(path); + std::error_code e; + return filesystem::exists(path, e); } ReturnValue_t HostFilesystem::truncateFile(FilesystemParams params) { path path(params.path); - if (not filesystem::exists(path)) { + std::error_code e; + if (not filesystem::exists(path, e)) { return FILE_DOES_NOT_EXIST; } ofstream of(path);