2017-03-29 13:20 UTC

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0009999CentOS-6filepublic2015-12-23 04:14
Reporterrene0 
PrioritynormalSeverityminorReproducibilityalways
StatusnewResolutionopen 
Product Version 
Target VersionFixed in Version 
Summary0009999: file-libs magic file missing pattern for python file
Descriptionfile-libs 5.04-21.el6 shipped with centos6 is missing a magic pattern which detects the following python script as having a mime type of text/x-java.

<snip>
#!/usr/bin/env python

import sys

def main():
    print("hello world")

if __name__ == '__main__':
    sys.exit(main())
</snip>

A fix is to add the following to /etc/magic

<snip>
0 regex \^(\ |\\t)*def\ +[a-zA-Z]+
>&0 regex \ *\\(([a-zA-Z]|,|\ )*\\):$ Python script text executable
!:mime text/x-python
</snip>

The above snippet is found in file-libs 5.11-21.el7 shipped with centos7.
Steps To Reproduce1. Install file & file-libs.

yum install -y file file-libs

2. Create py script.

cat - <<EOF > /tmp/helloworld.py
#!/usr/bin/env python

import sys

def main():
    print("hello world")

if __name__ == '__main__':
    sys.exit(main())
EOF

3. check mime type with file.

$ file --mime-type /tmp/helloworld.py
/tmp/helloworld.py: text/x-java

For a fix, update /etc/magic and rerun file.

$ cat - <<EOF >> /etc/magic
0 regex \^(\ |\\t)*def\ +[a-zA-Z]+
>&0 regex \ *\\(([a-zA-Z]|,|\ )*\\):$ Python script text executable
!:mime text/x-python
EOF
$ file --mime-type /tmp/helloworld.py
/tmp/helloworld.py: text/x-python

TagsNo tags attached.
Attached Files

-Relationships
+Relationships

-Notes
There are no notes attached to this issue.
+Notes

-Issue History
Date Modified Username Field Change
2015-12-23 04:14 rene0 New Issue
+Issue History