eive-obsw/bsp_q7s/fs/FilesystemHelper.cpp

39 lines
1.2 KiB
C++

#include "FilesystemHelper.h"
#include <filesystem>
#include <fstream>
#include "SdCardManager.h"
#include "eive/definitions.h"
#include "fsfw/serviceinterface.h"
FilesystemHelper::FilesystemHelper() {}
ReturnValue_t FilesystemHelper::checkPath(std::string path) {
SdCardManager* sdcMan = SdCardManager::instance();
if (sdcMan == nullptr) {
sif::warning << "FilesystemHelper::checkPath: Invalid SD card manager" << std::endl;
return returnvalue::FAILED;
}
if (path.substr(0, sizeof(config::SD_0_MOUNT_POINT)) == std::string(config::SD_0_MOUNT_POINT)) {
if (!sdcMan->isSdCardUsable(sd::SLOT_0)) {
sif::warning << "FilesystemHelper::checkPath: SD card 0 not mounted" << std::endl;
return SD_NOT_MOUNTED;
}
} else if (path.substr(0, sizeof(config::SD_1_MOUNT_POINT)) ==
std::string(config::SD_1_MOUNT_POINT)) {
if (!sdcMan->isSdCardUsable(sd::SLOT_1)) {
sif::warning << "FilesystemHelper::checkPath: SD card 1 not mounted" << std::endl;
return SD_NOT_MOUNTED;
}
}
return returnvalue::OK;
}
ReturnValue_t FilesystemHelper::fileExists(std::string file) {
if (not std::filesystem::exists(file)) {
return FILE_NOT_EXISTS;
}
return returnvalue::OK;
}