Skip to content

Commit

Permalink
Fixes #4770. YAML::Store does not retrieve UTF8 values correctly in r…
Browse files Browse the repository at this point in the history
…ead-only mode.

This is just a work around until Psych is updated with a proper fix.  I opened
#4779 to make sure I delete this fix later.
enebo committed Sep 5, 2017
1 parent 5bfce16 commit c715c6f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/ruby/stdlib/yaml/store.rb
Original file line number Diff line number Diff line change
@@ -79,4 +79,29 @@ def empty_marshal_data
def empty_marshal_checksum
EMPTY_MARSHAL_CHECKSUM
end

# FIXME: These two constants and the method open_and_lock_file should not
# be in this file (taken from pstore). See #4779.
RDWR_ACCESS = {mode: IO::RDWR | IO::CREAT | IO::BINARY, encoding: Encoding::UTF_8}.freeze
RD_ACCESS = {mode: IO::RDONLY | IO::BINARY, encoding: Encoding::UTF_8}.freeze
def open_and_lock_file(filename, read_only)
if read_only
begin
file = File.new(filename, RD_ACCESS)
begin
file.flock(File::LOCK_SH)
return file
rescue
file.close
raise
end
rescue Errno::ENOENT
return nil
end
else
file = File.new(filename, RDWR_ACCESS)
file.flock(File::LOCK_EX)
return file
end
end
end

0 comments on commit c715c6f

Please sign in to comment.