finished host FS impl

This commit is contained in:
2022-08-11 09:32:18 +02:00
parent aca8b53a59
commit 20eee2c469
5 changed files with 73 additions and 21 deletions

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;
}