avoid exceptions
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit

This commit is contained in:
2023-03-08 14:50:25 +01:00
parent 0bdc6d3d7c
commit ccf03b131b
19 changed files with 83 additions and 45 deletions

View File

@ -605,7 +605,8 @@ ReturnValue_t CoreController::sdCardSetup(sd::SdCard sdCard, sd::SdState targetS
sif::info << "Unmounting SD card " << sdChar << std::endl;
return sdcMan->unmountSdCard(sdCard);
} else {
if (std::filesystem::exists(mountString)) {
std::error_code e;
if (std::filesystem::exists(mountString, e)) {
sif::info << "SD card " << sdChar << " already on and mounted at " << mountString
<< std::endl;
return SdCardManager::ALREADY_MOUNTED;
@ -702,7 +703,8 @@ ReturnValue_t CoreController::initVersionFile() {
std::string versionFilePath = currMntPrefix + VERSION_FILE;
std::fstream versionFile;
if (not std::filesystem::exists(versionFilePath)) {
std::error_code e;
if (not std::filesystem::exists(versionFilePath, e)) {
sif::info << "Writing version file " << versionFilePath << ".." << std::endl;
versionFile.open(versionFilePath, std::ios_base::out);
versionFile << fullObswVersionString << std::endl;
@ -814,7 +816,8 @@ ReturnValue_t CoreController::actionListDirectoryIntoFile(ActionId_t actionId,
}
ReturnValue_t CoreController::initBootCopyFile() {
if (not std::filesystem::exists(CURR_COPY_FILE)) {
std::error_code e;
if (not std::filesystem::exists(CURR_COPY_FILE, e)) {
// This file is created by the systemd service eive-early-config so this should
// not happen normally
std::string cmd = "xsc_boot_copy > " + std::string(CURR_COPY_FILE);
@ -1118,7 +1121,8 @@ ReturnValue_t CoreController::updateProtInfo(bool regenerateChipStateFile) {
return result;
}
}
if (not filesystem::exists(CHIP_STATE_FILE)) {
std::error_code e;
if (not filesystem::exists(CHIP_STATE_FILE, e)) {
return returnvalue::FAILED;
}
ifstream chipStateFile(CHIP_STATE_FILE);
@ -1197,8 +1201,13 @@ void CoreController::performMountedSdCardOperations() {
if (not performOneShotSdCardOpsSwitch) {
std::ostringstream path;
path << mntPoint << "/" << CONF_FOLDER;
if (not std::filesystem::exists(path.str())) {
std::filesystem::create_directory(path.str());
std::error_code e;
if (not std::filesystem::exists(path.str()), e) {
bool created = std::filesystem::create_directory(path.str(), e);
if (not created) {
sif::error << "Could not create CONF folder at " << path << ": " << e << std::endl;
return;
}
}
initVersionFile();
ReturnValue_t result = initBootCopyFile();
@ -1283,7 +1292,8 @@ ReturnValue_t CoreController::performSdCardCheck() {
void CoreController::performRebootFileHandling(bool recreateFile) {
using namespace std;
std::string path = currMntPrefix + REBOOT_FILE;
if (not std::filesystem::exists(path) or recreateFile) {
std::error_code e;
if (not std::filesystem::exists(path, e) or recreateFile) {
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "CoreController::performRebootFileHandling: Recreating reboot file" << std::endl;
#endif
@ -1750,7 +1760,8 @@ ReturnValue_t CoreController::initClockFromTimeFile() {
using namespace GpsHyperion;
using namespace std;
std::string fileName = currMntPrefix + BACKUP_TIME_FILE;
if (sdcMan->isSdCardUsable(std::nullopt) and std::filesystem::exists(fileName) and
std::error_code e;
if (sdcMan->isSdCardUsable(std::nullopt) and std::filesystem::exists(fileName, e) and
((gpsFix == FixMode::UNKNOWN or gpsFix == FixMode::NOT_SEEN) or
not utility::timeSanityCheck())) {
ifstream timeFile(fileName);
@ -1875,7 +1886,8 @@ ReturnValue_t CoreController::executeSwUpdate(SwUpdateSources sourceDir, const u
prefixPath = path("/tmp");
}
path archivePath = prefixPath / path(config::OBSW_UPDATE_ARCHIVE_FILE_NAME);
if (not exists(archivePath)) {
std::error_code e;
if (not exists(archivePath, e)) {
return HasFileSystemIF::FILE_DOES_NOT_EXIST;
}
ostringstream cmd("tar -xJf", ios::app);
@ -1885,12 +1897,13 @@ ReturnValue_t CoreController::executeSwUpdate(SwUpdateSources sourceDir, const u
utility::handleSystemError(result, "CoreController::executeAction: SW Update Decompression");
}
path strippedImagePath = prefixPath / path(config::STRIPPED_OBSW_BINARY_FILE_NAME);
if (!exists(strippedImagePath)) {
std::error_code e;
if (!exists(strippedImagePath, e)) {
// TODO: Custom returnvalue?
return returnvalue::FAILED;
}
path obswVersionFilePath = prefixPath / path(config::OBSW_VERSION_FILE_NAME);
if (!exists(obswVersionFilePath)) {
if (!exists(obswVersionFilePath, e)) {
// TODO: Custom returnvalue?
return returnvalue::FAILED;
}

View File

@ -45,7 +45,8 @@ void WatchdogHandler::periodicOperation() {
ReturnValue_t WatchdogHandler::initialize(bool enableWatchdogFunction) {
using namespace std::filesystem;
this->enableWatchFunction = enableWatchdogFunction;
if (not std::filesystem::exists(watchdog::FIFO_NAME)) {
std::error_code e;
if (not std::filesystem::exists(watchdog::FIFO_NAME, e)) {
// Still return returnvalue::OK for now
sif::info << "Watchdog FIFO " << watchdog::FIFO_NAME << " does not exist, can't initiate"
<< " watchdog" << std::endl;

View File

@ -198,7 +198,8 @@ ReturnValue_t SdCardManager::setSdCardState(sd::SdCard sdCard, bool on) {
ReturnValue_t SdCardManager::getSdCardsStatus(SdStatePair& active) {
using namespace std;
MutexGuard mg(sdLock, LOCK_TYPE, SD_LOCK_TIMEOUT, LOCK_CTX);
if (not filesystem::exists(SD_STATE_FILE)) {
std::error_code e;
if (not filesystem::exists(SD_STATE_FILE, e)) {
return STATUS_FILE_NEXISTS;
}
@ -239,7 +240,8 @@ ReturnValue_t SdCardManager::mountSdCard(sd::SdCard sdCard) {
mountDev = SD_1_DEV_NAME;
mountPoint = config::SD_1_MOUNT_POINT;
}
if (not filesystem::exists(mountDev)) {
std::error_code e;
if (not filesystem::exists(mountDev, e)) {
sif::warning << "SdCardManager::mountSdCard: Device file does not exists. Make sure to"
" turn on the SD card"
<< std::endl;
@ -274,7 +276,8 @@ ReturnValue_t SdCardManager::unmountSdCard(sd::SdCard sdCard) {
} else if (sdCard == sd::SdCard::SLOT_1) {
mountPoint = config::SD_1_MOUNT_POINT;
}
if (not filesystem::exists(mountPoint)) {
std::error_code e;
if (not filesystem::exists(mountPoint, e)) {
sif::error << "SdCardManager::unmountSdCard: Default mount point " << mountPoint
<< "does not exist" << std::endl;
return UNMOUNT_ERROR;

View File

@ -1,7 +1,7 @@
#ifndef BSP_Q7S_MEMORY_LOCALPARAMETERHANDLER_H_
#define BSP_Q7S_MEMORY_LOCALPARAMETERHANDLER_H_
#include <mission/memory/NVMParameterBase.h>
#include <mission/memory/NvmParameterBase.h>
#include <mission/memory/SdCardMountedIF.h>
#include <string>

View File

@ -37,9 +37,10 @@ int obsw::obsw(int argc, char* argv[]) {
std::cout << "-- " << __DATE__ << " " << __TIME__ << " --" << std::endl;
#if Q7S_CHECK_FOR_ALREADY_RUNNING_IMG == 1
std::error_code e;
// Check special file here. This file is created or deleted by the eive-watchdog application
// or systemd service!
if (std::filesystem::exists(watchdog::RUNNING_FILE_NAME)) {
if (std::filesystem::exists(watchdog::RUNNING_FILE_NAME, e)) {
sif::warning << "File " << watchdog::RUNNING_FILE_NAME
<< " exists so the software might "
"already be running. Check if obsw systemd service has been stopped."
@ -84,8 +85,9 @@ void obsw::bootDelayHandling() {
homedir = getpwuid(getuid())->pw_dir;
}
std::filesystem::path bootDelayFile = std::filesystem::path(homedir) / "boot_delay_secs.txt";
std::error_code e;
// Init delay handling.
if (std::filesystem::exists(bootDelayFile)) {
if (std::filesystem::exists(bootDelayFile, e)) {
std::ifstream ifile(bootDelayFile);
std::string lineStr;
unsigned int bootDelaySecs = 0;