You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rz...@apache.org on 2026/10/05 17:40:16 UTC

(tomee) branch files-tmpdir-atomic updated (9df2a27d4e -> 44ce42670f)

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

rzo1 pushed a change to branch files-tmpdir-atomic
in repository https://gitbox.apache.org/repos/asf/tomee.git


 discard 9df2a27d4e create Files.tmpdir() directories atomically
     new 44ce42670f create Files.tmpdir() directories atomically

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (9df2a27d4e)
            \
             N -- N -- N   refs/heads/files-tmpdir-atomic (44ce42670f)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 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:


(tomee) 01/01: create Files.tmpdir() directories atomically

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

rzo1 pushed a commit to branch files-tmpdir-atomic
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit 44ce42670f79700f3ccdbb2df2369ce9c615201c
Author: Richard Zowalla <zo...@colorful-bytes.com>
AuthorDate: Mon Oct 5 19:30:59 2026 +0200

    create Files.tmpdir() directories atomically
    
    Use Files.createTempDirectory instead of createTempFile/delete/mkdir,
    which raced in a shared temp dir, and get owner-only permissions.
---
 .../main/java/org/apache/openejb/loader/Files.java | 12 +++-------
 .../java/org/apache/openejb/loader/FilesTest.java  | 26 +++++++++++++++++++++-
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java b/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java
index cc97b3b1ef..d045a17aab 100644
--- a/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java
+++ b/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java
@@ -192,7 +192,8 @@ public class Files {
         try {
             File file;
             try {
-                file = File.createTempFile("temp", "dir");
+                // created atomically with owner-only permissions on POSIX file systems
+                file = java.nio.file.Files.createTempDirectory("temp").toFile();
             } catch (final Throwable e) {
                 //Use a local tmp directory
                 final File tmp = new File("tmp");
@@ -203,16 +204,9 @@ public class Files {
                     throw new IOException("Failed to create local tmp directory: " + tmp.getAbsolutePath());
                 }
 
-                file = File.createTempFile("temp", "dir", tmp);
+                file = java.nio.file.Files.createTempDirectory(tmp.toPath(), "temp").toFile();
             }
 
-            hackJDK4715154();
-
-            if (!file.delete()) {
-                throw new IOException("Failed to create temp dir. Delete failed");
-            }
-
-            mkdir(file);
             deleteOnExit(file);
 
             return file;
diff --git a/container/openejb-loader/src/test/java/org/apache/openejb/loader/FilesTest.java b/container/openejb-loader/src/test/java/org/apache/openejb/loader/FilesTest.java
index daca321feb..86a11a711f 100644
--- a/container/openejb-loader/src/test/java/org/apache/openejb/loader/FilesTest.java
+++ b/container/openejb-loader/src/test/java/org/apache/openejb/loader/FilesTest.java
@@ -20,11 +20,15 @@ import org.junit.Test;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.attribute.PosixFileAttributeView;
+import java.nio.file.attribute.PosixFilePermission;
+import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertTrue;
 
 public class FilesTest {
@@ -72,4 +76,24 @@ public class FilesTest {
         final long time = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS);
         Logger.getLogger(this.getClass().getName()).log(Level.INFO, String.format("Completed File.%1$s in %2$sms" , remove ? "remove" : "delete", String.valueOf(time)));
     }
-}
\ No newline at end of file
+
+    @Test
+    public void tmpdirCreatesDistinctPrivateDirectories() throws Exception {
+        final File dir1 = Files.tmpdir();
+        final File dir2 = Files.tmpdir();
+
+        assertTrue(dir1.isDirectory());
+        assertTrue(dir2.isDirectory());
+        assertNotEquals(dir1.getAbsoluteFile(), dir2.getAbsoluteFile());
+
+        for (final File dir : new File[]{dir1, dir2}) {
+            if (java.nio.file.Files.getFileStore(dir.toPath()).supportsFileAttributeView(PosixFileAttributeView.class)) {
+                final Set<PosixFilePermission> permissions = java.nio.file.Files.getPosixFilePermissions(dir.toPath());
+                for (final PosixFilePermission permission : permissions) {
+                    assertFalse("tmpdir must be owner-only but has " + permission,
+                            permission.name().startsWith("GROUP_") || permission.name().startsWith("OTHERS_"));
+                }
+            }
+        }
+    }
+}