diff --git a/src/command/StorageCommands.cxx b/src/command/StorageCommands.cxx index 3f4d56629..cf25cd08f 100644 --- a/src/command/StorageCommands.cxx +++ b/src/command/StorageCommands.cxx @@ -94,7 +94,7 @@ print_storage_uri(Client &client, Response &r, const Storage &storage) if (uri.empty()) return; - if (PathTraitsUTF8::IsAbsolute(uri.c_str())) { + if (PathTraitsUTF8::IsAbsolute(uri)) { /* storage points to local directory */ if (!client.IsLocal()) diff --git a/src/fs/AllocatedPath.hxx b/src/fs/AllocatedPath.hxx index 8809657ea..e2ce947aa 100644 --- a/src/fs/AllocatedPath.hxx +++ b/src/fs/AllocatedPath.hxx @@ -337,7 +337,7 @@ public: [[gnu::pure]] bool IsAbsolute() const noexcept { - return Traits::IsAbsolute(c_str()); + return Traits::IsAbsolute(value); } }; diff --git a/src/fs/Traits.hxx b/src/fs/Traits.hxx index 57f4814b0..7d4f64b34 100644 --- a/src/fs/Traits.hxx +++ b/src/fs/Traits.hxx @@ -130,6 +130,15 @@ struct PathTraitsFS { return IsSeparator(*p); } + [[gnu::pure]] + static bool IsAbsolute(string_view p) noexcept { +#ifdef _WIN32 + if (IsDrive(p) && IsSeparator(p[2])) + return true; +#endif + return !p.empty() && IsSeparator(p.front()); + } + [[gnu::pure]] [[gnu::nonnull]] static bool IsSpecialFilename(const_pointer name) noexcept { return (name[0] == '.' && name[1] == 0) || @@ -274,6 +283,15 @@ struct PathTraitsUTF8 { return IsSeparator(*p); } + [[gnu::pure]] + static bool IsAbsolute(string_view p) noexcept { +#ifdef _WIN32 + if (IsDrive(p) && IsSeparator(p[2])) + return true; +#endif + return !p.empty() && IsSeparator(p.front()); + } + /** * Is this any kind of absolute URI? (Unlike IsAbsolute(), * this includes URIs/URLs with a scheme)