MCPcopy Create free account
hub / github.com/VCVRack/Rack / getRelativePath

Function getRelativePath

src/system.cpp:357–372  ·  view source on GitHub ↗

Returns `p` in relative path form, relative to `base` Limitation: `p` must be a descendant of `base`. Doesn't support adding `../` to the return path. */

Source from the content-addressed store, hash-verified

355Limitation: `p` must be a descendant of `base`. Doesn't support adding `../` to the return path.
356*/
357static std::string getRelativePath(std::string path, std::string base) {
358 try {
359 path = fs::absolute(fs::u8path(path)).generic_u8string();
360 base = fs::absolute(fs::u8path(base)).generic_u8string();
361 }
362 catch (fs::filesystem_error& e) {
363 throw Exception("%s", e.what());
364 }
365 if (path.size() < base.size())
366 throw Exception("getRelativePath() error: path is shorter than base");
367 if (!std::equal(base.begin(), base.end(), path.begin()))
368 throw Exception("getRelativePath() error: path does not begin with base");
369
370 // If path == base, this correctly returns "."
371 return "." + std::string(path.begin() + base.size(), path.end());
372}
373
374
375static la_ssize_t archiveWriteVectorCallback(struct archive* a, void* client_data, const void* buffer, size_t length) {

Callers 1

archiveDirectoryFunction · 0.85

Calls 3

ExceptionClass · 0.85
whatMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected