• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dedicate-project / beast / 83ba6ee4-64d8-4300-bcbc-007a3bb86324

pending completion
83ba6ee4-64d8-4300-bcbc-007a3bb86324

Pull #9

circleci

fairlight1337
Large block of Doxygen comments added
Pull Request #9: Adding pipeline applications

1197 of 1197 new or added lines in 21 files covered. (100.0%)

2837 of 3042 relevant lines covered (93.26%)

13117.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.24
/src/filesystem_helper.cpp
1
#include <beast/filesystem_helper.hpp>
2

3
// Standard
4
#include <fstream>
5
#include <stdexcept>
6

7
namespace beast {
8

9
FilesystemHelper::FilesystemHelper(const std::string& model_path) {
37✔
10
  m_model_path = std::filesystem::absolute(model_path);
37✔
11

12
  if (!std::filesystem::is_directory(m_model_path) &&
50✔
13
      !std::filesystem::create_directory(m_model_path)) {
13✔
14
    throw std::invalid_argument("Could not create model directory.");
×
15
  }
16
}
37✔
17

18
std::string FilesystemHelper::saveModel(const std::string& model_identifier,
25✔
19
                                        const nlohmann::json& model) const {
20
  std::string filename = getUniqueFilename(model_identifier);
25✔
21
  updateModel(filename, model_identifier, model, nlohmann::json::object());
25✔
22

23
  return filename;
25✔
24
}
25

26
void FilesystemHelper::updateModel(const std::string& filename, const std::string& model_identifier,
25✔
27
                                   const nlohmann::json& model,
28
                                   const nlohmann::json& metadata) const {
29
  const std::string filepath = (m_model_path / filename).string();
75✔
30

31
  std::ofstream file(filepath);
50✔
32
  if (!file.is_open()) {
25✔
33
    throw std::invalid_argument("Could not open file for writing.");
×
34
  }
35

36
  nlohmann::json wrapper;
50✔
37
  wrapper["name"] = model_identifier;
25✔
38
  wrapper["model"] = model;
25✔
39
  wrapper["metadata"] = metadata;
25✔
40

41
  file << wrapper.dump(2);
25✔
42
  file.close();
25✔
43
}
25✔
44

45
std::string FilesystemHelper::cleanFilename(const std::string& filename) {
25✔
46
  std::string result;
25✔
47
  bool last_char_was_underscore = false;
25✔
48
  for (char current : filename) {
325✔
49
    if ((current >= 'a' && current <= 'z') || (current >= 'A' && current <= 'Z') ||
300✔
50
        (current >= '0' && current <= '9')) {
26✔
51
      result += current;
270✔
52
      last_char_was_underscore = false;
270✔
53
    } else if (!last_char_was_underscore && !result.empty()) {
30✔
54
      result += "_";
29✔
55
      last_char_was_underscore = true;
29✔
56
    }
57
  }
58
  if (result.back() == '_') {
25✔
59
    result.pop_back();
1✔
60
  }
61
  return result;
25✔
62
}
63

64
std::string FilesystemHelper::getUniqueFilename(const std::string& original_filename) const {
25✔
65
  int counter = 0;
25✔
66
  std::string cleaned_filename = cleanFilename(original_filename);
50✔
67
  std::string unique_filename = cleaned_filename + ".json";
25✔
68
  while (std::filesystem::exists(m_model_path / unique_filename)) {
26✔
69
    counter++;
1✔
70
    unique_filename = cleaned_filename + "_" + std::to_string(counter) + ".json";
1✔
71
  }
72
  return unique_filename;
50✔
73
}
74

75
std::vector<nlohmann::json> FilesystemHelper::loadModels() const {
33✔
76
  std::vector<nlohmann::json> models;
33✔
77

78
  for (const auto& file : std::filesystem::directory_iterator(m_model_path)) {
103✔
79
    if (file.path().extension() == ".json") {
4✔
80
      std::ifstream input(file.path());
8✔
81
      if (!input.is_open()) {
4✔
82
        throw std::invalid_argument("Could not open file for reading.");
×
83
      }
84

85
      nlohmann::json model;
4✔
86
      input >> model;
4✔
87

88
      models.push_back({{"filename", file.path().filename().string()}, {"content", model}});
28✔
89
    }
90
  }
91

92
  return models;
33✔
93
}
94

95
void FilesystemHelper::deleteModel(const std::string& filename) const {
4✔
96
  std::filesystem::path filepath = m_model_path / filename;
8✔
97
  if (!std::filesystem::exists(filepath)) {
4✔
98
    throw std::invalid_argument("Could not delete model - file does not exist.");
1✔
99
  }
100
  std::filesystem::remove(filepath);
3✔
101
}
3✔
102

103
bool FilesystemHelper::modelExists(const std::string& filename) const {
3✔
104
  return std::filesystem::exists(m_model_path / filename);
3✔
105
}
106

107
} // namespace beast
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc