You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ms...@apache.org on 2026/08/11 22:24:52 UTC

(lucene) branch branch_10x updated: FilterDirectory should delegate copyFrom() to wrapped directory (#16173)

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

msfroh pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/branch_10x by this push:
     new 148ee2fd742 FilterDirectory should delegate copyFrom() to wrapped directory (#16173)
148ee2fd742 is described below

commit 148ee2fd742985e08b7bc8c0b089be34e643ff41
Author: Prithvi S <pr...@gmail.com>
AuthorDate: Wed Aug 12 03:44:23 2026 +0530

    FilterDirectory should delegate copyFrom() to wrapped directory (#16173)
---
 lucene/CHANGES.txt                                 |  2 ++
 .../org/apache/lucene/store/FilterDirectory.java   |  6 +++++
 .../apache/lucene/store/TestFilterDirectory.java   | 29 +++++++++++++++++++---
 3 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 0d0b58d1bde..87bfe1c83d4 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -154,6 +154,8 @@ Bug Fixes
   exceptional exits, so vector inputs switch back from sequential read advice.
   (Simon Cooper, John Maurice)
 
+* GITHUB#16173: FilterDirectory now delegates copyFrom() to the wrapped directory. (Prithvi S)
+
 Other
 ---------------------
 * GITHUB#16266: Remove deprecated search(Query, Collector) calls in QueryUtils by replacing
diff --git a/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java
index 43185a54f45..70c734f8eae 100644
--- a/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java
@@ -116,6 +116,12 @@ public abstract class FilterDirectory extends Directory {
     return getClass().getSimpleName() + "(" + in.toString() + ")";
   }
 
+  @Override
+  public void copyFrom(Directory from, String src, String dest, IOContext context)
+      throws IOException {
+    in.copyFrom(from, src, dest, context);
+  }
+
   @Override
   public Set<String> getPendingDeletions() throws IOException {
     return in.getPendingDeletions();
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java
index 6109115c885..397d6c325a7 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java
@@ -36,9 +36,6 @@ public class TestFilterDirectory extends BaseDirectoryTestCase {
     // verify that all methods of Directory are overridden by FilterDirectory,
     // except those under the 'exclude' list
     Set<Method> exclude = new HashSet<>();
-    exclude.add(
-        Directory.class.getMethod(
-            "copyFrom", Directory.class, String.class, String.class, IOContext.class));
     exclude.add(Directory.class.getMethod("openChecksumInput", String.class));
     for (Method m : FilterDirectory.class.getMethods()) {
       if (m.getDeclaringClass() == Directory.class) {
@@ -47,6 +44,32 @@ public class TestFilterDirectory extends BaseDirectoryTestCase {
     }
   }
 
+  public void testCopyFromDelegates() throws IOException {
+    try (Directory srcDir = new ByteBuffersDirectory();
+        Directory destDir = new ByteBuffersDirectory()) {
+      try (IndexOutput out = srcDir.createOutput("test.txt", IOContext.DEFAULT)) {
+        out.writeString("hello");
+      }
+      boolean[] delegated = {false};
+      FilterDirectory wrappedDestDir =
+          new FilterDirectory(destDir) {
+            @Override
+            public void copyFrom(Directory from, String src, String dest, IOContext context)
+                throws IOException {
+              delegated[0] = true;
+              in.copyFrom(from, src, dest, context);
+            }
+          };
+      FilterDirectory filterDestDir = new FilterDirectory(wrappedDestDir) {};
+      filterDestDir.copyFrom(srcDir, "test.txt", "copied.txt", IOContext.DEFAULT);
+      assertTrue("copyFrom should delegate to wrapped directory", delegated[0]);
+      assertTrue(slowFileExists(destDir, "copied.txt"));
+      try (IndexInput in = destDir.openInput("copied.txt", IOContext.DEFAULT)) {
+        assertEquals("hello", in.readString());
+      }
+    }
+  }
+
   public void testUnwrap() throws IOException {
     Directory dir = FSDirectory.open(createTempDir());
     FilterDirectory dir2 = new FilterDirectory(dir) {};