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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 6b2d98a97dec CAMEL-24835: a file consumer on the current directory 
(file:. or file:./) delivers its files (#26614)
6b2d98a97dec is described below

commit 6b2d98a97decf3ef46dfb3b1b5bdbca2098df619
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Sep 19 15:37:55 2026 +0200

    CAMEL-24835: a file consumer on the current directory (file:. or file:./) 
delivers its files (#26614)
    
    java.io.File.isHidden is true for "." because the name starts with a dot, 
so the consumer treated the current directory as a hidden one and listed 
nothing, silently. The current and parent directories are not hidden. Found by 
a local model in the round-2 benchmark on the camel-jbang-examples ladder.
---
 .../apache/camel/component/file/FileConsumer.java  | 15 +++-
 .../component/file/FileConsumeCurrentDirTest.java  | 81 ++++++++++++++++++++++
 2 files changed, 95 insertions(+), 1 deletion(-)

diff --git 
a/components/camel-file/src/main/java/org/apache/camel/component/file/FileConsumer.java
 
b/components/camel-file/src/main/java/org/apache/camel/component/file/FileConsumer.java
index 3b4505720fcf..80131f51cae7 100644
--- 
a/components/camel-file/src/main/java/org/apache/camel/component/file/FileConsumer.java
+++ 
b/components/camel-file/src/main/java/org/apache/camel/component/file/FileConsumer.java
@@ -214,7 +214,7 @@ public class FileConsumer extends GenericFileConsumer<File> 
implements ResumeAwa
     }
 
     private File[] listFiles(File directory) {
-        if (!getEndpoint().isIncludeHiddenDirs() && directory.isHidden()) {
+        if (!getEndpoint().isIncludeHiddenDirs() && 
isHiddenDirectory(directory)) {
             return null;
         }
         final File[] dirFiles = directory.listFiles();
@@ -379,6 +379,19 @@ public class FileConsumer extends 
GenericFileConsumer<File> implements ResumeAwa
         return (FileEndpoint) super.getEndpoint();
     }
 
+    /**
+     * Whether the directory is hidden: java.io.File.isHidden only looks at 
whether the name starts with a dot, so the
+     * current directory (file:. or file:./) and the parent directory (..) 
would count as hidden and the consumer would
+     * never deliver a file from them (CAMEL-24835).
+     */
+    private static boolean isHiddenDirectory(File directory) {
+        String name = directory.getName();
+        if (name.isEmpty() || ".".equals(name) || "..".equals(name)) {
+            return false;
+        }
+        return directory.isHidden();
+    }
+
     @Override
     protected boolean isMatchedHiddenFile(Supplier<GenericFile<File>> file, 
String name, boolean isDirectory) {
         if (isDirectory) {
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeCurrentDirTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeCurrentDirTest.java
new file mode 100644
index 000000000000..bdb43046be4f
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeCurrentDirTest.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.UUID;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * A consumer on the current directory (file:.) delivers its files: 
java.io.File.isHidden is true for "." because the
+ * name starts with a dot, which must not make the directory a hidden one 
(CAMEL-24835).
+ */
+public class FileConsumeCurrentDirTest extends ContextTestSupport {
+
+    private static final String TEST_FILE_NAME = "current-dir-" + 
UUID.randomUUID() + ".txt";
+    private final Path file = Path.of(TEST_FILE_NAME);
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @AfterEach
+    public void deleteFile() throws Exception {
+        Files.deleteIfExists(file);
+    }
+
+    @Test
+    public void testConsumeCurrentDir() throws Exception {
+        Files.writeString(file, "Report 123");
+
+        context.addRoutes(new RouteBuilder() {
+            public void configure() {
+                from("file:.?initialDelay=0&delay=10&noop=true&include=" + 
TEST_FILE_NAME)
+                        .convertBodyTo(String.class).to("mock:result");
+            }
+        });
+        context.start();
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Report 123");
+        mock.assertIsSatisfied();
+    }
+
+    @Test
+    public void testConsumeCurrentDirWithSlash() throws Exception {
+        Files.writeString(file, "Report 456");
+
+        context.addRoutes(new RouteBuilder() {
+            public void configure() {
+                from("file:./?initialDelay=0&delay=10&noop=true&include=" + 
TEST_FILE_NAME)
+                        .convertBodyTo(String.class).to("mock:result");
+            }
+        });
+        context.start();
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Report 456");
+        mock.assertIsSatisfied();
+    }
+}

Reply via email to