Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.
Bug 1050897 - Ruby script classification should not change when require 'foo' appears prior module
Summary: Ruby script classification should not change when require 'foo' appears prior...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: file
Version: 25
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Marek Cermak
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-01-09 10:06 UTC by Vít Ondruch
Modified: 2017-09-03 04:23 UTC (History)
4 users (show)

Fixed In Version: file-5.30-10.fc26 file-5.29-9.fc25
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-08-22 20:44:33 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
Patch proposal (2.61 KB, patch)
2017-08-18 09:51 UTC, Marek Cermak
no flags Details | Diff

Description Vít Ondruch 2014-01-09 10:06:46 UTC
Description of problem:

Small change in ruby file results in its different classification:


--- /home/vondruch/rhel-scm/ruby/ruby-2.0.0-p247/lib/rubygems/core_ext/kernel_require.rb
+++ /var/lib/mock/rhel-7-x86_64/root/builddir/build/BUILD/ruby-2.0.0-p353/lib/rubygems/core_ext/kernel_require.rb
@@ -4,7 +4,11 @@
 # See LICENSE.txt for permissions.
 #++
 
+require 'monitor'
+
 module Kernel
+
+  RUBYGEMS_ACTIVATION_MONITOR = Monitor.new # :nodoc:
 
   if defined?(gem_original_require) then
     # Ruby ships with a custom_require, override its require
@@ -32,6 +36,10 @@
   # that file has already been loaded is preserved.
 
   def require path
+    RUBYGEMS_ACTIVATION_MONITOR.enter
+
+    path = path.to_path if path.respond_to? :to_path
+
     spec = Gem.find_unresolved_default_spec(path)
     if spec
       Gem.remove_unresolved_default_spec(spec)
@@ -111,6 +119,8 @@
     end
 
     raise load_error
+  ensure
+    RUBYGEMS_ACTIVATION_MONITOR.exit
   end
 
   private :require

---




$ file ~/rhel-scm/ruby/ruby-2.0.0-p247/lib/rubygems/core_ext/kernel_require.rb 
 /home/vondruch/rhel-scm/ruby/ruby-2.0.0-p247/lib/rubygems/core_ext/kernel_require.rb: Ruby module source, ASCII text
$ file /var/lib/mock/rhel-7-x86_64/root/builddir/build/BUILD/ruby-2.0.0-p353/lib/rubygems/core_ext/kernel_require.rb 
 /var/lib/mock/rhel-7-x86_64/root/builddir/build/BUILD/ruby-2.0.0-p353/lib/rubygems/core_ext/kernel_require.rb: Ruby script, ASCII text

Version-Release number of selected component (if applicable):
$ rpm -q file
file-5.14-12.fc20.x86_64



Actual results:
The classification changes.


Expected results:
The classification stays the same.


Additional info:
To be honest, I am not sure if file is not trying to be over-granular. There is nothing like "Ruby module source". Modules can be freely mixed with classes and other code. There might be more modules in single file etc. I don't think there is way how to reliably distinguish such files.

However, the classifications could look like:

Ruby script, module source, ASCII text
Ruby script, class source, ASCII text
Ruby script, class/module source, ASCII text

In addition, not sure how file classifies the ASCII text, but since Ruby 2.0, every source code is treated as UTF-8 by default, unless there is some magic comment such as "# encoding: US-ASCII" somewhere on top of the file, but this might deserve independent report ;)

Comment 1 Jaroslav Reznik 2015-03-03 15:22:48 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 22 development cycle.
Changing version to '22'.

More information and reason for this action is here:
https://fedoraproject.org/wiki/Fedora_Program_Management/HouseKeeping/Fedora22

Comment 2 Fedora Admin XMLRPC Client 2016-06-24 10:59:23 UTC
This package has changed ownership in the Fedora Package Database.  Reassigning to the new owner of this component.

Comment 3 Fedora End Of Life 2016-07-19 10:51:45 UTC
Fedora 22 changed to end-of-life (EOL) status on 2016-07-19. Fedora 22 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.

Comment 4 Vít Ondruch 2016-07-19 12:07:29 UTC
This was not resolved to my knowledge ...

Comment 5 Kamil Dudka 2016-07-19 13:06:19 UTC
The default output of file(1) is intended for humans.  It is continuously being extended to provide additional info, so it can easily differ between different versions of file(1).  Please consider using the --mime option if you need more predictable output.

If you want to improve the heuristics that file uses for classification of ruby source code, please attach a set of examples with the expected classification.

Comment 6 Vít Ondruch 2016-07-20 08:55:40 UTC
As I tried to explain in additional information, there is really nothing like "Ruby module". The file is always Ruby script, it might contain classes, modules, mixture of classes or modules, or no classes or modules at all. But there is no official notion of "Ruby module source" as file currently pretends. This is completely artificial thing ...


And as far as I remember, this issue was unveiled by some tool like rpmdiff or so, which is using file on background, so I am not in control of the parameters ...

Comment 7 Jan Kurik 2016-07-26 04:30:03 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 25 development cycle.
Changing version to '25'.

Comment 8 Fedora Update System 2017-08-18 09:49:27 UTC
file-5.29-9.fc25 has been submitted as an update to Fedora 25. https://bodhi.fedoraproject.org/updates/FEDORA-2017-ee474bb41c

Comment 9 Fedora Update System 2017-08-18 09:49:43 UTC
file-5.30-10.fc26 has been submitted as an update to Fedora 26. https://bodhi.fedoraproject.org/updates/FEDORA-2017-859756e3ac

Comment 10 Marek Cermak 2017-08-18 09:51:42 UTC
Created attachment 1315153 [details]
Patch proposal

Ruby magic file modification

Upstream commit: 
https://github.com/file/file/commit/d56eb7ea0b9c2a4edec17032a92fe66aebb1aa3a

Comment 11 Fedora Update System 2017-08-18 21:54:54 UTC
file-5.29-9.fc25 has been pushed to the Fedora 25 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-ee474bb41c

Comment 12 Fedora Update System 2017-08-19 18:55:59 UTC
file-5.30-10.fc26 has been pushed to the Fedora 26 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-859756e3ac

Comment 13 Fedora Update System 2017-08-22 20:44:33 UTC
file-5.30-10.fc26 has been pushed to the Fedora 26 stable repository. If problems still persist, please make note of it in this bug report.

Comment 14 Fedora Update System 2017-09-03 04:23:55 UTC
file-5.29-9.fc25 has been pushed to the Fedora 25 stable repository. If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.