Skip to content

Commit

Permalink
replace most compile-time platform checks with build-time checks
Browse files Browse the repository at this point in the history
  • Loading branch information
vgough committed Aug 7, 2017
1 parent dcc7ff8 commit 6c7ad3e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Expand Up @@ -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})
Expand All @@ -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 <sys/types.h>
Expand All @@ -87,6 +96,7 @@ check_cxx_source_compiles ("#include <sys/types.h>
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)
Expand Down
5 changes: 5 additions & 0 deletions config.h.cmake
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions encfs/DirNode.cpp
Expand Up @@ -72,7 +72,7 @@ static bool _nextName(struct dirent *&de, const std::shared_ptr<DIR> &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"
Expand Down Expand Up @@ -430,7 +430,7 @@ bool DirNode::genRenameList(list<RenameEl> &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
Expand Down
2 changes: 1 addition & 1 deletion encfs/FileUtils.cpp
Expand Up @@ -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();
Expand Down
11 changes: 8 additions & 3 deletions encfs/RawFileIO.cpp
Expand Up @@ -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);
}
Expand All @@ -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;
}

Expand Down

0 comments on commit 6c7ad3e

Please sign in to comment.