diff options
author | keiju <keiju@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-01-14 14:17:18 +0000 |
---|---|---|
committer | keiju <keiju@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-01-14 14:17:18 +0000 |
commit | 9deb82b1d9457997c34ebca25f2f985778c6c8fd (patch) | |
tree | c1333646153d456287182567dcc4da28d9b1f449 /lib/irb | |
parent | 7dd52f895f8271be242ff549668d825295f12ccf (diff) | |
download | ruby-9deb82b1d9457997c34ebca25f2f985778c6c8fd.tar.gz |
* lib/irb/ext/save-history.rb: outputs its history to
owner-only-readable file and change the permission of a file that
already exists [Bug #7694]. Thanks Nobuhiro IMAI for bug reports.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38813 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/irb')
-rw-r--r-- | lib/irb/ext/save-history.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/irb/ext/save-history.rb b/lib/irb/ext/save-history.rb index 3e0740d6fa..90beefbc6c 100644 --- a/lib/irb/ext/save-history.rb +++ b/lib/irb/ext/save-history.rb @@ -92,7 +92,18 @@ module IRB history_file = File.expand_path(history_file) end history_file = IRB.rc_file("_history") unless history_file - open(history_file, 'w' ) do |f| + + # Change the permission of a file that already exists[BUG #7694] + begin + if File.stat(history_file).mode & 066 + File.chmod(0600, history_file) + end + rescue Errno::ENOENT + rescue + raise + end + + open(history_file, 'w', 0600 ) do |f| hist = HISTORY.to_a f.puts(hist[-num..-1] || hist) end |