replaceregexp task overrides the file permissions

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

replaceregexp task overrides the file permissions

forumUsr
Hello

In my ant build file:

Copy original installation folder to newer path ( I like to preserve the
permissions of the files during copy ):

<if>
<isset property="os.windows" />
<then>
<copy todir="${fnd0_XX.installationPath}/Test">
<fileset dir="${fnd0_XX.installationPath_old}/Test"/>
</copy>
</then>
<else>
<exec executable="cp">
<arg line="-p -R ${fnd0_XX.installationPath_old}/Test
${fnd0_XX.installationPath}"/>
</exec>
</else>
</if>


Find and replace string that have older path with the newer path in all the
files of the directory ( if needed recursively ) :

<replaceregexp match="${fnd0_XX.installationPath_old}/Test"
replace="${fnd0_XX.installationPath}/Test" flags="g" byline="true">
<fileset dir="${fnd0_XX.installationPath}/Test"/>
</replaceregexp>


After replacement, replaceregexp task overrode the permissions.

I found below article that mentions this behavior as well:
https://hmemcpy.com/2014/06/when-good-permissions-gone-bada-case-of-a-failed-build/


Is there an ANT task that I can use that will replace and retain the
permissions of the file ? I would like this behavior to be uniform on all
platforms.

Thanks..
Reply | Threaded
Open this post in threaded view
|

Re: replaceregexp task overrides the file permissions

Stefan Bodewig

> After replacement, replaceregexp task overrode the permissions.

It does, as do <copy> or <fixcrlf> or any other task where Ant creates a
file by itself.

Historically this all stems from Java not providing access to
permissions of files or directories at all. Neither reading permissions
nor writing them. This has changed with Java 7 and thus we could adapt
the tasks for Ant 1.10.x (which requires Java 8+) but we haven't done
so.

One reason for this is the Java API is a pain to work with, in
particular if you want to make it work cross platform. I even doubt Java
is able to properly capture and restore "permissions" on Windows - or
anything else that goes beyond POSIX user/group/other read/write/execute
combinations - at all.

Many words to say, there isn't anything in Ant that will help you
preserving the permissions. Technically this would be possible now and
it would be a valid enhancement - even if it just worked for Unix-likes.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]