From 84963a55110dd5e95d6d4d90fbe48b4a2addc4ff Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Thu, 9 Aug 2018 10:46:22 -0400 Subject: 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 --- src/google/protobuf/compiler/command_line_interface.cc | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 8380367f..12dec9c2 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/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 parts = Split(filename, "/\\", true); +#else std::vector parts = Split(filename, "/", true); +#endif string path_so_far = prefix; for (int i = 0; i < parts.size() - 1; i++) { path_so_far += parts[i]; -- cgit v1.2.3 From bf784289d280f9c85167c2fbe497ef0a5ec17568 Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Mon, 13 Aug 2018 17:17:33 -0400 Subject: Always spilt on '\' and '/' --- src/google/protobuf/compiler/command_line_interface.cc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src') diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 12dec9c2..a1f3bafc 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -168,12 +168,8 @@ 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 + // On Windows, both '/' and '\' are valid path separators. std::vector parts = Split(filename, "/\\", true); -#else - std::vector parts = Split(filename, "/", true); -#endif string path_so_far = prefix; for (int i = 0; i < parts.size() - 1; i++) { path_so_far += parts[i]; -- cgit v1.2.3