https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112017-09-15T20:13:52ZRuby Issue Tracking SystemRuby master - Bug #13907: Operation not permitted (Errno::EPERM) when adjusting .irbrc_history file permissionshttps://bugs.ruby-lang.org/issues/13907?journal_id=667042017-09-15T20:13:52Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>I am pretty sure that this is a small bug in IRB. It is a method in IRB itself,<br>
so it should be the responsibility of IRB to handle cases like the above<br>
properly.</p>
<p>The method looks like this:</p>
<pre><code>def save_history
if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
if history_file = IRB.conf[:HISTORY_FILE]
history_file = File.expand_path(history_file)
end
history_file = IRB.rc_file("_history") unless history_file
# Change the permission of a file that already exists[BUG #7694]
begin
if File.stat(history_file).mode & 066 != 0
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
end
end
</code></pre>
<p>The problem should be at:</p>
<pre><code>if File.stat(history_file).mode & 066 != 0
File.chmod(0600, history_file)
</code></pre>
<p>I don't have 2.3.3. so I can not check if this still exists in<br>
more recent versions of IRB. But I think that in general,<br>
there should either be a check BEFORE File.chmod, to see whether<br>
we can modify the file in question - this may be more elegant.</p>
<p>Or alternatively, Errno::EPERM should also be rescued. (In the<br>
above check, with proper permissions, one can probably change it<br>
within ruby + irb; whereas, without proper permissions, I do<br>
not think that ruby can do something if you lack permissions to<br>
the filesystem.)</p>
<p>But anyway, I agree with you - IRB should check for the proper<br>
permission.</p>
<p>PS: The old bug referenced from the above method that I just posted,<br>
part of the file save-history.rb, was from 4 years ago at:</p>
<p><a href="https://bugs.ruby-lang.org/issues/7694" class="external">https://bugs.ruby-lang.org/issues/7694</a></p>
<p>I just note this down if others want to have a look too.</p> Ruby master - Bug #13907: Operation not permitted (Errno::EPERM) when adjusting .irbrc_history file permissionshttps://bugs.ruby-lang.org/issues/13907?journal_id=788232019-06-24T18:19:03Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>keiju (Keiju Ishitsuka)</i></li></ul><p>I'm not sure if this is a bug or not. However, considering that irb ignores permission issues on <code>.irbrc</code> (not intentionally I think), I suppose it makes sense to also ignore permission issues on the history file. I added a pull request in case the IRB maintainers want to make this change: <a href="https://github.com/ruby/irb/pull/19" class="external">https://github.com/ruby/irb/pull/19</a>.</p> Ruby master - Bug #13907: Operation not permitted (Errno::EPERM) when adjusting .irbrc_history file permissionshttps://bugs.ruby-lang.org/issues/13907?journal_id=801092019-07-26T21:47:04Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li></ul>