mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/pstore.rb (commit_new): use FileUtils.copy_stream for Cygwin.
[ruby-dev:23157] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5915 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
81096d395c
commit
4774e8fda5
2 changed files with 11 additions and 6 deletions
|
@ -2,6 +2,9 @@ Sun Mar 7 16:22:26 2004 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||||
|
|
||||||
* Makefile.in (lex.c): use $? instead of $<.
|
* Makefile.in (lex.c): use $? instead of $<.
|
||||||
|
|
||||||
|
* lib/pstore.rb (commit_new): use FileUtils.copy_stream for Cygwin.
|
||||||
|
[ruby-dev:23157]
|
||||||
|
|
||||||
Sun Mar 7 05:34:42 2004 Minero Aoki <aamine@loveruby.net>
|
Sun Mar 7 05:34:42 2004 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
* lib/net/http.rb: HTTPHeader keeps its header fields as an array.
|
* lib/net/http.rb: HTTPHeader keeps its header fields as an array.
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
# p db["root"]
|
# p db["root"]
|
||||||
# end
|
# end
|
||||||
|
|
||||||
require "ftools"
|
require "fileutils"
|
||||||
require "digest/md5"
|
require "digest/md5"
|
||||||
|
|
||||||
class PStore
|
class PStore
|
||||||
|
@ -100,7 +100,7 @@ class PStore
|
||||||
file = File.open(@filename, File::RDWR | File::CREAT)
|
file = File.open(@filename, File::RDWR | File::CREAT)
|
||||||
if !read_only
|
if !read_only
|
||||||
file.flock(File::LOCK_EX)
|
file.flock(File::LOCK_EX)
|
||||||
commit_new() if FileTest.exist?(new_file)
|
commit_new(file) if FileTest.exist?(new_file)
|
||||||
content = file.read()
|
content = file.read()
|
||||||
else
|
else
|
||||||
file.flock(File::LOCK_SH)
|
file.flock(File::LOCK_SH)
|
||||||
|
@ -138,7 +138,7 @@ class PStore
|
||||||
t.write(content)
|
t.write(content)
|
||||||
}
|
}
|
||||||
File.rename(tmp_file, new_file)
|
File.rename(tmp_file, new_file)
|
||||||
commit_new()
|
commit_new(file)
|
||||||
end
|
end
|
||||||
content = nil # unreference huge data
|
content = nil # unreference huge data
|
||||||
end
|
end
|
||||||
|
@ -152,10 +152,12 @@ class PStore
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def commit_new()
|
def commit_new(f)
|
||||||
|
f.truncate(0)
|
||||||
|
f.rewind
|
||||||
new_file = @filename + ".new"
|
new_file = @filename + ".new"
|
||||||
if !File.copy(new_file, @filename)
|
File.open(new_file) do |nf|
|
||||||
raise IOError
|
FileUtils.copy_stream(nf, f)
|
||||||
end
|
end
|
||||||
File.unlink(new_file)
|
File.unlink(new_file)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue