You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by vy...@apache.org on 2020/06/17 08:27:50 UTC

[logging-log4j2] branch LOG4J2-2828 updated (52696e7 -> cbf7acb)

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

vy pushed a change to branch LOG4J2-2828
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git.


 discard 52696e7  LOG4J2-2828 Retain file permissions after rollover in RollingRandomAccessFileAppender.
     new cbf7acb  LOG4J2-2828 Retain file permissions after rollover in RollingRandomAccessFileAppender.

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   (52696e7)
            \
             N -- N -- N   refs/heads/LOG4J2-2828 (cbf7acb)

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:
 .../RollingRandomAccessFileManagerTest.java        | 31 ++++++++++++----------
 1 file changed, 17 insertions(+), 14 deletions(-)


[logging-log4j2] 01/01: LOG4J2-2828 Retain file permissions after rollover in RollingRandomAccessFileAppender.

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

vy pushed a commit to branch LOG4J2-2828
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit cbf7acb2cead757fcabc0a4253f8199f1c2284b1
Author: Volkan Yazıcı <vo...@gmail.com>
AuthorDate: Wed Jun 17 10:25:14 2020 +0200

    LOG4J2-2828 Retain file permissions after rollover in RollingRandomAccessFileAppender.
---
 .../rolling/RollingRandomAccessFileManager.java    |  4 +
 .../RollingRandomAccessFileManagerTest.java        | 92 +++++++++++++++++++---
 2 files changed, 84 insertions(+), 12 deletions(-)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
index ad7df84..7f7bf85 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
@@ -22,6 +22,7 @@ import java.io.OutputStream;
 import java.io.RandomAccessFile;
 import java.io.Serializable;
 import java.nio.ByteBuffer;
+import java.nio.file.Paths;
 
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LoggerContext;
@@ -140,6 +141,9 @@ public class RollingRandomAccessFileManager extends RollingFileManager {
 
     private void createFileAfterRollover(String fileName) throws IOException {
         this.randomAccessFile = new RandomAccessFile(fileName, "rw");
+        if (isAttributeViewEnabled()) {
+            defineAttributeView(Paths.get(fileName));
+        }
         if (isAppend()) {
             randomAccessFile.seek(randomAccessFile.length());
         }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java
index 8f7f717..b365322 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java
@@ -17,6 +17,26 @@
 
 package org.apache.logging.log4j.core.appender.rolling;
 
+import org.apache.logging.log4j.core.config.DefaultConfiguration;
+import org.apache.logging.log4j.core.util.Closer;
+import org.apache.logging.log4j.core.util.FileUtils;
+import org.apache.logging.log4j.core.util.NullOutputStream;
+import org.apache.logging.log4j.util.Strings;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.RandomAccessFile;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.attribute.PosixFileAttributeView;
+import java.nio.file.attribute.PosixFilePermission;
+import java.nio.file.attribute.PosixFilePermissions;
+import java.util.Set;
+import java.util.concurrent.locks.LockSupport;
+
 import static org.apache.logging.log4j.hamcrest.FileMatchers.beforeNow;
 import static org.apache.logging.log4j.hamcrest.FileMatchers.hasLength;
 import static org.apache.logging.log4j.hamcrest.FileMatchers.isEmpty;
@@ -25,21 +45,10 @@ import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.lessThanOrEqualTo;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.RandomAccessFile;
-import java.util.concurrent.locks.LockSupport;
-
-import org.apache.logging.log4j.core.util.Closer;
-import org.apache.logging.log4j.core.util.NullOutputStream;
-import org.apache.logging.log4j.util.Strings;
-import org.junit.Test;
-
 /**
  * Tests the RollingRandomAccessFileManager class.
  */
@@ -198,4 +207,63 @@ public class RollingRandomAccessFileManagerTest {
         assertThat(file, lastModified(equalTo(manager.getFileTime())));
     }
 
+    @Test
+    public void testRolloverRetainsFileAttributes() throws Exception {
+
+        // Short-circuit if host doesn't support file attributes.
+        if (!FileUtils.isFilePosixAttributeViewSupported()) {
+            return;
+        }
+
+        // Create the initial file.
+        final File file = File.createTempFile("log4j2", "test");
+        LockSupport.parkNanos(1000000); // 1 millisec
+
+        // Set the initial file attributes.
+        final String filePermissionsString = "rwxrwxrwx";
+        final Set<PosixFilePermission> filePermissions =
+                PosixFilePermissions.fromString(filePermissionsString);
+        FileUtils.defineFilePosixAttributeView(file.toPath(), filePermissions, null, null);
+
+        // Create the manager.
+        final RolloverStrategy rolloverStrategy = DefaultRolloverStrategy
+                .newBuilder()
+                .setMax("7")
+                .setMin("1")
+                .setFileIndex("max")
+                .setStopCustomActionsOnError(false)
+                .setConfig(new DefaultConfiguration())
+                .build();
+        final RollingRandomAccessFileManager manager =
+                RollingRandomAccessFileManager.getRollingRandomAccessFileManager(
+                        file.getAbsolutePath(),
+                        Strings.EMPTY,
+                        true,
+                        true,
+                        RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE,
+                        new SizeBasedTriggeringPolicy(Long.MAX_VALUE),
+                        rolloverStrategy,
+                        null,
+                        null,
+                        filePermissionsString,
+                        null,
+                        null,
+                        null);
+        assertNotNull(manager);
+        manager.initialize();
+
+        // Trigger a rollover.
+        manager.rollover();
+
+        // Verify the rolled over file attributes.
+        final Set<PosixFilePermission> actualFilePermissions = Files
+                .getFileAttributeView(
+                        Paths.get(manager.getFileName()),
+                        PosixFileAttributeView.class)
+                .readAttributes()
+                .permissions();
+        assertEquals(filePermissions, actualFilePermissions);
+
+    }
+
 }