зеркало из https://github.com/github/ruby.git
* lib/pstore.rb: open all in binary mode, and get rid of the quirk of
msvcrt. fixed: [ruby-dev:29518] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
b000ee600f
Коммит
fbe8d44d5c
|
@ -1,3 +1,8 @@
|
|||
Sat Sep 9 04:55:59 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* lib/pstore.rb: open all in binary mode, and get rid of the quirk of
|
||||
msvcrt. fixed: [ruby-dev:29518]
|
||||
|
||||
Sat Sep 9 04:47:45 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* Makefile.in, win32/Makefile.sub (MINIRUBY): append MINIRUBYOPT.
|
||||
|
|
|
@ -78,6 +78,11 @@ require "digest/md5"
|
|||
# end
|
||||
#
|
||||
class PStore
|
||||
binmode = defined?(File::BINARY) ? File::BINARY : 0
|
||||
RDWR_ACCESS = File::RDWR | File::CREAT | binmode
|
||||
RD_ACCESS = File::RDONLY | binmode
|
||||
WR_ACCESS = File::WRONLY | File::CREAT | File::TRUNC | binmode
|
||||
|
||||
# The error type thrown by all PStore methods.
|
||||
class Error < StandardError
|
||||
end
|
||||
|
@ -287,17 +292,15 @@ class PStore
|
|||
|
||||
content = nil
|
||||
unless read_only
|
||||
file = File.open(@filename, File::RDWR | File::CREAT)
|
||||
file.binmode
|
||||
file = File.open(@filename, RDWR_ACCESS)
|
||||
file.flock(File::LOCK_EX)
|
||||
commit_new(file) if FileTest.exist?(new_file)
|
||||
content = file.read()
|
||||
else
|
||||
begin
|
||||
file = File.open(@filename, File::RDONLY)
|
||||
file.binmode
|
||||
file = File.open(@filename, RD_ACCESS)
|
||||
file.flock(File::LOCK_SH)
|
||||
content = (File.read(new_file) rescue file.read())
|
||||
content = (File.open(new_file, RD_ACCESS) {|n| n.read} rescue file.read())
|
||||
rescue Errno::ENOENT
|
||||
content = ""
|
||||
end
|
||||
|
@ -326,10 +329,7 @@ class PStore
|
|||
tmp_file = @filename + ".tmp"
|
||||
content = dump(@table)
|
||||
if !md5 || size != content.size || md5 != Digest::MD5.digest(content)
|
||||
File.open(tmp_file, "w") {|t|
|
||||
t.binmode
|
||||
t.write(content)
|
||||
}
|
||||
File.open(tmp_file, WR_ACCESS) {|t| t.write(content)}
|
||||
File.rename(tmp_file, new_file)
|
||||
commit_new(file)
|
||||
end
|
||||
|
@ -365,8 +365,7 @@ class PStore
|
|||
f.truncate(0)
|
||||
f.rewind
|
||||
new_file = @filename + ".new"
|
||||
File.open(new_file) do |nf|
|
||||
nf.binmode
|
||||
File.open(new_file, RD_ACCESS) do |nf|
|
||||
FileUtils.copy_stream(nf, f)
|
||||
end
|
||||
File.unlink(new_file)
|
||||
|
|
Загрузка…
Ссылка в новой задаче