Merge pull request 'exceptionless host filesystem' (#132) from avoid_exceptions into develop

Reviewed-on: #132
This commit is contained in:
Robin Müller 2023-03-08 14:55:18 +01:00
commit 23d9b44b3e

View File

@ -15,7 +15,8 @@ ReturnValue_t HostFilesystem::writeToFile(FileOpParams params, const uint8_t *da
return returnvalue::FAILED; return returnvalue::FAILED;
} }
path path(params.path()); path path(params.path());
if (not exists(path)) { std::error_code e;
if (not exists(path, e)) {
return HasFileSystemIF::FILE_DOES_NOT_EXIST; return HasFileSystemIF::FILE_DOES_NOT_EXIST;
} }
// This is equivalent to "r+" mode, which is what we need here. Only using ::out would truncate // 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; return returnvalue::FAILED;
} }
path path(params.path()); path path(params.path());
if (not exists(path)) { std::error_code e;
if (not exists(path, e)) {
return HasFileSystemIF::FILE_DOES_NOT_EXIST; return HasFileSystemIF::FILE_DOES_NOT_EXIST;
} }
ifstream file(path); ifstream file(path);
@ -59,7 +61,8 @@ ReturnValue_t HostFilesystem::createFile(FilesystemParams params, const uint8_t
return returnvalue::FAILED; return returnvalue::FAILED;
} }
path path(params.path); path path(params.path);
if (exists(path)) { std::error_code e;
if (exists(path, e)) {
return HasFileSystemIF::FILE_ALREADY_EXISTS; return HasFileSystemIF::FILE_ALREADY_EXISTS;
} }
ofstream file(path); ofstream file(path);
@ -74,7 +77,8 @@ ReturnValue_t HostFilesystem::removeFile(const char *path_, FileSystemArgsIF *ar
return returnvalue::FAILED; return returnvalue::FAILED;
} }
path path(path_); path path(path_);
if (not exists(path)) { std::error_code e;
if (not exists(path, e)) {
return HasFileSystemIF::FILE_DOES_NOT_EXIST; return HasFileSystemIF::FILE_DOES_NOT_EXIST;
} }
if (remove(path, errorCode)) { if (remove(path, errorCode)) {
@ -89,7 +93,8 @@ ReturnValue_t HostFilesystem::createDirectory(FilesystemParams params, bool crea
} }
path dirPath(params.path); path dirPath(params.path);
if (exists(dirPath)) { std::error_code e;
if (exists(dirPath, e)) {
return HasFileSystemIF::DIRECTORY_ALREADY_EXISTS; return HasFileSystemIF::DIRECTORY_ALREADY_EXISTS;
} }
@ -110,7 +115,8 @@ ReturnValue_t HostFilesystem::removeDirectory(FilesystemParams params, bool dele
return returnvalue::FAILED; return returnvalue::FAILED;
} }
path dirPath(params.path); path dirPath(params.path);
if (not exists(dirPath)) { std::error_code e;
if (not exists(dirPath, e)) {
return HasFileSystemIF::DIRECTORY_DOES_NOT_EXIST; return HasFileSystemIF::DIRECTORY_DOES_NOT_EXIST;
} }
if (is_regular_file(dirPath)) { if (is_regular_file(dirPath)) {
@ -149,12 +155,14 @@ ReturnValue_t HostFilesystem::rename(const char *oldPath_, const char *newPath_,
bool HostFilesystem::fileExists(FilesystemParams params) { bool HostFilesystem::fileExists(FilesystemParams params) {
path path(params.path); path path(params.path);
return filesystem::exists(path); std::error_code e;
return filesystem::exists(path, e);
} }
ReturnValue_t HostFilesystem::truncateFile(FilesystemParams params) { ReturnValue_t HostFilesystem::truncateFile(FilesystemParams params) {
path path(params.path); path path(params.path);
if (not filesystem::exists(path)) { std::error_code e;
if (not filesystem::exists(path, e)) {
return FILE_DOES_NOT_EXIST; return FILE_DOES_NOT_EXIST;
} }
ofstream of(path); ofstream of(path);