From 6db0a2649c9da7e69add9f01a40089c6da7fc584 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 2 Jul 2023 16:38:12 +0200 Subject: [PATCH] libluna: Add a variant of PathParser::join() for relative paths --- libluna/include/luna/PathParser.h | 1 + libluna/src/PathParser.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libluna/include/luna/PathParser.h b/libluna/include/luna/PathParser.h index 672b82e8..a8f8ecbc 100644 --- a/libluna/include/luna/PathParser.h +++ b/libluna/include/luna/PathParser.h @@ -17,6 +17,7 @@ class PathParser PathParser(const PathParser&) = delete; static Result join(StringView path1, StringView path2); + static Result join_paths(StringView path1, StringView path2); static Result realpath(StringView path); diff --git a/libluna/src/PathParser.cpp b/libluna/src/PathParser.cpp index 5116b47c..bb7271e9 100644 --- a/libluna/src/PathParser.cpp +++ b/libluna/src/PathParser.cpp @@ -62,6 +62,13 @@ Result PathParser::dirname(StringView path) } Result PathParser::join(StringView path1, StringView path2) +{ + String result = TRY(join_paths(path1, path2)); + + return realpath(result.view()); +} + +Result PathParser::join_paths(StringView path1, StringView path2) { StringBuilder sb; TRY(sb.add(path1)); @@ -70,9 +77,7 @@ Result PathParser::join(StringView path1, StringView path2) TRY(sb.add(path2)); - String result = TRY(sb.string()); - - return realpath(result.view()); + return sb.string(); } Result PathParser::realpath(StringView path)