Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/src/main/java/org/jruby/util/io/PosixShim.java
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,9 @@ private int tryLock(ChannelFD fd, boolean exclusive) throws IOException {
return 0;
}

return lockFailedReturn(exclusive ? LOCK_EX : LOCK_SH);
// null means another process holds the lock, which flock(2) reports as EWOULDBLOCK
setErrno(Errno.EWOULDBLOCK);
return -1;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions spec/ruby/core/file/flock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
END_OF_CODE
end

it "returns false if trying to non-exclusively lock an exclusively locked file" do
@file.flock File::LOCK_EX

ruby_exe(<<-END_OF_CODE).should == "false"
File.open('#{@name}', "r") do |f2|
print f2.flock(File::LOCK_SH | File::LOCK_NB).to_s
end
END_OF_CODE
end

it "blocks if trying to lock an exclusively locked file" do
@file.flock File::LOCK_EX

Expand Down
1 change: 0 additions & 1 deletion spec/tags/ruby/core/file/flock_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
critical(hangs):File#flock blocks if trying to lock an exclusively locked file
windows:File#flock returns false if trying to lock an exclusively locked file
Loading