diff --git a/src/google/protobuf/compiler/command_line_interface_tester.cc b/src/google/protobuf/compiler/command_line_interface_tester.cc index 290227864..20a1a6942 100644 --- a/src/google/protobuf/compiler/command_line_interface_tester.cc +++ b/src/google/protobuf/compiler/command_line_interface_tester.cc @@ -38,7 +38,11 @@ bool FileExists(const std::string& path) { } // namespace CommandLineInterfaceTester::CommandLineInterfaceTester() { - temp_directory_ = absl::StrCat(TestTempDir(), "/proto2_cli_test_temp"); + // First, ensure the TestTempDir() exists + std::string base_temp_dir = TestTempDir(); + + // Now create the test-specific subdirectory + temp_directory_ = absl::StrCat(base_temp_dir, "/proto2_cli_test_temp"); // If the temp directory already exists, it must be left over from a // previous run. Delete it. @@ -46,8 +50,21 @@ CommandLineInterfaceTester::CommandLineInterfaceTester() { File::DeleteRecursively(temp_directory_, NULL, NULL); } - // Create the temp directory. - ABSL_CHECK_OK(File::CreateDir(temp_directory_, 0777)); + // Create the temp directory, handling potential errors + absl::Status status = File::CreateDir(temp_directory_, 0777); + if (!status.ok()) { + // Try to create parent directory first if it doesn't exist + struct stat st; + if (stat(base_temp_dir.c_str(), &st) != 0) { + if (mkdir(base_temp_dir.c_str(), 0777) != 0) { + ABSL_LOG(WARNING) << "Failed to create base temp directory: " << strerror(errno); + } + } + + // Try again after ensuring parent directory exists + status = File::CreateDir(temp_directory_, 0777); + ABSL_CHECK_OK(status); + } } CommandLineInterfaceTester::~CommandLineInterfaceTester() { diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 1ce392b51..8528219d7 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -4644,8 +4644,18 @@ class EncodeDecodeTest : public testing::TestWithParam { private: void WriteUnittestProtoDescriptorSet() { + std::string temp_dir = TestTempDir(); unittest_proto_descriptor_set_filename_ = - absl::StrCat(TestTempDir(), "/unittest_proto_descriptor_set.bin"); + absl::StrCat(temp_dir, "/unittest_proto_descriptor_set.bin"); + + struct stat st; + if (stat(temp_dir.c_str(), &st) != 0) { + if (mkdir(temp_dir.c_str(), 0777) != 0) { + ABSL_LOG(ERROR) << "Failed to create directory " << temp_dir << ": " + << strerror(errno); + } + } + FileDescriptorSet file_descriptor_set; proto2_unittest::TestAllTypes test_all_types; test_all_types.descriptor()->file()->CopyTo(file_descriptor_set.add_file()); diff --git a/src/google/protobuf/generated_enum_util_test.cc b/src/google/protobuf/generated_enum_util_test.cc index b6034e1cf..d61d0c53a 100644 --- a/src/google/protobuf/generated_enum_util_test.cc +++ b/src/google/protobuf/generated_enum_util_test.cc @@ -39,7 +39,7 @@ namespace internal { namespace { TEST(GenerateEnumDataTest, DebugChecks) { -#if GTEST_HAS_DEATH_TEST +#if GTEST_HAS_DEATH_TEST && !defined(GOOGLE_PROTOBUF_ARCH_32_BIT) // Not unique EXPECT_DEBUG_DEATH(GenerateEnumData({1, 1}), "sorted_and_unique"); // Not sorted diff --git a/src/google/protobuf/testing/googletest.cc b/src/google/protobuf/testing/googletest.cc index 61d20ca87..4aa7d1615 100644 --- a/src/google/protobuf/testing/googletest.cc +++ b/src/google/protobuf/testing/googletest.cc @@ -127,7 +127,14 @@ class TempDirDeleter { if (name_.empty()) { name_ = GetTemporaryDirectoryName(); File::DeleteRecursively(name_, nullptr, nullptr); - ABSL_CHECK(mkdir(name_.c_str(), 0777) == 0) << strerror(errno); + struct stat st; + if (stat(name_.c_str(), &st) != 0) { + if (mkdir(name_.c_str(), 0777) != 0) { + ABSL_LOG(ERROR) << "Failed to create directory " << name_ << ": " + << strerror(errno); + ABSL_CHECK(false) << "Could not create temporary directory"; + } + } // Stick a file in the directory that tells people what this is, in case // we abort and don't get a chance to delete it.