]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Support Windows drive letter in file URLs for remote storage
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 24 May 2023 19:04:30 +0000 (21:04 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 24 May 2023 19:54:23 +0000 (21:54 +0200)
Closes #1291.

doc/MANUAL.adoc
src/storage/remote/FileStorage.cpp

index 4d91736cdd6197e2160b43f5605169d097dc25b5..d353575ee9868e43e33a58ab5fbcba2273dde42b 100644 (file)
@@ -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:
index b1c8a338c53c5aff2da4e653f7ff5baa1f569062..a860732bc32f09ac5da88888e9abb8a92996ce02 100644 (file)
@@ -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);
   }