From cdb346c65eeb9f976cf3db21b3cb2f7d8837cf6b Mon Sep 17 00:00:00 2001 From: Danny Wilson Date: Sat, 7 Nov 2015 04:51:33 +0100 Subject: [PATCH 1/2] Fix build on Solaris d_type is not part of the POSIX spec unfortunately. --- configure.ac | 1 + src/libutil/util.cc | 4 ++++ src/libutil/util.hh | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/configure.ac b/configure.ac index 88e64573d..bade079b3 100644 --- a/configure.ac +++ b/configure.ac @@ -48,6 +48,7 @@ test "$localstatedir" = '${prefix}/var' && localstatedir=/nix/var # Solaris-specific stuff. +AC_STRUCT_DIRENT_D_TYPE if test "$sys_name" = sunos; then # Solaris requires -lsocket -lnsl for network functions LIBS="-lsocket -lnsl $LIBS" diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 27116fd18..d1b67c6d4 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -232,7 +232,11 @@ DirEntries readDirectory(const Path & path) checkInterrupt(); string name = dirent->d_name; if (name == "." || name == "..") continue; +#ifdef HAVE_STRUCT_DIRENT_D_TYPE entries.emplace_back(name, dirent->d_ino, dirent->d_type); +#else + entries.emplace_back(name, dirent->d_ino, getFileType(absPath(name, path))); +#endif } if (errno) throw SysError(format("reading directory ‘%1%’") % path); diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 038838820..2edc5344f 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -11,6 +11,12 @@ #include +#ifndef HAVE_STRUCT_DIRENT_D_TYPE +#define DT_UNKNOWN 0 +#define DT_REG 1 +#define DT_LNK 2 +#define DT_DIR 3 +#endif namespace nix { From 69b9d8fdbd4d428515c15cf47c2ed2324f7aa021 Mon Sep 17 00:00:00 2001 From: Danny Wilson Date: Wed, 25 Nov 2015 21:57:19 +0100 Subject: [PATCH 2/2] Use DT_UNKNOWN when dirent d_type extension is not supported. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit edolstra: “…since callers of readDirectory have to handle the possibility of DT_UNKNOWN anyway, and we don't want to do a stat call for every directory entry unless it's really needed.” --- src/libutil/util.cc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libutil/util.cc b/src/libutil/util.cc index d1b67c6d4..656d67a53 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -232,11 +232,7 @@ DirEntries readDirectory(const Path & path) checkInterrupt(); string name = dirent->d_name; if (name == "." || name == "..") continue; -#ifdef HAVE_STRUCT_DIRENT_D_TYPE - entries.emplace_back(name, dirent->d_ino, dirent->d_type); -#else - entries.emplace_back(name, dirent->d_ino, getFileType(absPath(name, path))); -#endif + entries.emplace_back(name, dirent->d_ino, #ifdef HAVE_STRUCT_DIRENT_D_TYPE dirent->d_type #else DT_UNKNOWN #endif); } if (errno) throw SysError(format("reading directory ‘%1%’") % path);