avoid exceptions
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user