MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ check_sidecars()

std::vector< std::string > MayaFlux::Reflect::Tool::check_sidecars ( const RequestMap & requests,
const std::vector< std::filesystem::path > & headers,
const std::vector< std::filesystem::path > & existing )
nodiscard

Compares the sidecars on disk with what the generator would write, touching nothing.

Reports, one message per problem:

  • a header with MF_DESCRIBE text that produced no request;
  • a missing sidecar;
  • a sidecar that differs, naming the records and members added or removed;
  • a missing, repeated or misplaced sidecar include;
  • a sidecar in existing whose header has no request left.
Parameters
headersEvery header the scan covered.
existingSidecars found on disk under the roots, for the orphan check. Empty skips it.
Returns
No messages when everything is current.

Definition at line 102 of file Check.cpp.

106{
107 std::vector<std::string> problems;
108 std::vector<std::filesystem::path> expected;
109
110 for (const auto& header : headers) {
111 const auto found = requests.find(header);
112 if (found == requests.end()) {
113 problems.push_back(header.string() + ": contains MF_DESCRIBE text but produced no request");
114 continue;
115 }
116
117 const std::filesystem::path sidecar = sidecar_path(header);
118 expected.push_back(sidecar);
119 const std::string where = sidecar.string() + ": ";
120 const std::string want = render_sidecar(found->second);
121
122 if (auto have = read_text(sidecar)) {
123 for (auto at = have->find("\r\n"); at != std::string::npos; at = have->find("\r\n", at + 1)) {
124 have->erase(at, 1);
125 }
126 if (*have != want) {
127 const auto messages = drift(where, *have, want);
128 problems.insert(problems.end(), messages.begin(), messages.end());
129 }
130 } else {
131 problems.push_back(where + "missing, expected " + std::to_string(found->second.records.size()) + " record(s)");
132 }
133
134 if (const auto problem = check_include(found->second)) {
135 problems.push_back(*problem);
136 }
137 }
138
139 for (const auto& sidecar : existing) {
140 if (std::ranges::find(expected, sidecar) == expected.end()) {
141 problems.push_back(sidecar.string() + ": orphaned, its header has no MF_DESCRIBE left");
142 }
143 }
144 return problems;
145}
std::string render_sidecar(const HeaderRequests &requests)
Text of the sidecar for one header, with its records sorted by name.
Definition Sidecar.cpp:95
std::optional< std::string > read_text(const std::filesystem::path &path)
The whole content of path, or nullopt when it cannot be read.
Definition Sidecar.cpp:30
std::filesystem::path sidecar_path(const std::filesystem::path &header)
Path of the sidecar for header: Name.hpp becomes Name.describe.hpp beside it.
Definition Sidecar.cpp:85
std::optional< std::string > check_include(const HeaderRequests &requests)
Checks that the header includes its sidecar exactly once, after its last marker.
Definition Sidecar.cpp:161

References check_include(), read_text(), render_sidecar(), and sidecar_path().

Here is the call graph for this function: