Project

General

Profile

Actions

Bug #17840

open

`make install` overriding file permission with 644

Added by jaruga (Jun Aruga) about 2 months ago. Updated about 2 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:103660]

Description

On the current latest master b0b5a4e86ef2740c427f9356a4173a1debf4f79c, by the following steps, I can see the difference between files permission between installed Ruby's gems directory installed by make install and gems directory installed by gem install. It seems that the make install with tool/rbinstall.rb overrides the file permission with 644. Is this intentional? Thanks.

$ autoconf
$ ./configure \
  --prefix=${HOME}/local/ruby-master-b0b5a4e \
  --enable-shared
$ make
$ make install
$ ~/local/ruby-master-b0b5a4e/bin/ruby -v
ruby 3.1.0dev (2021-04-28T18:50:15Z master b0b5a4e86e) [x86_64-linux]

$ ~/local/ruby-master-b0b5a4e/bin/gem -v
3.3.0.dev

Then seeing gems/bundled_gems file, install the same version's bundled gems to user's directory.

$ ~/local/ruby-master-b0b5a4e/bin/gem install -v 2.0.0 --user power_assert
$ ~/local/ruby-master-b0b5a4e/bin/gem install -v 13.0.3 --user rake
$ ~/local/ruby-master-b0b5a4e/bin/gem install -v 3.4.1 --user test-unit
$ ~/local/ruby-master-b0b5a4e/bin/gem install -v 1.2.0 --user rbs

Then compare files permissions.

power_assert

$ ls -l ~/local/ruby-master-b0b5a4e/lib/ruby/gems/3.1.0/gems/power_assert-2.0.0/bin/
total 8
-rw-r--r--. 1 jaruga jaruga 146 Apr 29 17:07 console
-rw-r--r--. 1 jaruga jaruga  74 Apr 29 17:07 setup


$ ls -l ~/.gem/ruby/3.1.0/gems/power_assert-2.0.0/bin/
total 8
-rwxrwxr-x. 1 jaruga jaruga 146 Apr 29 18:00 console*
-rwxrwxr-x. 1 jaruga jaruga  74 Apr 29 18:00 setup*

rake

$ ls -l ~/local/ruby-master-b0b5a4e/lib/ruby/gems/3.1.0/gems/rake-13.0.3/bin/
total 24
-rw-r--r--. 1 jaruga jaruga 2841 Apr 29 17:07 bundle
-rw-r--r--. 1 jaruga jaruga   85 Apr 29 17:07 console
-rw-r--r--. 1 jaruga jaruga  787 Apr 29 17:07 rake
-rw-r--r--. 1 jaruga jaruga  787 Apr 29 17:07 rdoc
-rw-r--r--. 1 jaruga jaruga  796 Apr 29 17:07 rubocop
-rw-r--r--. 1 jaruga jaruga   74 Apr 29 17:07 setup

$ ls -l ~/.gem/ruby/3.1.0/gems/rake-13.0.3/bin/
total 24
-rwxr-xr-x. 1 jaruga jaruga 2841 Apr 29 18:00 bundle*
-rwxr-xr-x. 1 jaruga jaruga   85 Apr 29 18:00 console*
-rwxr-xr-x. 1 jaruga jaruga  787 Apr 29 18:00 rake*
-rwxr-xr-x. 1 jaruga jaruga  787 Apr 29 18:00 rdoc*
-rwxr-xr-x. 1 jaruga jaruga  796 Apr 29 18:00 rubocop*
-rwxr-xr-x. 1 jaruga jaruga   74 Apr 29 18:00 setup*

rbs

$ ls -l ~/local/ruby-master-b0b5a4e/lib/ruby/gems/3.1.0/gems/rbs-1.2.0/bin/
total 40
-rw-r--r--. 1 jaruga jaruga 4369 Apr 29 17:07 annotate-with-rdoc
-rw-r--r--. 1 jaruga jaruga  338 Apr 29 17:07 console
-rw-r--r--. 1 jaruga jaruga 2977 Apr 29 17:07 query-rdoc
-rw-r--r--. 1 jaruga jaruga  200 Apr 29 17:07 rbs-prof
-rw-r--r--. 1 jaruga jaruga 1199 Apr 29 17:07 run_in_md.rb
-rw-r--r--. 1 jaruga jaruga  150 Apr 29 17:07 setup
-rw-r--r--. 1 jaruga jaruga 1856 Apr 29 17:07 sort
-rw-r--r--. 1 jaruga jaruga  103 Apr 29 17:07 steep
-rw-r--r--. 1 jaruga jaruga  710 Apr 29 17:07 test_runner.rb

