FS helpers #604

Merged
muellerr merged 9 commits from core_ctrl_fs_helpers into develop 2023-04-16 02:57:16 +02:00
3 changed files with 19 additions and 11 deletions
Showing only changes of commit f4fedd20c9 - Show all commits

View File

@ -1039,10 +1039,9 @@ ReturnValue_t CoreController::actionListDirectoryDumpDirectly(ActionId_t actionI
} }
} }
std::array<uint8_t, 1024> dirListingBuf{}; std::array<uint8_t, 1024> dirListingBuf{};
// First four bytes reserved for segment index. dirListingBuf[8] = parser.compressionOptionSet();
std::memcpy(dirListingBuf.data() + sizeof(uint32_t), repoName, repoNameLen); // First four bytes reserved for segment index. One byte for compression option information
// Null termination for ground parser. std::strcpy(reinterpret_cast<char *>(dirListingBuf.data() + 2 * sizeof(uint32_t) + 1), repoName);
dirListingBuf[sizeof(uint32_t) + repoNameLen] = '\0';
std::ifstream ifile(LIST_DIR_DUMP_WORK_FILE, std::ios::binary); std::ifstream ifile(LIST_DIR_DUMP_WORK_FILE, std::ios::binary);
if (ifile.bad()) { if (ifile.bad()) {
return returnvalue::FAILED; return returnvalue::FAILED;
@ -1053,17 +1052,26 @@ ReturnValue_t CoreController::actionListDirectoryDumpDirectly(ActionId_t actionI
size_t dumpedBytes = 0; size_t dumpedBytes = 0;
size_t nextDumpLen = 0; size_t nextDumpLen = 0;
size_t dummy = 0; size_t dummy = 0;
size_t maxDumpLen = dirListingBuf.size() - repoNameLen - sizeof(uint32_t); size_t maxDumpLen = dirListingBuf.size() - 2 * sizeof(uint32_t) - 1 - repoNameLen - 1;
size_t listingDataOffset = 2 * sizeof(uint32_t) + 1 + repoNameLen + 1;
uint32_t chunks = totalFileSize / maxDumpLen;
if (totalFileSize % maxDumpLen != 0) {
chunks++;
}
SerializeAdapter::serialize(&chunks, dirListingBuf.data() + sizeof(uint32_t), &dummy,
dirListingBuf.size() - sizeof(uint32_t),
SerializeIF::Endianness::NETWORK);
while (dumpedBytes < totalFileSize) { while (dumpedBytes < totalFileSize) {
ifile.seekg(dumpedBytes, std::ios::beg);
nextDumpLen = maxDumpLen; nextDumpLen = maxDumpLen;
if (totalFileSize - dumpedBytes < maxDumpLen) { if (totalFileSize - dumpedBytes < maxDumpLen) {
nextDumpLen = totalFileSize - dumpedBytes; nextDumpLen = totalFileSize - dumpedBytes;
} }
SerializeAdapter::serialize(&segmentIdx, dirListingBuf.data(), &dummy, dirListingBuf.size(), SerializeAdapter::serialize(&segmentIdx, dirListingBuf.data(), &dummy, dirListingBuf.size(),
SerializeIF::Endianness::NETWORK); SerializeIF::Endianness::NETWORK);
ifile.read(reinterpret_cast<char *>(dirListingBuf.data() + sizeof(uint32_t) + repoNameLen + 1), ifile.read(reinterpret_cast<char *>(dirListingBuf.data() + listingDataOffset), nextDumpLen);
nextDumpLen); result = actionHelper.reportData(commandedBy, actionId, dirListingBuf.data(),
result = actionHelper.reportData(commandedBy, actionId, dirListingBuf.data(), nextDumpLen); listingDataOffset + nextDumpLen);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
// Remove work file when we are done // Remove work file when we are done
std::filesystem::remove(LIST_DIR_DUMP_WORK_FILE, e); std::filesystem::remove(LIST_DIR_DUMP_WORK_FILE, e);

View File

@ -134,8 +134,8 @@ class ListDirectoryCmdBase {
bool compressionOptionSet() const { return this->compressOption; } bool compressionOptionSet() const { return this->compressOption; }
const char* getRepoName(size_t& repoNameLen) const { const char* getRepoName(size_t& repoNameLen) const {
return this->repoName;
repoNameLen = this->repoNameLen; repoNameLen = this->repoNameLen;
return this->repoName;
} }
size_t getBaseSize() { size_t getBaseSize() {
@ -186,8 +186,8 @@ class ListDirectoryIntoFile : public ListDirectoryCmdBase {
return result; return result;
} }
const char* getTargetName(size_t& targetNameLen) const { const char* getTargetName(size_t& targetNameLen) const {
return this->targetName;
targetNameLen = this->targetNameLen; targetNameLen = this->targetNameLen;
return this->targetName;
} }
private: private:

2
tmtc

@ -1 +1 @@
Subproject commit bb463aa05cf90809edf852d348ab1f7593ece74e Subproject commit d623e83be8536f8887f1da00a1f0c4be191db1e8