From: Joel Rosdahl Date: Wed, 24 May 2023 19:04:30 +0000 (+0200) Subject: fix: Support Windows drive letter in file URLs for remote storage X-Git-Tag: v4.8.2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0026966efbd5609ddaca76ac57e8824202729de;p=thirdparty%2Fccache.git fix: Support Windows drive letter in file URLs for remote storage Closes #1291. --- diff --git a/doc/MANUAL.adoc b/doc/MANUAL.adoc index 4d91736cd..d353575ee 100644 --- a/doc/MANUAL.adoc +++ b/doc/MANUAL.adoc @@ -936,6 +936,7 @@ Examples: + * `+file:/shared/nfs/directory+` * `+file:///shared/nfs/one|read-only file:///shared/nfs/two+` +* `+file:///Z:/example/windows/folder+` * `+http://example.com/cache+` * `+redis://example.com+` + @@ -1184,6 +1185,7 @@ Examples: * `+file:/shared/nfs/directory+` * `+file:///shared/nfs/directory|umask=002|update-mtime=true+` +* `+file:///Z:/example/windows/folder+` * `+file://example.com/shared/ccache%20folder+` Optional attributes: diff --git a/src/storage/remote/FileStorage.cpp b/src/storage/remote/FileStorage.cpp index b1c8a338c..a860732bc 100644 --- a/src/storage/remote/FileStorage.cpp +++ b/src/storage/remote/FileStorage.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2021-2022 Joel Rosdahl and other contributors +// Copyright (C) 2021-2023 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -71,6 +71,10 @@ FileStorageBackend::FileStorageBackend(const Params& params) const auto& host = params.url.host(); #ifdef _WIN32 m_dir = util::replace_all(params.url.path(), "/", "\\"); + if (m_dir.length() >= 3 && m_dir[0] == '\\' && m_dir[2] == ':') { + // \X:\foo\bar -> X:\foo\bar according to RFC 8089 appendix E.2. + m_dir = m_dir.substr(1); + } if (!host.empty()) { m_dir = FMT("\\\\{}{}", host, m_dir); }