* lib/pstore.rb (PStore::CHECKSUM_ALGO): extract the algorithm for
  checksum, instead of qualified names for each times.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-06-28 13:55:02 +00:00
Родитель cafeeb4bec
Коммит c9df0f82b7
2 изменённых файлов: 9 добавлений и 3 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Tue Jun 28 22:55:00 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/pstore.rb (PStore::CHECKSUM_ALGO): extract the algorithm for
checksum, instead of qualified names for each times.
Tue Jun 28 22:29:36 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* bootstraptest/runner.rb: do not use safe navigation operator.

Просмотреть файл

@ -352,9 +352,10 @@ class PStore
private
# Constant for relieving Ruby's garbage collector.
CHECKSUM_ALGO = Digest::MD5
EMPTY_STRING = ""
EMPTY_MARSHAL_DATA = Marshal.dump({})
EMPTY_MARSHAL_CHECKSUM = Digest::MD5.digest(EMPTY_MARSHAL_DATA)
EMPTY_MARSHAL_CHECKSUM = CHECKSUM_ALGO.digest(EMPTY_MARSHAL_DATA)
#
# Open the specified filename (either in read-only mode or in
@ -409,7 +410,7 @@ class PStore
size = empty_marshal_data.bytesize
else
table = load(data)
checksum = Digest::MD5.digest(data)
checksum = CHECKSUM_ALGO.digest(data)
size = data.bytesize
raise Error, "PStore file seems to be corrupted." unless table.is_a?(Hash)
end
@ -429,7 +430,7 @@ class PStore
def save_data(original_checksum, original_file_size, file)
new_data = dump(@table)
if new_data.bytesize != original_file_size || Digest::MD5.digest(new_data) != original_checksum
if new_data.bytesize != original_file_size || CHECKSUM_ALGO.digest(new_data) != original_checksum
if @ultra_safe && !on_windows?
# Windows doesn't support atomic file renames.
save_data_with_atomic_file_rename_strategy(new_data, file)