You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by ja...@apache.org on 2025/07/01 16:17:21 UTC

(ant) branch master updated (6a37d4724 -> fe3727ee4)

This is an automated email from the ASF dual-hosted git repository.

jaikiran pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git


    from 6a37d4724 explicitly explain the use of nested text in concat.
     new 54350f7e9 antunit-tests - mark files as writable before attempting to delete in our antunit tests' tearDown()
     new fe3727ee4 FileUtils.tryHardToDelete() - On Windows, mark the file writable if it's read-only, before retrying File.delete()

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/main/org/apache/tools/ant/util/FileUtils.java |  5 +++++
 src/tests/antunit/antunit-base.xml                | 18 +++++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)


(ant) 01/02: antunit-tests - mark files as writable before attempting to delete in our antunit tests' tearDown()

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jaikiran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git

commit 54350f7e967f965169a07f65ec925b621cef231d
Author: Jaikiran Pai <ja...@apache.org>
AuthorDate: Tue Jul 1 18:45:20 2025 +0530

    antunit-tests - mark files as writable before attempting to delete in our antunit tests' tearDown()
    
    Some of these antunit tests used to create read-only files and then tearDown() would delete the files and the directories containing them.
    Starting Java 25, after https://bugs.openjdk.org/browse/JDK-8355954 bug fix, read-only files on Windows cannot be deleted.
    The tearDown() method in these tests has now been updated to reset the permission on these test generated files to writable before deleting them.
---
 src/tests/antunit/antunit-base.xml | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/tests/antunit/antunit-base.xml b/src/tests/antunit/antunit-base.xml
index 48226b8f6..ec7ec745d 100644
--- a/src/tests/antunit/antunit-base.xml
+++ b/src/tests/antunit/antunit-base.xml
@@ -35,7 +35,23 @@
     <equals arg1="${build.sysclasspath}" arg2="only"/>
   </condition>
 
-  <target name="tearDown">
+  <condition property="windows_os">
+    <os family="windows"/>
+  </condition>
+  <target name="markFilesWritable" if="windows_os">
+    <!--
+      some tests create read-only files in input/output directory.
+      Windows doesn't allow deleting read-only files, so we reset
+      the permissions on those files to writable before tearDown
+      can delete the input/output directory.
+    -->
+    <setpermissions mode="666" nonPosixMode="tryDosOrFail">
+      <fileset dir="${input}" erroronmissingdir="false"/>
+      <fileset dir="${output}" erroronmissingdir="false"/>
+    </setpermissions>
+  </target>
+
+  <target name="tearDown" depends="markFilesWritable">
     <delete dir="${input}"/>
     <delete dir="${output}"/>
     <delete dir="${resources}"/>


(ant) 02/02: FileUtils.tryHardToDelete() - On Windows, mark the file writable if it's read-only, before retrying File.delete()

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jaikiran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git

commit fe3727ee48b5ff89f65de52dea91c1bc757e4705
Author: Jaikiran Pai <ja...@apache.org>
AuthorDate: Tue Jul 1 19:28:59 2025 +0530

    FileUtils.tryHardToDelete() - On Windows, mark the file writable if it's read-only, before retrying File.delete()
---
 src/main/org/apache/tools/ant/util/FileUtils.java | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java
index 087ab703d..824820233 100644
--- a/src/main/org/apache/tools/ant/util/FileUtils.java
+++ b/src/main/org/apache/tools/ant/util/FileUtils.java
@@ -1754,6 +1754,11 @@ public class FileUtils {
      */
     public boolean tryHardToDelete(File f, boolean runGC) {
         if (!f.delete()) {
+            // If the file is read-only on Windows, then it cannot be deleted.
+            // We set it to writable and then retry to delete it.
+            if (!f.canWrite() && ON_WINDOWS) {
+                final boolean ignored = f.setWritable(true);
+            }
             if (runGC) {
                 System.gc();
             }