This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 31977 - Cannot make a declarative MIME resolver check magic headers for only some file extensions
Summary: Cannot make a declarative MIME resolver check magic headers for only some fil...
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Filesystems (show other bugs)
Version: 3.x
Hardware: All All
: P3 blocker (vote)
Assignee: Petr Nejedly
URL:
Keywords: PERFORMANCE
Depends on: 18910
Blocks: 16191 117280 119099
  Show dependency tree
 
Reported: 2003-03-13 15:35 UTC by Jesse Glick
Modified: 2008-12-22 13:34 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2003-03-13 15:35:02 UTC
Try the attached module JAR. It works as expected
to recognize JAR manifest files. Unfortunately it
is very inefficient because it opens *every* file
on disk to examine its contents when creating data
objects; when turning it on, you can hear your
disk grind for a while.

<file>
    <magic
hex="4D616E69666573742D56657273696F6E3A20312E30"/>
    <resolver mime="text/x-java-jar-manifest"/>
</file>

is the problem. Would be nicer to write e.g.

<file>
    <ext name="mf"/>
    <ext name="MF"/>
    <ext name="txt"/>
    <magic
hex="4D616E69666573742D56657273696F6E3A20312E30"/>
    <resolver mime="text/x-java-jar-manifest"/>
</file>

but this does not work; then *every* text file is
treated as a manifest, which is incorrect. Really
wanted something like:

<file>
    <and>
        <or>
            <ext name="mf"/>
            <ext name="MF"/>
            <ext name="txt"/>
        </or>
        <magic
hex="4D616E69666573742D56657273696F6E3A20312E30"/>
    </and>
    <resolver mime="text/x-java-jar-manifest"/>
</file>

But such syntax is not currently supported. This
could be a real performance problem as we move to
DS II when all files are recognized according to
MIME type.
Comment 1 Jesse Glick 2004-08-17 04:03:50 UTC
No immediate impact. Clearly not fixable for D - API frozen.
Comment 2 rmatous 2004-08-24 17:08:20 UTC
This syntax seems to me supported:

<file name="manifest2.MF"><![CDATA[<?xml version="1.0"?>
    <MIME-resolver>
	<file>
	<ext name="MF"/>
	<magic hex="4D616E69666573742D56657273696F6E3A20312E30"/>
	<resolver mime="text/x-java-jar-manifest"/>
	</file>
    </MIME-resolver>]]>
</file>

<file name="manifest.mf"><![CDATA[<?xml version="1.0"?>
    <MIME-resolver>
	<file>
	<ext name="mf"/>
	<magic hex="4D616E69666573742D56657273696F6E3A20312E30"/>
	<resolver mime="text/x-java-jar-manifest"/>
	</file>
    </MIME-resolver>]]>
</file>

<file name="manifest3.txt"><![CDATA[<?xml version="1.0"?>
    <MIME-resolver>
	<file>
	<ext name="txt"/>
	<magic hex="4D616E69666573742D56657273696F6E3A20312E30"/>
	<resolver mime="text/x-java-jar-manifest"/>
	</file>
    </MIME-resolver>]]>
</file>

Is it enough ?
Comment 3 Jesse Glick 2004-08-24 23:57:33 UTC
Your example is broken (need a single XML file), but yes I think it
would work to have several <file> elements in a <MIME-resolver>
duplicating the magic key. Just ugly, that is all.
Comment 4 rmatous 2004-08-25 10:41:48 UTC
It works as far as I tested it in unit tests (single XML file would
also definitely work). 


I don't see it so ugly. But I admit that your ant alike syntax is better.
Comment 5 Jesse Glick 2007-03-04 22:34:44 UTC
It does not work. The semantics of <file>:

http://www.netbeans.org/download/dev/javadoc/org-openide-filesystems/org/openide/filesystems/doc-files/resolverDocumentation.html#file

"Some of them must match to proceed to the resolver element."

This means that I cannot e.g. patch

scripting/sh/src/org/netbeans/modules/languages/sh/sh.xml

to include:

    <file>
        <ext name=""/>
        <magic hex="23212f62696e2f73680a"/> <!-- "#!/bin/sh\n" -->
        <resolver mime="text/sh"/>
    </file>

It does not work - *any* file without an extension is treated as a shell script,
and *every* other file is opened to look for the magic token. I want an <and>
here, not an <or>.
Comment 6 rmatous 2007-10-01 15:35:12 UTC
Petr, because of fixing #117319 - please  look at this issue or reassign back
Comment 7 Petr Nejedly 2007-10-01 23:12:15 UTC
I think that the only logical interpretation of the declarative resolver would be implicit OR of all subelements of the
same kind and implicit AND between all present kind groups, that is:
<file>
    <ext name="mf"/>
    <ext name="MF"/>
    <ext name="txt"/>
    <magic
hex="4D616E69666573742D56657273696F6E3A20312E30"/>
    <resolver mime="text/x-java-jar-manifest"/>
</file>

should be interpreted as
(mf || MF || txt) && magic(4D616E69666573742D56657273696F6E3A20312E30).

It doesn't make sense to place "AND" between elements of the same kind. It doesn't make sense to place OR between
elements of the different kind either (but this is current state).
I believe no current resolver depend on the present behavior of or-between-kinds, so it should be safe to change the
behavior. The change would be semantically incompatible, technically speaking, though.
Comment 8 Petr Nejedly 2007-10-16 11:40:33 UTC
I'm going to fix this as outlined.
Even one test in MIMEResolverImplTest suggests that it is in fact the expected behavior.
BTW: The test should be failing, because there was another bug in MIMEResolverImpl (off-by-one when stripping mime type
argument), but was passing by accident just because the current behavior is not as described here. 
Comment 9 Petr Nejedly 2007-10-16 15:44:05 UTC
Fixed in:
core/src/org/netbeans/core/filesystems/MIMEResolverImpl.java,v1.29
core/test/unit/src/org/netbeans/core/filesystems/MIMEResolverImplTest.java,v1.14
core/test/unit/src/org/netbeans/core/filesystems/code-fs.xml,v1.4
core/test/unit/src/org/netbeans/core/filesystems/data-fs.xml,v1.4

A small test added to verify the AND behavior between different rule kinds.