Bug 56619 - Allow specifying file mode in <fileset> so that <tar> can use it through resource collections
Summary: Allow specifying file mode in <fileset> so that <tar> can use it through reso...
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Ant Notifications List
Depends on:
Reported: 2014-06-13 05:33 UTC by Trejkaz (pen name)
Modified: 2014-06-22 09:33 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Trejkaz (pen name) 2014-06-13 05:33:53 UTC
When tarring up files which are already all in the right location, we can use <tarfileset filemode="755"> to make certain parts executable.

    <tar destfile="${tar.name}" compression="bzip2">
        <tarfileset dir="${dir}" filemode="755">
            <patternset refid="executable-files"/>
        <tarfileset dir="${dir}" >
            <patternset refid="non-executable-files"/>

However, having to copy all the files into one location just to tar them again adds noticeable build time (the tar file is about 200 MB) so in cases where executable flags don't matter, we do something like this:

    <union id="included.files.common">
        <fileset dir="${our.jars.dir}" includes="*.jar"/>
    <union id="included.files.app">
        <fileset dir="src/app-base" includes="bin/*"/>

    <tar destfile="${tar.name}" compression="bzip2">
                <resources refid="included.files.common"/>
                <resources refid="included.files.app"/>
            <globmapper from="*" to="${base-name}-${product.fullversion}/*"/>

I would like to be able to combine the two approaches, so that I can keep the reuse and copy-avoiding benefits of using resource collections but also keep the ability top put specific permissions on the files.

One way to do this would be to add the filemode attribute to <fileset/>, something like this:

    <union id="included.files.common">
        <fileset dir="${our.jars.dir}" includes="*.jar" filemode="755"/>

The implementation would go something like this:

   1. Move getMode() from ArchiveResource up to Resource.
   2. Implement getMode() in any subclasses like FileResource. Some other
      subclasses might also make sense to add this information to.
   3. In any tasks casting to ArchiveResource, weaken the cast.

Then any file modes at the lower levels of the resource collections would just propagate upwards and automatically work.
Comment 1 Stefan Bodewig 2014-06-22 09:33:14 UTC
with the changes you propose we wouldn't necessarily need to add mode to fileset as you could still use zio/tarfileset to add the mode.  In fact I think you'd probably even keep the mode through union (casting up to ArchiveResource) right now if you used tarfilesets to build up your union.  The point where you lose mode information is when mappedresources comes into the mix.

In addition to the changes you propose we'd also need to modify ResourceDecorator so the mode doesn't get lost.

If you look into the implementation of <tar> you'll see it also has TarFileSet hardcoded when it comes to overriding the mode of resources - <zip> and the compress antlib do better here, but they still special cases ArchiveFileSet.  In the end you'll probably want to add dir/filemode to ResourceCollection as well.