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. */
| 355 | Limitation: `p` must be a descendant of `base`. Doesn't support adding `../` to the return path. |
| 356 | */ |
| 357 | static 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 | |
| 375 | static la_ssize_t archiveWriteVectorCallback(struct archive* a, void* client_data, const void* buffer, size_t length) { |
no test coverage detected