$ ls -l ~/.gem/ruby/3.1.0/gems/rbs-1.2.0/bin/
total 40
-rwxr-xr-x. 1 jaruga jaruga 4369 Apr 29 18:01 annotate-with-rdoc*
-rwxr-xr-x. 1 jaruga jaruga  338 Apr 29 18:01 console*
-rwxr-xr-x. 1 jaruga jaruga 2977 Apr 29 18:01 query-rdoc*
-rwxr-xr-x. 1 jaruga jaruga  200 Apr 29 18:01 rbs-prof*
-rw-r--r--. 1 jaruga jaruga 1199 Apr 29 18:01 run_in_md.rb
-rwxr-xr-x. 1 jaruga jaruga  150 Apr 29 18:01 setup*
-rwxr-xr-x. 1 jaruga jaruga 1856 Apr 29 18:01 sort*
-rwxr-xr-x. 1 jaruga jaruga  103 Apr 29 18:01 steep*
-rwxr-xr-x. 1 jaruga jaruga  710 Apr 29 18:01 test_runner.rb*

test-unit

$ ls -l ~/local/ruby-master-b0b5a4e/lib/ruby/gems/3.1.0/gems/test-unit-3.4.1/test/run-test.rb 
-rw-r--r--. 1 jaruga jaruga 620 Apr 29 17:07 /home/jaruga/local/ruby-master-b0b5a4e/lib/ruby/gems/3.1.0/gems/test-unit-3.4.1/test/run-test.rb

$ ls -l ~/.gem/ruby/3.1.0/gems/test-unit-3.4.1/test/run-test.rb 
-rwxr-xr-x. 1 jaruga jaruga 620 Apr 29 18:01 /home/jaruga/.gem/ruby/3.1.0/gems/test-unit-3.4.1/test/run-test.rb*

The reason why I choose the files is because I found the following items detected by a lint program in Fedora project. The messages mean that a file with shebang do not have executable bits.

rubygem-power_assert.noarch: E: non-executable-script /usr/share/gems/gems/power_assert-1.2.0/bin/console 644 /usr/bin/env ruby
rubygem-power_assert.noarch: E: non-executable-script /usr/share/gems/gems/power_assert-1.2.0/bin/setup 644 /usr/bin/env bash
rubygem-rake.noarch: E: non-executable-script /usr/share/gems/gems/rake-13.0.3/bin/bundle 644 /usr/bin/env ruby
rubygem-rake.noarch: E: non-executable-script /usr/share/gems/gems/rake-13.0.3/bin/console 644 /usr/bin/env ruby
rubygem-rake.noarch: E: non-executable-script /usr/share/gems/gems/rake-13.0.3/bin/rake 644 /usr/bin/env ruby
rubygem-rake.noarch: E: non-executable-script /usr/share/gems/gems/rake-13.0.3/bin/rdoc 644 /usr/bin/env ruby
rubygem-rake.noarch: E: non-executable-script /usr/share/gems/gems/rake-13.0.3/bin/rubocop 644 /usr/bin/env ruby
rubygem-rake.noarch: E: non-executable-script /usr/share/gems/gems/rake-13.0.3/bin/setup 644 /usr/bin/env bash
rubygem-rbs.noarch: E: non-executable-script /usr/share/gems/gems/rbs-1.0.4/bin/annotate-with-rdoc 644 /usr/bin/env ruby
rubygem-rbs.noarch: E: non-executable-script /usr/share/gems/gems/rbs-1.0.4/bin/console 644 /usr/bin/env ruby
rubygem-rbs.noarch: E: non-executable-script /usr/share/gems/gems/rbs-1.0.4/bin/query-rdoc 644 /usr/bin/env ruby
rubygem-rbs.noarch: E: non-executable-script /usr/share/gems/gems/rbs-1.0.4/bin/rbs-prof 644 /usr/bin/env ruby
rubygem-rbs.noarch: E: non-executable-script /usr/share/gems/gems/rbs-1.0.4/bin/setup 644 /usr/bin/env bash
rubygem-rbs.noarch: E: non-executable-script /usr/share/gems/gems/rbs-1.0.4/bin/sort 644 /usr/bin/env ruby
rubygem-rbs.noarch: E: non-executable-script /usr/share/gems/gems/rbs-1.0.4/bin/steep 644 /bin/sh 
rubygem-rbs.noarch: E: non-executable-script /usr/share/gems/gems/rbs-1.0.4/bin/test_runner.rb 644 /usr/bin/env ruby
rubygem-test-unit.noarch: E: non-executable-script /usr/share/gems/gems/test-unit-3.3.7/test/run-test.rb 644 /usr/bin/env ruby

