]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
feat(file-storage): Support server name in URL on Windows
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 18 Jul 2022 12:19:44 +0000 (14:19 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 18 Jul 2022 12:20:15 +0000 (14:20 +0200)
doc/MANUAL.adoc
src/storage/secondary/FileStorage.cpp

index fc0eb1c3582f7e72871c652cf778e12508f01d41..be147f68cb3f1ed6f2be9a0a0df745146a4c3598 100644 (file)
@@ -1074,15 +1074,16 @@ on cache hits and misses:
 <<config_reshare,*reshare*>> option.
 
 
-
 === File storage backend
 
-URL format: `+file:DIRECTORY+` or `+file://DIRECTORY+`
+URL format: `+file:DIRECTORY+` or `+file://[HOST]DIRECTORY+`
 
 This backend stores data as separate files in a directory structure below
-*DIRECTORY* (an absolute path), similar (but not identical) to the primary cache
-storage. A typical use case for this backend would be sharing a cache on an NFS
-directory.
+*DIRECTORY*, similar (but not identical) to the primary cache storage. A typical
+use case for this backend would be sharing a cache on an NFS directory.
+*DIRECTORY* must start with a slash. *HOST* can be the empty string or
+localhost. On Windows, *HOST* can also be the name of a server hosting a shared
+folder.
 
 IMPORTANT: ccache will not perform any cleanup of the storage -- that has to be
 done by other means, for instance by running `ccache --trim-dir` periodically.
@@ -1091,6 +1092,7 @@ Examples:
 
 * `+file:/shared/nfs/directory+`
 * `+file:///shared/nfs/directory|umask=002|update-mtime=true+`
+* `+file://example.com/shared/folder+`
 
 Optional attributes:
 
index f1d550c34d44d41d0ce808586de474c7f69fbb51..8807ab407117f8a03dc0d2aa02caa59f48b3bb22 100644 (file)
@@ -55,7 +55,7 @@ public:
 private:
   enum class Layout { flat, subdirs };
 
-  const std::string m_dir;
+  std::string m_dir;
   std::optional<mode_t> m_umask;
   bool m_update_mtime = false;
   Layout m_layout = Layout::subdirs;
@@ -64,15 +64,24 @@ private:
 };
 
 FileStorageBackend::FileStorageBackend(const Params& params)
-  : m_dir(params.url.path())
 {
   ASSERT(params.url.scheme() == "file");
-  if (!params.url.host().empty()) {
-    throw core::Fatal(FMT(
-      "invalid file path \"{}\": specifying a host (\"{}\") is not supported",
-      params.url.str(),
-      params.url.host()));
+
+  const auto& host = params.url.host();
+#ifdef _WIN32
+  m_dir = util::replace_all(params.url.path(), "/", "\\");
+  if (!host.empty()) {
+    m_dir = FMT("\\\\{}\\{}", host, m_dir);
+  }
+#else
+  if (!host.empty() && host != "localhost") {
+    throw core::Fatal(
+      FMT("invalid file URL \"{}\": specifying a host other than localhost is"
+          " not supported",
+          params.url.str()));
   }
+  m_dir = params.url.path();
+#endif
 
   for (const auto& attr : params.attributes) {
     if (attr.key == "layout") {