MCPcopy Create free account
hub / github.com/Snapchat/Valdi / loadResourceFromDisk

Function loadResourceFromDisk

valdi/test/utils/valdi_test_utils.cpp:168–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

166 }
167
168 for (const auto& candidate : candidates) {
169 if (Valdi::DiskUtils::stat(candidate).exists()) {
170 return candidate;
171 }
172 }
173 if (!candidates.empty()) {
174 return candidates.front();
175 }
176 return Valdi::Path(path);
177}
178
179Valdi::Result<Valdi::BytesView> loadFileFromAbsolutePath(const Valdi::Path& absolutePath) {
180 return Valdi::DiskUtils::load(absolutePath);
181}
182
183Valdi::Result<Valdi::BytesView> loadResourceFromDisk(const std::string& path) {
184 auto result = loadFileFromAbsolutePath(resolveOpenSourceTestPath(path));
185 if (result) {
186 return result;
187 }
188 // Fallbacks: Bazel may run tests with cwd = runfiles root without setting TEST_SRCDIR.
189 char cwdBuffer[PATH_MAX];
190 if (::getcwd(cwdBuffer, PATH_MAX) != nullptr) {
191 Valdi::Path runfilesPath(cwdBuffer);
192 runfilesPath.append("valdi");
193 runfilesPath.append(path);
194 runfilesPath.normalize();
195 auto fallback = loadFileFromAbsolutePath(runfilesPath);
196 if (fallback) {
197 return fallback;

Callers 2

SetUpMethod · 0.85
SetUpBaseMethod · 0.85

Calls 4

loadFileFromAbsolutePathFunction · 0.85
appendMethod · 0.65
normalizeMethod · 0.45

Tested by

no test coverage detected