From 6c7ad3e534a86373e28db869fc12809ca17b4ef4 Mon Sep 17 00:00:00 2001 From: Valient Gough Date: Sun, 6 Aug 2017 18:10:52 -0700 Subject: [PATCH] replace most compile-time platform checks with build-time checks --- CMakeLists.txt | 10 ++++++++++ config.h.cmake | 5 +++++ encfs/DirNode.cpp | 4 ++-- encfs/FileUtils.cpp | 2 +- encfs/RawFileIO.cpp | 11 ++++++++--- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 34a4f72..30fa9a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,12 @@ if (APPLE) endif() endif() +if (WIN32 OR APPLE) + set(DEFAULT_CASE_INSENSITIVE TRUE) +else() + set(DEFAULT_CASE_INSENSITIVE FALSE) +endif() + # Check for FUSE. find_package (FUSE REQUIRED) include_directories (${FUSE_INCLUDE_DIR}) @@ -76,6 +82,9 @@ include (CheckIncludeFileCXX) check_include_file_cxx (attr/xattr.h HAVE_ATTR_XATTR_H) check_include_file_cxx (sys/xattr.h HAVE_SYS_XATTR_H) +include(CheckStructHasMember) +check_struct_has_member(dirent d_type dirent.h HAVE_DIRENT_D_TYPE LANGUAGE CXX) + # Check if xattr functions take extra arguments, as they do on OSX. include (CheckCXXSourceCompiles) check_cxx_source_compiles ("#include @@ -87,6 +96,7 @@ check_cxx_source_compiles ("#include include (CheckFuncs) check_function_exists_glibc (lchmod HAVE_LCHMOD) check_function_exists_glibc (utimensat HAVE_UTIMENSAT) +check_function_exists_glibc (fdatasync HAVE_FDATASYNC) set (CMAKE_THREAD_PREFER_PTHREAD) find_package (Threads REQUIRED) diff --git a/config.h.cmake b/config.h.cmake index 1e2fdc4..8548d70 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -6,6 +6,11 @@ #cmakedefine XATTR_LLIST #cmakedefine HAVE_LCHMOD +#cmakedefine HAVE_FDATASYNC + +#cmakedefine HAVE_DIRENT_D_TYPE + +#cmakedefine DEFAULT_CASE_INSENSITIVE /* TODO: add other thread library support. */ #cmakedefine CMAKE_USE_PTHREADS_INIT diff --git a/encfs/DirNode.cpp b/encfs/DirNode.cpp index 2457d1c..9a3c847 100644 --- a/encfs/DirNode.cpp +++ b/encfs/DirNode.cpp @@ -72,7 +72,7 @@ static bool _nextName(struct dirent *&de, const std::shared_ptr &dir, if (de != nullptr) { if (fileType != nullptr) { -#if defined(_DIRENT_HAVE_D_TYPE) || defined(__FreeBSD__) || defined(__APPLE__) +#if defined(HAVE_DIRENT_D_TYPE) *fileType = de->d_type; #else #warning "struct dirent.d_type not supported" @@ -430,7 +430,7 @@ bool DirNode::genRenameList(list &renameList, const char *fromP, ren.newPName = string(toP) + '/' + plainName; bool isDir; -#if defined(_DIRENT_HAVE_D_TYPE) +#if defined(HAVE_DIRENT_D_TYPE) if (de->d_type != DT_UNKNOWN) { isDir = (de->d_type == DT_DIR); } else diff --git a/encfs/FileUtils.cpp b/encfs/FileUtils.cpp index 5080952..3fb0c8c 100644 --- a/encfs/FileUtils.cpp +++ b/encfs/FileUtils.cpp @@ -1035,7 +1035,7 @@ RootPtr createV6Config(EncFS_Context *ctx, alg = findCipherAlgorithm("AES", keySize); // If case-insensitive system, opt for Block32 filename encoding -#if defined(__APPLE__) || defined(WIN32) +#if DEFAULT_CASE_INSENSITIVE nameIOIface = BlockNameIO::CurrentInterface(true); #else nameIOIface = BlockNameIO::CurrentInterface(); diff --git a/encfs/RawFileIO.cpp b/encfs/RawFileIO.cpp index b4373fd..fc90ba2 100644 --- a/encfs/RawFileIO.cpp +++ b/encfs/RawFileIO.cpp @@ -257,9 +257,6 @@ int RawFileIO::truncate(off_t size) { if (fd >= 0 && canWrite) { res = ::ftruncate(fd, size); -#if !defined(__FreeBSD__) && !defined(__APPLE__) - ::fdatasync(fd); -#endif } else { res = ::truncate(name.c_str(), size); } @@ -276,6 +273,14 @@ int RawFileIO::truncate(off_t size) { knownSize = true; } + if (fd >= 0 && canWrite) { +#if defined(HAVE_FDATASYNC) + ::fdatasync(fd); +#else + ::fsync(fd); +#endif + } + return res; }