Quellcode durchsuchen

Fix TryCreateParentDirectory on Windows

On Windows, both '/' and '\' are valid path separators. So when creating
the parent directories, split the filename on both

Signed-off-by: Akshat Gokhale <agokhale@pivotal.io>
Sam Smith vor 7 Jahren
Ursprung
Commit
84963a5511
1 geänderte Dateien mit 5 neuen und 0 gelöschten Zeilen
  1. 5 0
      src/google/protobuf/compiler/command_line_interface.cc

+ 5 - 0
src/google/protobuf/compiler/command_line_interface.cc

@@ -168,7 +168,12 @@ bool VerifyDirectoryExists(const string& path) {
 // directories listed in |filename|.
 bool TryCreateParentDirectory(const string& prefix, const string& filename) {
   // Recursively create parent directories to the output file.
+#if defined(_WIN32)
+  // on Windows, both '/' and '\' are valid path separators
+  std::vector<string> parts = Split(filename, "/\\", true);
+#else
   std::vector<string> parts = Split(filename, "/", true);
+#endif
   string path_so_far = prefix;
   for (int i = 0; i < parts.size() - 1; i++) {
     path_so_far += parts[i];