https://bz.apache.org/bugzilla/show_bug.cgi?id=66522
Bug ID: 66522 Summary: Ant Task ReplaceRegExp alters file permissions Product: Ant Version: unspecified Hardware: PC OS: Linux Status: NEW Severity: normal Priority: P2 Component: Core tasks Assignee: notifications@ant.apache.org Reporter: thomas.starlin...@clarivate.com Target Milestone: --- Ant Task ReplaceRegExp creates a temp file and overwrites the target with this temp file. During this operation the targets file permissions are overwritten by the temp file permissions. ReplaceRegExp uses org.apache.tools.ant.util.FileUtils to create the temp file in the first place. This behaviour was introduced by https://github.com/apache/ant/commit/a8645a151bc706259fb1789ef587d05482d98612 in version 1.10.8. The following minimal ant build.xml illustrates this: -------------8<-------------8<-------------8<------------- <project name="MyProject" default="init" basedir="."> <target name="init"> <!-- Create the time stamp --> <tstamp/> <!-- Create the build directory structure used by compile --> <tempfile property="temp.file"/> <exec executable="ls"><arg value="-l"/><arg value="${temp.file}"/></exec> <echo message="temp.file = ${temp.file}"/> <echo message="temp.file = ${temp.file}" file="${temp.file}"/> <exec executable="umask"/> <exec executable="ls"><arg value="-l"/><arg value="${temp.file}"/></exec> <replaceregexp file="${temp.file}" preserveLastModified="true" byline="true" encoding="ISO-8859-1" match="temp.file" replace="sch...." /> <exec executable="ls"><arg value="-l"/><arg value="${temp.file}"/></exec> <delete file="${temp.file}"/> </target> </project> -------------8<-------------8<-------------8<------------- Output: -------------8<-------------8<-------------8<------------- test]$ ./apache-ant-1.10.13/bin/ant -Dant.tmpdir=`pwd` -v -f x.xml Apache Ant(TM) version 1.10.13 compiled on January 4 2023 Buildfile: /tmp/test/x.xml Detected Java version: 17 in: /home/tcipms/uny_home/jdk17.0.6 Detected OS: Linux parsing buildfile /tmp/test/x.xml with URI = file:/tmp/test/x.xml Project base dir set to: /tmp/test Build sequence for target(s) `init' is [init] Complete build sequence is [init, ] init: parsing buildfile jar:file:/tmp/test/apache-ant-1.10.13/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/tmp/test/apache-ant-1.10.13/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file [echo] temp.file = /tmp/test/null1446571442 [exec] Current OS is Linux [exec] Executing 'umask' [exec] The ' characters around the executable and arguments are [exec] not part of the command. [exec] 0000 [exec] Current OS is Linux [exec] Executing 'ls' with arguments: [exec] '-l' [exec] '/tmp/test/null1446571442' [exec] [exec] The ' characters around the executable and arguments are [exec] not part of the command. [exec] -rw-rw-rw-. 1 unycom unycom 36 Mar 8 17:18 /tmp/test/null1446571442 [replaceregexp] Replacing pattern 'temp.file' with 'sch....' in '/tmp/test/null1446571442' by line. [replaceregexp] File has changed; saving the updated file [exec] Current OS is Linux [exec] Executing 'ls' with arguments: [exec] '-l' [exec] '/tmp/test/null1446571442' [exec] [exec] The ' characters around the executable and arguments are [exec] not part of the command. [exec] -rw-------. 1 unycom unycom 34 Mar 8 17:18 /tmp/test/null1446571442 [delete] Deleting: /tmp/test/null1446571442 BUILD SUCCESSFUL Total time: 0 seconds -------------8<-------------8<-------------8<------------- The problem most probably arises due to the fact that the temp files FileAttribute parameters are hard coded to "rw" (https://github.com/apache/ant/blame/rel/1.10.8/src/main/org/apache/tools/ant/util/FileUtils.java#L108). Since it seems to be possible to gather FileAttributes for the parent directory (https://github.com/apache/ant/blame/rel/1.10.8/src/main/org/apache/tools/ant/util/FileUtils.java#L1012) it should also be possible to derive file permissions from the target file and set them accordingly. -- You are receiving this mail because: You are the assignee for the bug.