Issue #13907 has been updated by jeremyevans0 (Jeremy Evans).

Assignee set to keiju (Keiju Ishitsuka)
Status changed from Open to Assigned

I'm not sure if this is a bug or not.  However, considering that irb ignores permission issues on `.irbrc` (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: https://github.com/ruby/irb/pull/19.

----------------------------------------
Bug #13907: Operation not permitted (Errno::EPERM) when adjusting .irbrc_history file permissions
https://bugs.ruby-lang.org/issues/13907#change-78823

* Author: heaven (Alexander S.)
* Status: Assigned
* Priority: Normal
* Assignee: keiju (Keiju Ishitsuka)
* Target version: 
* ruby -v: ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
This is happening every time I close irb on the server:
```
$ bin/rails console
Loading staging environment (Rails 5.1.3)
2.3.0 :001 > IRB.conf[:SAVE_HISTORY]
 => 100
2.3.0 :002 > IRB.conf[:HISTORY_FILE]
 => nil
2.3.0 :003 > IRB.rc_file("_history")
 => "/usr/local/rvm/rubies/ruby-2.3.3/.irbrc_history"
2.3.0 :004 > exit
/usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:91:in `chmod': Operation not permitted @ chmod_internal - /usr/local/rvm/rubies/ruby-2.3.3/.irbrc_history (Errno::EPERM)
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:91:in `save_history'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:64:in `block in extended'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb.rb:404:in `block in irb_at_exit'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb.rb:404:in `each'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb.rb:404:in `irb_at_exit'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb.rb:398:in `start'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/commands/console/console_command.rb:62:in `start'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/commands/console/console_command.rb:17:in `start'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/commands/console/console_command.rb:85:in `perform'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/command/base.rb:63:in `perform'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/command.rb:44:in `invoke'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/commands.rb:16:in `<top (required)>'
	from bin/rails:10:in `require'
	from bin/rails:10:in `<main>'
```

IRB is trying to adjust file permissions `File.chmod(0600, history_file)` which isn't possible because the file owner is root:rvm. I am not sure if this is really an IRB bug or not, but perhaps it should check the owner first.

```
$ ls -la /usr/local/rvm/rubies/ruby-2.3.3/
total 36
drwxrwsr-x 6 root rvm 4096 Sep 15 11:46 .
drwxrwsr-x 4 root rvm 4096 Aug 14 12:05 ..
drwxrwsr-x 2 root rvm 4096 Aug 14 12:05 bin
-rw-rw-r-- 1 root rvm 7954 Aug 14 12:05 config
drwxrwsr-x 3 root rvm 4096 Aug 14 12:05 include
-rwxrwxr-x 1 root rvm  406 Aug 14 12:05 .irbrc
-rw-rw-r-- 1 root rvm    0 Sep 15 12:28 .irbrc_history
drwxrwsr-x 4 root rvm 4096 Aug 14 12:05 lib
drwxrwsr-x 3 root rvm 4096 Aug 14 12:05 share
```



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>