]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Improve basedir calculation on Windows
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 23 Feb 2020 19:45:07 +0000 (20:45 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 23 Feb 2020 20:31:17 +0000 (21:31 +0100)
Now basedir with backslashes or forward slashes should work.

src/Config.cpp
src/Util.cpp
unittest/test_argument_processing.cpp

index 831dd9b1d60335c1f11d3922d30a654fe19bfba6..0dfb2d071c8791260ac963f977574bcd95124826 100644 (file)
@@ -683,6 +683,7 @@ Config::set_item(const std::string& key,
     m_base_dir = parse_env_string(value);
     if (!m_base_dir.empty()) { // The empty string means "disable"
       verify_absolute_path(m_base_dir);
+      m_base_dir = Util::normalize_absolute_path(m_base_dir);
     }
     break;
 
index e59d5a7594fee75362c8a90ddfa2554cff26aa13..abca1d34f56fbfdf30a33ca428787084aa8fb89d 100644 (file)
@@ -119,6 +119,9 @@ common_dir_prefix_length(string_view dir, string_view path)
     return 0;
   }
 
+  assert(dir[0] == '/');
+  assert(path[0] == '/');
+
   const size_t limit = std::min(dir.length(), path.length());
   size_t i = 0;
 
@@ -134,7 +137,7 @@ common_dir_prefix_length(string_view dir, string_view path)
 
   do {
     --i;
-  } while (i > 0 && i != string_view::npos && dir[i] != '/' && path[i] != '/');
+  } while (i > 0 && dir[i] != '/' && path[i] != '/');
 
   return i;
 }
@@ -220,7 +223,13 @@ get_actual_cwd()
 {
   char buffer[PATH_MAX];
   if (getcwd(buffer, sizeof(buffer))) {
+#ifndef _WIN32
     return buffer;
+#else
+    std::string cwd = buffer;
+    std::replace(cwd.begin(), cwd.end(), '\\', '/');
+    return cwd;
+#endif
   } else {
     return {};
   }
index bf0708999d0768bf2f8a976765ebc868a69eb05a..31e90022e829c0e7e3be5c1c51df89aa617df6b9 100644 (file)
@@ -35,6 +35,7 @@ get_root()
 #else
   char volume[4]; // "C:\"
   GetVolumePathName(Util::get_actual_cwd().c_str(), volume, sizeof(volume));
+  volume[2] = '/'; // Since base directory is normalized to forward slashes
   return volume;
 #endif
 }