more tests added

This commit is contained in:
2021-07-19 14:34:03 +02:00
committed by Robin Mueller
parent d4e5919a21
commit 42578ba2ac
4 changed files with 102 additions and 20 deletions

View File

@ -143,9 +143,15 @@ ReturnValue_t FileSystemHandler::appendToFile(const char *repositoryPath, const
ReturnValue_t FileSystemHandler::createFile(const char *repositoryPath, const char *filename,
const uint8_t *data, size_t size, void *args) {
std::string fullPath;
bool useMountPrefix = true;
parseCfg(reinterpret_cast<FsCommandCfg*>(args), useMountPrefix);
if(useMountPrefix) {
fullPath += currentMountPrefix;
}
// A double slash between repo and filename should not be an issue, so add it in any case
std::string fullPath = currentMountPrefix + std::string(repositoryPath) + "/" +
std::string(filename);
fullPath += std::string(repositoryPath) + "/" + std::string(filename);
if(std::filesystem::exists(fullPath)) {
return FILE_ALREADY_EXISTS;
}
@ -159,9 +165,15 @@ ReturnValue_t FileSystemHandler::createFile(const char *repositoryPath, const ch
ReturnValue_t FileSystemHandler::deleteFile(const char *repositoryPath, const char *filename,
void *args) {
std::string fullPath;
bool useMountPrefix = true;
parseCfg(reinterpret_cast<FsCommandCfg*>(args), useMountPrefix);
if(useMountPrefix) {
fullPath += currentMountPrefix;
}
// A double slash between repo and filename should not be an issue, so add it in any case
std::string fullPath = currentMountPrefix + std::string(repositoryPath) + "/" +
std::string(filename);
fullPath += std::string(repositoryPath) + "/" + std::string(filename);
if(not std::filesystem::exists(fullPath)) {
return FILE_DOES_NOT_EXIST;
}
@ -174,7 +186,14 @@ ReturnValue_t FileSystemHandler::deleteFile(const char *repositoryPath, const ch
}
ReturnValue_t FileSystemHandler::createDirectory(const char *repositoryPath, void *args) {
std::string fullPath = currentMountPrefix + std::string(repositoryPath);
std::string fullPath;
bool useMountPrefix = true;
parseCfg(reinterpret_cast<FsCommandCfg*>(args), useMountPrefix);
if(useMountPrefix) {
fullPath += currentMountPrefix;
}
fullPath += std::string(repositoryPath);
if(std::filesystem::exists(fullPath)) {
return DIRECTORY_ALREADY_EXISTS;
}
@ -187,7 +206,14 @@ ReturnValue_t FileSystemHandler::createDirectory(const char *repositoryPath, voi
ReturnValue_t FileSystemHandler::removeDirectory(const char *repositoryPath,
bool deleteRecurively, void *args) {
std::string fullPath = currentMountPrefix + std::string(repositoryPath);
std::string fullPath;
bool useMountPrefix = true;
parseCfg(reinterpret_cast<FsCommandCfg*>(args), useMountPrefix);
if(useMountPrefix) {
fullPath += currentMountPrefix;
}
fullPath += std::string(repositoryPath);
if(not std::filesystem::exists(fullPath)) {
return DIRECTORY_DOES_NOT_EXIST;
}
@ -217,3 +243,9 @@ ReturnValue_t FileSystemHandler::removeDirectory(const char *repositoryPath,
return HasReturnvaluesIF::RETURN_OK;
}
void FileSystemHandler::parseCfg(FsCommandCfg *cfg, bool& useMountPrefix) {
if(cfg != nullptr) {
useMountPrefix = cfg->useMountPrefix;
}
}