diff --git a/test/Object/directory.ll b/test/Object/directory.ll index bf8ff325950..48eefcb6ecb 100644 --- a/test/Object/directory.ll +++ b/test/Object/directory.ll @@ -2,9 +2,6 @@ ;RUN: not llvm-ar r %T/test.a . 2>&1 | FileCheck %s ;CHECK: .: Is a directory -; Opening a directory works on cygwin and freebsd. -;XFAIL: freebsd, cygwin - ;RUN: rm -f %T/test.a ;RUN: touch %T/a-very-long-file-name ;RUN: llvm-ar r %T/test.a %s %T/a-very-long-file-name diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index 64ef3fa1bb9..d70db728f2d 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -782,6 +782,13 @@ static void performWriteOperation(ArchiveOperation Operation, sys::fs::file_status Status; failIfError(sys::fs::status(FD, Status), FileName); + // Opening a directory doesn't make sense. Let it failed. + // Linux cannot open directories with open(2), although + // cygwin and *bsd can. + if (Status.type() == sys::fs::file_type::directory_file) + failIfError(error_code(errc::is_a_directory, posix_category()), + FileName); + OwningPtr File; failIfError(MemoryBuffer::getOpenFile(FD, FileName, File, Status.getSize(), false),