diff options
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/primops.cc | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index ca4ccf449599..461a5477686c 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -815,22 +815,15 @@ static void prim_readDir(EvalState & state, const Pos & pos, Value * * args, Val DirEntries entries = readDirectory(path); state.mkAttrs(v, entries.size()); - for (const auto & ent : entries) { + for (auto & ent : entries) { Value * ent_val = state.allocAttr(v, state.symbols.create(ent.name)); - if (ent.type == DT_UNKNOWN) { - struct stat st = lstat(path + "/" + ent.name); - mkString(*ent_val, - S_ISREG(st.st_mode) ? "regular" : - S_ISDIR(st.st_mode) ? "directory" : - S_ISLNK(st.st_mode) ? "symlink" : - "unknown"); - } else { - mkString(*ent_val, - ent.type == DT_REG ? "regular" : - ent.type == DT_DIR ? "directory" : - ent.type == DT_LNK ? "symlink" : - "unknown"); - } + if (ent.type == DT_UNKNOWN) + ent.type = getFileType(path); + mkString(*ent_val, + ent.type == DT_REG ? "regular" : + ent.type == DT_DIR ? "directory" : + ent.type == DT_LNK ? "symlink" : + "unknown"); } v.attrs->sort(); |