This is an automated email from the ASF dual-hosted git repository.

dongjoon pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/orc.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 0749e4b36 ORC-1686: [C++] Avoid using std::filesystem
0749e4b36 is described below

commit 0749e4b36f9fa6ec708474d1da4e593c514d548d
Author: Gang Wu <ust...@gmail.com>
AuthorDate: Wed Apr 10 10:47:39 2024 -0700

    ORC-1686: [C++] Avoid using std::filesystem
    
    ### What changes were proposed in this pull request?
    Remove std::filesystem and use OS API instead.
    
    ### Why are the changes needed?
    Apache Arrow C++ library is required to support old compilers like clang8. 
Since Apache ORC C++ library has used std::filesystem to check TZDB 
availability since 2.0.0, Apache Arrow requires to add more linking options for 
std::filesystem. See https://github.com/apache/arrow/pull/41023 for detail.
    
    ### How was this patch tested?
    Passing CIs.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    No.
    
    Closes #1886 from wgtmac/ORC-1686.
    
    Authored-by: Gang Wu <ust...@gmail.com>
    Signed-off-by: Dongjoon Hyun <dongj...@apache.org>
    (cherry picked from commit 695e0f33609adae0114708c3be756bb7b77f4d79)
    Signed-off-by: Dongjoon Hyun <dongj...@apache.org>
---
 c++/src/Adaptor.cc    | 16 ++++++++++++++++
 c++/src/Adaptor.hh.in |  1 +
 c++/src/Timezone.cc   |  3 +--
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/c++/src/Adaptor.cc b/c++/src/Adaptor.cc
index d9390131b..d5dd7802f 100644
--- a/c++/src/Adaptor.cc
+++ b/c++/src/Adaptor.cc
@@ -53,6 +53,12 @@ ssize_t pread(int fd, void* buf, size_t size, off_t offset) {
 #endif
 #endif
 
+#ifdef _MSC_VER
+#include <Windows.h>
+#else
+#include <sys/stat.h>
+#endif
+
 namespace orc {
 #ifdef HAS_DOUBLE_TO_STRING
   std::string to_string(double val) {
@@ -73,4 +79,14 @@ namespace orc {
     return std::to_string(static_cast<long long int>(val));
   }
 #endif
+
+  bool fileExists(const char* path) {
+#ifdef _MSC_VER
+    return GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES;
+#else
+    struct stat st;
+    return stat(path, &st) == 0;
+#endif
+  }
+
 }  // namespace orc
diff --git a/c++/src/Adaptor.hh.in b/c++/src/Adaptor.hh.in
index 6b2174080..d0a658c8e 100644
--- a/c++/src/Adaptor.hh.in
+++ b/c++/src/Adaptor.hh.in
@@ -109,6 +109,7 @@ typedef SSIZE_T ssize_t;
 namespace orc {
   std::string to_string(double val);
   std::string to_string(int64_t val);
+  bool fileExists(const char* path);
 }
 
 #ifdef HAS_BUILTIN_OVERFLOW_CHECK
diff --git a/c++/src/Timezone.cc b/c++/src/Timezone.cc
index 27e14480d..8b8ac69b1 100644
--- a/c++/src/Timezone.cc
+++ b/c++/src/Timezone.cc
@@ -24,7 +24,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
-#include <filesystem>
 #include <map>
 #include <sstream>
 
@@ -675,7 +674,7 @@ namespace orc {
     if (itr != timezoneCache.end()) {
       return *(itr->second).get();
     }
-    if (!std::filesystem::exists(std::filesystem::path(filename))) {
+    if (!fileExists(filename.c_str())) {
       std::stringstream ss;
       ss << "Time zone file " << filename << " does not exist."
          << " Please install IANA time zone database and set TZDIR env.";

Reply via email to