Note this ticket is related to the following issue tickets I opened yesterday. It's to suggest to drop development files in the gem file.

Updated by xtkoba (Tee KOBAYASHI) about 2 months ago

Seems intentionally done at tool/rbinstall.rb:774. Files having pattern libexec/* are chmodded to prog_mode (0755), otherwise to data_mode (0644).

Updated by jaruga (Jun Aruga) about 2 months ago

Thanks for checking. I assumed the data_mode (0644) might cause this situation.

However after editing rbinstall.rb to change the data_mode from 0644 to 0755, I still saw the installed files permissions were still 644.

$ vi tool/rbinstall.rb
diff --git a/tool/rbinstall.rb b/tool/rbinstall.rb
index 141b67097b..eed48c7901 100755
--- a/tool/rbinstall.rb
+++ b/tool/rbinstall.rb
@@ -47,7 +47,8 @@ def parse_args(argv = ARGV)
   $dryrun = false
   $rdocdir = nil
   $htmldir = nil
-  $data_mode = 0644
+  # $data_mode = 0666
+  $data_mode = 0755
   $prog_mode = 0755
   $dir_mode = nil
   $script_mode = nil
$ rm -rf ~/local/ruby-master-b0b5a4e

$ make install
$ ls -l ~/local/ruby-master-b0b5a4e/lib/ruby/gems/3.1.0/gems/power_assert-2.0.0/bin/
total 8
-rw-r--r--. 1 jaruga jaruga 146 Apr 29 17:07 console
-rw-r--r--. 1 jaruga jaruga  74 Apr 29 17:07 setup

$ ls -l ~/local/ruby-master-b0b5a4e/lib/ruby/gems/3.1.0/gems/test-unit-3.4.1/test/run-test.rb 
-rw-r--r--. 1 jaruga jaruga 620 Apr 29 17:07 /home/jaruga/local/ruby-master-b0b5a4e/lib/ruby/gems/3.1.0/gems/test-unit-3.4.1/test/run-test.rb

Updated by xtkoba (Tee KOBAYASHI) about 2 months ago

jaruga (Jun Aruga) That is because what you changed is the default value of data_mode which is overwritten by command-line options:

./miniruby -I../lib -I. -I.ext/common  ../tool/runruby.rb --extout=.ext  -- --disable-gems -r./x86_64-linux-fake ../tool/rbinstall.rb --make="make" --dest-dir="" --extout=".ext" --mflags="-n" --make-flags="n" --data-mode=0644 --prog-mode=0755 --installed-list .installed.list --mantype="doc" --exclude=doc

in which 0644 comes from INSTALL_DATA_MODE defined in common.mk. Try make install INSTALL_DATA_MODE=0755 for example and see what happens.

As for package management, for example Gentoo Portage removes bundled gems and so it has no trouble with permissions of gem-derived files.

Updated by jaruga (Jun Aruga) about 2 months ago

You are right! Thank you for your detailed explanation! I confirmed the files permissions were changed by your steps.

As for package management, for example Gentoo Portage removes bundled gems and so it has no trouble with permissions of gem-derived files.

It's helpful and interesting for me to see other Linux distribution's cases. As we do not really see a problem for the Fedora RPM Ruby package in the current logic, possibly we will go ahead without change.

I was able to confirm that the installed bundled gem files' permissions are kept without change by just removing the data_mode in the options (the code)

$ git diff
diff --git a/tool/rbinstall.rb b/tool/rbinstall.rb
index 141b67097b..6bae246af1 100755
--- a/tool/rbinstall.rb
+++ b/tool/rbinstall.rb
@@ -979,7 +979,6 @@ def install_default_gem(dir, srcdir, bindir)
     :domain => :local,
     :ignore_dependencies => true,
     :dir_mode => $dir_mode,
-    :data_mode => $data_mode,
     :prog_mode => $script_mode,
     :wrappers => true,
     :format_executable => true, 

Checking a history of tool/rbinstall.rb, it seems the following commits introduced the data_mode used in installing gems.

Date: Tue Jan 13 08:21:51 2015 +0000
rbinstall.rb: reuse options hash
https://github.com/ruby/ruby/commit/79cd3c375711fb835d190d9e51a8de841f260075

Date: Sun Apr 5 00:34:27 2015 +0000
rbinstall.rb: same options for gems
https://github.com/ruby/ruby/commit/5180de635a93d079070f1c942522cf2a969ec7f8

Actions

Also available in: Atom PDF