Skip to content

Commit

Permalink
llvm-ar: Let opening a directory failed in llvm-ar.
Browse files Browse the repository at this point in the history
Linux cannot open directories with open(2), although cygwin and *bsd can.

Motivation: The test, Object/directory.ll, had been failing with --target=cygwin on Linux. XFAIL was improper for host issues.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194257 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
chapuni committed Nov 8, 2013
1 parent de71238 commit 6af8781
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 0 additions & 3 deletions test/Object/directory.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tools/llvm-ar/llvm-ar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MemoryBuffer> File;
failIfError(MemoryBuffer::getOpenFile(FD, FileName, File,
Status.getSize(), false),
Expand Down

0 comments on commit 6af8781

Please sign in to comment.