mirror of https://github.com/apache/lucene.git
LUCENE-10526: add single method to mockfile to wrap a Path (#822)
Currently "new FilterPath" is called from everywhere, making it impossible for a mockfilesystem to use a custom subclass. Add FilterFileSystemProvider.wrapPath(path), which subclasses can override. Fix tests to use it instead of juggling URI objects and passing FileSystems around.
This commit is contained in:
parent
ec53a72a44
commit
844bd88839
|
@ -147,7 +147,8 @@ Build
|
||||||
|
|
||||||
Other
|
Other
|
||||||
---------------------
|
---------------------
|
||||||
(No changes)
|
* LUCENE-10526: Test-framework: Add FilterFileSystemProvider.wrapPath(Path) method for mock filesystems
|
||||||
|
to override if they need to extend the Path implementation. (Gautam Worah, Robert Muir)
|
||||||
|
|
||||||
======================= Lucene 9.1.0 =======================
|
======================= Lucene 9.1.0 =======================
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,6 @@ import java.io.PrintStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.NoSuchFileException;
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -100,7 +98,6 @@ import org.apache.lucene.tests.analysis.Token;
|
||||||
import org.apache.lucene.tests.index.RandomIndexWriter;
|
import org.apache.lucene.tests.index.RandomIndexWriter;
|
||||||
import org.apache.lucene.tests.index.SuppressingConcurrentMergeScheduler;
|
import org.apache.lucene.tests.index.SuppressingConcurrentMergeScheduler;
|
||||||
import org.apache.lucene.tests.mockfile.ExtrasFS;
|
import org.apache.lucene.tests.mockfile.ExtrasFS;
|
||||||
import org.apache.lucene.tests.mockfile.FilterPath;
|
|
||||||
import org.apache.lucene.tests.mockfile.WindowsFS;
|
import org.apache.lucene.tests.mockfile.WindowsFS;
|
||||||
import org.apache.lucene.tests.store.BaseDirectoryWrapper;
|
import org.apache.lucene.tests.store.BaseDirectoryWrapper;
|
||||||
import org.apache.lucene.tests.store.MockDirectoryWrapper;
|
import org.apache.lucene.tests.store.MockDirectoryWrapper;
|
||||||
|
@ -1272,8 +1269,8 @@ public class TestIndexWriter extends LuceneTestCase {
|
||||||
for (int iter = 0; iter < 2; iter++) {
|
for (int iter = 0; iter < 2; iter++) {
|
||||||
// relies on windows semantics
|
// relies on windows semantics
|
||||||
Path path = createTempDir();
|
Path path = createTempDir();
|
||||||
FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
|
WindowsFS provider = new WindowsFS(path.getFileSystem());
|
||||||
Path indexPath = new FilterPath(path, fs);
|
Path indexPath = provider.wrapPath(path);
|
||||||
|
|
||||||
// NOTE: on Unix, we cannot use MMapDir, because WindowsFS doesn't see/think it keeps file
|
// NOTE: on Unix, we cannot use MMapDir, because WindowsFS doesn't see/think it keeps file
|
||||||
// handles open. Yet, on Windows, we MUST use
|
// handles open. Yet, on Windows, we MUST use
|
||||||
|
@ -2807,8 +2804,8 @@ public class TestIndexWriter extends LuceneTestCase {
|
||||||
Path path = createTempDir();
|
Path path = createTempDir();
|
||||||
|
|
||||||
// Use WindowsFS to prevent open files from being deleted:
|
// Use WindowsFS to prevent open files from being deleted:
|
||||||
FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
|
WindowsFS provider = new WindowsFS(path.getFileSystem());
|
||||||
Path root = new FilterPath(path, fs);
|
Path root = provider.wrapPath(path);
|
||||||
|
|
||||||
// MMapDirectory doesn't work because it closes its file handles after mapping!
|
// MMapDirectory doesn't work because it closes its file handles after mapping!
|
||||||
List<Closeable> toClose = new ArrayList<>();
|
List<Closeable> toClose = new ArrayList<>();
|
||||||
|
@ -2879,8 +2876,8 @@ public class TestIndexWriter extends LuceneTestCase {
|
||||||
Path path = createTempDir();
|
Path path = createTempDir();
|
||||||
|
|
||||||
// Use WindowsFS to prevent open files from being deleted:
|
// Use WindowsFS to prevent open files from being deleted:
|
||||||
FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
|
WindowsFS provider = new WindowsFS(path.getFileSystem());
|
||||||
Path root = new FilterPath(path, fs);
|
Path root = provider.wrapPath(path);
|
||||||
try (FSDirectory _dir = new NIOFSDirectory(root)) {
|
try (FSDirectory _dir = new NIOFSDirectory(root)) {
|
||||||
Directory dir = new FilterDirectory(_dir) {};
|
Directory dir = new FilterDirectory(_dir) {};
|
||||||
|
|
||||||
|
@ -2918,8 +2915,8 @@ public class TestIndexWriter extends LuceneTestCase {
|
||||||
Path path = createTempDir();
|
Path path = createTempDir();
|
||||||
|
|
||||||
// Use WindowsFS to prevent open files from being deleted:
|
// Use WindowsFS to prevent open files from being deleted:
|
||||||
FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
|
WindowsFS provider = new WindowsFS(path.getFileSystem());
|
||||||
Path root = new FilterPath(path, fs);
|
Path root = provider.wrapPath(path);
|
||||||
IndexCommit indexCommit;
|
IndexCommit indexCommit;
|
||||||
DirectoryReader reader;
|
DirectoryReader reader;
|
||||||
// MMapDirectory doesn't work because it closes its file handles after mapping!
|
// MMapDirectory doesn't work because it closes its file handles after mapping!
|
||||||
|
@ -2973,8 +2970,8 @@ public class TestIndexWriter extends LuceneTestCase {
|
||||||
assumeFalse("windows is not supported", Constants.WINDOWS);
|
assumeFalse("windows is not supported", Constants.WINDOWS);
|
||||||
|
|
||||||
// Use WindowsFS to prevent open files from being deleted:
|
// Use WindowsFS to prevent open files from being deleted:
|
||||||
FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
|
WindowsFS provider = new WindowsFS(path.getFileSystem());
|
||||||
Path root = new FilterPath(path, fs);
|
Path root = provider.wrapPath(path);
|
||||||
// MMapDirectory doesn't work because it closes its file handles after mapping!
|
// MMapDirectory doesn't work because it closes its file handles after mapping!
|
||||||
try (FSDirectory dir = new NIOFSDirectory(root)) {
|
try (FSDirectory dir = new NIOFSDirectory(root)) {
|
||||||
IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
|
IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
|
||||||
|
|
|
@ -17,9 +17,7 @@
|
||||||
package org.apache.lucene.store;
|
package org.apache.lucene.store;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.file.AtomicMoveNotSupportedException;
|
import java.nio.file.AtomicMoveNotSupportedException;
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -34,7 +32,6 @@ import org.apache.lucene.index.IndexWriter;
|
||||||
import org.apache.lucene.index.IndexWriterConfig;
|
import org.apache.lucene.index.IndexWriterConfig;
|
||||||
import org.apache.lucene.index.TestIndexWriterReader;
|
import org.apache.lucene.index.TestIndexWriterReader;
|
||||||
import org.apache.lucene.tests.analysis.MockAnalyzer;
|
import org.apache.lucene.tests.analysis.MockAnalyzer;
|
||||||
import org.apache.lucene.tests.mockfile.FilterPath;
|
|
||||||
import org.apache.lucene.tests.mockfile.WindowsFS;
|
import org.apache.lucene.tests.mockfile.WindowsFS;
|
||||||
import org.apache.lucene.tests.store.BaseDirectoryTestCase;
|
import org.apache.lucene.tests.store.BaseDirectoryTestCase;
|
||||||
import org.apache.lucene.tests.store.MockDirectoryWrapper;
|
import org.apache.lucene.tests.store.MockDirectoryWrapper;
|
||||||
|
@ -180,8 +177,8 @@ public class TestFileSwitchDirectory extends BaseDirectoryTestCase {
|
||||||
// relies on windows semantics
|
// relies on windows semantics
|
||||||
Path path = createTempDir();
|
Path path = createTempDir();
|
||||||
assumeFalse("Irony we seem to not emulate windows well enough", Constants.WINDOWS);
|
assumeFalse("Irony we seem to not emulate windows well enough", Constants.WINDOWS);
|
||||||
FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
|
WindowsFS provider = new WindowsFS(path.getFileSystem());
|
||||||
Path indexPath = new FilterPath(path, fs);
|
Path indexPath = provider.wrapPath(path);
|
||||||
try (final FileSwitchDirectory dir =
|
try (final FileSwitchDirectory dir =
|
||||||
new FileSwitchDirectory(
|
new FileSwitchDirectory(
|
||||||
Collections.singleton("tim"),
|
Collections.singleton("tim"),
|
||||||
|
|
|
@ -17,15 +17,12 @@
|
||||||
package org.apache.lucene.store;
|
package org.apache.lucene.store;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.OpenOption;
|
import java.nio.file.OpenOption;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.attribute.FileAttribute;
|
import java.nio.file.attribute.FileAttribute;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.apache.lucene.tests.mockfile.FilterFileChannel;
|
import org.apache.lucene.tests.mockfile.FilterFileChannel;
|
||||||
import org.apache.lucene.tests.mockfile.FilterPath;
|
|
||||||
import org.apache.lucene.tests.mockfile.LeakFS;
|
import org.apache.lucene.tests.mockfile.LeakFS;
|
||||||
import org.apache.lucene.tests.store.BaseDirectoryTestCase;
|
import org.apache.lucene.tests.store.BaseDirectoryTestCase;
|
||||||
|
|
||||||
|
@ -53,8 +50,7 @@ public class TestNIOFSDirectory extends BaseDirectoryTestCase {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
FileSystem fs = leakFS.getFileSystem(URI.create("file:///"));
|
Path wrapped = leakFS.wrapPath(path);
|
||||||
Path wrapped = new FilterPath(path, fs);
|
|
||||||
try (Directory dir = new NIOFSDirectory(wrapped)) {
|
try (Directory dir = new NIOFSDirectory(wrapped)) {
|
||||||
try (IndexOutput out = dir.createOutput("test.bin", IOContext.DEFAULT)) {
|
try (IndexOutput out = dir.createOutput("test.bin", IOContext.DEFAULT)) {
|
||||||
out.writeString("hello");
|
out.writeString("hello");
|
||||||
|
|
|
@ -18,7 +18,6 @@ package org.apache.lucene.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.AccessDeniedException;
|
import java.nio.file.AccessDeniedException;
|
||||||
|
@ -125,10 +124,9 @@ public class TestIOUtils extends LuceneTestCase {
|
||||||
|
|
||||||
public void testFsyncAccessDeniedOpeningDirectory() throws Exception {
|
public void testFsyncAccessDeniedOpeningDirectory() throws Exception {
|
||||||
final Path path = createTempDir().toRealPath();
|
final Path path = createTempDir().toRealPath();
|
||||||
final FileSystem fs =
|
final FilterFileSystemProvider provider =
|
||||||
new AccessDeniedWhileOpeningDirectoryFileSystem(path.getFileSystem())
|
new AccessDeniedWhileOpeningDirectoryFileSystem(path.getFileSystem());
|
||||||
.getFileSystem(URI.create("file:///"));
|
final Path wrapped = provider.wrapPath(path);
|
||||||
final Path wrapped = new FilterPath(path, fs);
|
|
||||||
if (Constants.WINDOWS) {
|
if (Constants.WINDOWS) {
|
||||||
// no exception, we early return and do not even try to open the directory
|
// no exception, we early return and do not even try to open the directory
|
||||||
IOUtils.fsync(wrapped, true);
|
IOUtils.fsync(wrapped, true);
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
package org.apache.lucene.misc.store;
|
package org.apache.lucene.misc.store;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
@ -33,7 +31,6 @@ import org.apache.lucene.store.IOContext;
|
||||||
import org.apache.lucene.store.IndexInput;
|
import org.apache.lucene.store.IndexInput;
|
||||||
import org.apache.lucene.store.IndexOutput;
|
import org.apache.lucene.store.IndexOutput;
|
||||||
import org.apache.lucene.store.NIOFSDirectory;
|
import org.apache.lucene.store.NIOFSDirectory;
|
||||||
import org.apache.lucene.tests.mockfile.FilterPath;
|
|
||||||
import org.apache.lucene.tests.mockfile.WindowsFS;
|
import org.apache.lucene.tests.mockfile.WindowsFS;
|
||||||
import org.apache.lucene.tests.store.BaseDirectoryTestCase;
|
import org.apache.lucene.tests.store.BaseDirectoryTestCase;
|
||||||
import org.apache.lucene.util.Constants;
|
import org.apache.lucene.util.Constants;
|
||||||
|
@ -111,9 +108,9 @@ public class TestHardLinkCopyDirectoryWrapper extends BaseDirectoryTestCase {
|
||||||
// irony: currently we don't emulate windows well enough to work on windows!
|
// irony: currently we don't emulate windows well enough to work on windows!
|
||||||
assumeFalse("windows is not supported", Constants.WINDOWS);
|
assumeFalse("windows is not supported", Constants.WINDOWS);
|
||||||
Path path = createTempDir();
|
Path path = createTempDir();
|
||||||
FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
|
WindowsFS provider = new WindowsFS(path.getFileSystem());
|
||||||
Directory dir1 = new NIOFSDirectory(new FilterPath(path, fs));
|
Directory dir1 = new NIOFSDirectory(provider.wrapPath(path));
|
||||||
Directory dir2 = new NIOFSDirectory(new FilterPath(path.resolve("link"), fs));
|
Directory dir2 = new NIOFSDirectory(provider.wrapPath(path.resolve("link")));
|
||||||
|
|
||||||
IndexOutput target = dir1.createOutput("target.txt", IOContext.DEFAULT);
|
IndexOutput target = dir1.createOutput("target.txt", IOContext.DEFAULT);
|
||||||
target.writeInt(1);
|
target.writeInt(1);
|
||||||
|
|
|
@ -18,7 +18,6 @@ package org.apache.lucene.tests.mockfile;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.DirectoryStream;
|
import java.nio.file.DirectoryStream;
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -34,7 +33,7 @@ public class FilterDirectoryStream implements DirectoryStream<Path> {
|
||||||
protected final DirectoryStream<Path> delegate;
|
protected final DirectoryStream<Path> delegate;
|
||||||
|
|
||||||
/** The underlying {@code FileSystem} instance. */
|
/** The underlying {@code FileSystem} instance. */
|
||||||
protected final FileSystem fileSystem;
|
protected final FilterFileSystem fileSystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a {@code FilterDirectoryStream} based on the specified base stream.
|
* Construct a {@code FilterDirectoryStream} based on the specified base stream.
|
||||||
|
@ -43,7 +42,7 @@ public class FilterDirectoryStream implements DirectoryStream<Path> {
|
||||||
*
|
*
|
||||||
* @param delegate specified base stream.
|
* @param delegate specified base stream.
|
||||||
*/
|
*/
|
||||||
public FilterDirectoryStream(DirectoryStream<Path> delegate, FileSystem fileSystem) {
|
public FilterDirectoryStream(DirectoryStream<Path> delegate, FilterFileSystem fileSystem) {
|
||||||
this.delegate = Objects.requireNonNull(delegate);
|
this.delegate = Objects.requireNonNull(delegate);
|
||||||
this.fileSystem = Objects.requireNonNull(fileSystem);
|
this.fileSystem = Objects.requireNonNull(fileSystem);
|
||||||
}
|
}
|
||||||
|
@ -64,7 +63,7 @@ public class FilterDirectoryStream implements DirectoryStream<Path> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path next() {
|
public Path next() {
|
||||||
return new FilterPath(delegateIterator.next(), fileSystem);
|
return fileSystem.parent.wrapPath(delegateIterator.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,7 +24,6 @@ import java.nio.file.Path;
|
||||||
import java.nio.file.PathMatcher;
|
import java.nio.file.PathMatcher;
|
||||||
import java.nio.file.WatchService;
|
import java.nio.file.WatchService;
|
||||||
import java.nio.file.attribute.UserPrincipalLookupService;
|
import java.nio.file.attribute.UserPrincipalLookupService;
|
||||||
import java.nio.file.spi.FileSystemProvider;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -55,7 +54,7 @@ public class FilterFileSystem extends FileSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileSystemProvider provider() {
|
public FilterFileSystemProvider provider() {
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +99,7 @@ public class FilterFileSystem extends FileSystem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path next() {
|
public Path next() {
|
||||||
return new FilterPath(iterator.next(), FilterFileSystem.this);
|
return parent.wrapPath(iterator.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -142,7 +141,7 @@ public class FilterFileSystem extends FileSystem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path getPath(String first, String... more) {
|
public Path getPath(String first, String... more) {
|
||||||
return new FilterPath(delegate.getPath(first, more), this);
|
return parent.wrapPath(delegate.getPath(first, more));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -170,9 +169,4 @@ public class FilterFileSystem extends FileSystem {
|
||||||
public FileSystem getDelegate() {
|
public FileSystem getDelegate() {
|
||||||
return delegate;
|
return delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the {@code FilterFileSystemProvider} sent to this on init. */
|
|
||||||
public FileSystemProvider getParent() {
|
|
||||||
return parent;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ public abstract class FilterFileSystemProvider extends FileSystemProvider {
|
||||||
/** The underlying {@code FileSystemProvider}. */
|
/** The underlying {@code FileSystemProvider}. */
|
||||||
protected final FileSystemProvider delegate;
|
protected final FileSystemProvider delegate;
|
||||||
/** The underlying {@code FileSystem} instance. */
|
/** The underlying {@code FileSystem} instance. */
|
||||||
protected FileSystem fileSystem;
|
protected FilterFileSystem fileSystem;
|
||||||
/** The URI scheme for this provider. */
|
/** The URI scheme for this provider. */
|
||||||
protected final String scheme;
|
protected final String scheme;
|
||||||
|
|
||||||
|
@ -116,7 +116,11 @@ public abstract class FilterFileSystemProvider extends FileSystemProvider {
|
||||||
if (fileSystem == null) {
|
if (fileSystem == null) {
|
||||||
throw new IllegalStateException("subclass did not initialize singleton filesystem");
|
throw new IllegalStateException("subclass did not initialize singleton filesystem");
|
||||||
}
|
}
|
||||||
Path path = delegate.getPath(uri);
|
return wrapPath(delegate.getPath(uri));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** wraps a Path with provider-specific behavior */
|
||||||
|
public FilterPath wrapPath(Path path) {
|
||||||
return new FilterPath(path, fileSystem);
|
return new FilterPath(path, fileSystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +227,7 @@ public abstract class FilterFileSystemProvider extends FileSystemProvider {
|
||||||
new Filter<Path>() {
|
new Filter<Path>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(Path entry) throws IOException {
|
public boolean accept(Path entry) throws IOException {
|
||||||
return filter.accept(new FilterPath(entry, fileSystem));
|
return filter.accept(wrapPath(entry));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return new FilterDirectoryStream(
|
return new FilterDirectoryStream(
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class FilterPath implements Path, Unwrappable<Path> {
|
||||||
protected final Path delegate;
|
protected final Path delegate;
|
||||||
|
|
||||||
/** The parent {@code FileSystem} for this path. */
|
/** The parent {@code FileSystem} for this path. */
|
||||||
protected final FileSystem fileSystem;
|
protected final FilterFileSystem fileSystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a {@code FilterPath} with parent {@code fileSystem}, based on the specified base
|
* Construct a {@code FilterPath} with parent {@code fileSystem}, based on the specified base
|
||||||
|
@ -50,7 +50,7 @@ public class FilterPath implements Path, Unwrappable<Path> {
|
||||||
* @param delegate specified base path.
|
* @param delegate specified base path.
|
||||||
* @param fileSystem parent fileSystem.
|
* @param fileSystem parent fileSystem.
|
||||||
*/
|
*/
|
||||||
public FilterPath(Path delegate, FileSystem fileSystem) {
|
public FilterPath(Path delegate, FilterFileSystem fileSystem) {
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
this.fileSystem = fileSystem;
|
this.fileSystem = fileSystem;
|
||||||
}
|
}
|
||||||
|
@ -270,9 +270,8 @@ public class FilterPath implements Path, Unwrappable<Path> {
|
||||||
return Unwrappable.unwrapAll(path);
|
return Unwrappable.unwrapAll(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Override this to customize the return wrapped path from various operations */
|
private final Path wrap(Path other) {
|
||||||
protected Path wrap(Path other) {
|
return fileSystem.parent.wrapPath(other);
|
||||||
return new FilterPath(other, fileSystem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Override this to customize the unboxing of Path from various operations */
|
/** Override this to customize the unboxing of Path from various operations */
|
||||||
|
|
|
@ -293,7 +293,7 @@ public abstract class HandleTrackingFS extends FilterFileSystemProvider {
|
||||||
new Filter<Path>() {
|
new Filter<Path>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(Path entry) throws IOException {
|
public boolean accept(Path entry) throws IOException {
|
||||||
return filter.accept(new FilterPath(entry, fileSystem));
|
return filter.accept(wrapPath(entry));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
DirectoryStream<Path> stream = delegate.newDirectoryStream(toDelegate(dir), wrappedFilter);
|
DirectoryStream<Path> stream = delegate.newDirectoryStream(toDelegate(dir), wrappedFilter);
|
||||||
|
|
|
@ -61,10 +61,8 @@ import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.NoSuchFileException;
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
@ -140,7 +138,6 @@ import org.apache.lucene.tests.index.MismatchedDirectoryReader;
|
||||||
import org.apache.lucene.tests.index.MismatchedLeafReader;
|
import org.apache.lucene.tests.index.MismatchedLeafReader;
|
||||||
import org.apache.lucene.tests.index.MockIndexWriterEventListener;
|
import org.apache.lucene.tests.index.MockIndexWriterEventListener;
|
||||||
import org.apache.lucene.tests.index.MockRandomMergePolicy;
|
import org.apache.lucene.tests.index.MockRandomMergePolicy;
|
||||||
import org.apache.lucene.tests.mockfile.FilterPath;
|
|
||||||
import org.apache.lucene.tests.mockfile.VirusCheckingFS;
|
import org.apache.lucene.tests.mockfile.VirusCheckingFS;
|
||||||
import org.apache.lucene.tests.search.AssertingIndexSearcher;
|
import org.apache.lucene.tests.search.AssertingIndexSearcher;
|
||||||
import org.apache.lucene.tests.store.BaseDirectoryWrapper;
|
import org.apache.lucene.tests.store.BaseDirectoryWrapper;
|
||||||
|
@ -1398,8 +1395,7 @@ public abstract class LuceneTestCase extends Assert {
|
||||||
public static Path addVirusChecker(Path path) {
|
public static Path addVirusChecker(Path path) {
|
||||||
if (TestUtil.hasVirusChecker(path) == false) {
|
if (TestUtil.hasVirusChecker(path) == false) {
|
||||||
VirusCheckingFS fs = new VirusCheckingFS(path.getFileSystem(), random().nextLong());
|
VirusCheckingFS fs = new VirusCheckingFS(path.getFileSystem(), random().nextLong());
|
||||||
FileSystem filesystem = fs.getFileSystem(URI.create("file:///"));
|
path = fs.wrapPath(path);
|
||||||
path = new FilterPath(path, filesystem);
|
|
||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1682,7 +1682,7 @@ public final class TestUtil {
|
||||||
FileSystem fs = path.getFileSystem();
|
FileSystem fs = path.getFileSystem();
|
||||||
while (fs instanceof FilterFileSystem) {
|
while (fs instanceof FilterFileSystem) {
|
||||||
FilterFileSystem ffs = (FilterFileSystem) fs;
|
FilterFileSystem ffs = (FilterFileSystem) fs;
|
||||||
if (ffs.getParent() instanceof WindowsFS) {
|
if (ffs.provider() instanceof WindowsFS) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
fs = ffs.getDelegate();
|
fs = ffs.getDelegate();
|
||||||
|
@ -1696,7 +1696,7 @@ public final class TestUtil {
|
||||||
FileSystem fs = path.getFileSystem();
|
FileSystem fs = path.getFileSystem();
|
||||||
while (fs instanceof FilterFileSystem) {
|
while (fs instanceof FilterFileSystem) {
|
||||||
FilterFileSystem ffs = (FilterFileSystem) fs;
|
FilterFileSystem ffs = (FilterFileSystem) fs;
|
||||||
if (ffs.getParent() instanceof WindowsFS) {
|
if (ffs.provider() instanceof WindowsFS) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
fs = ffs.getDelegate();
|
fs = ffs.getDelegate();
|
||||||
|
@ -1718,7 +1718,7 @@ public final class TestUtil {
|
||||||
FileSystem fs = path.getFileSystem();
|
FileSystem fs = path.getFileSystem();
|
||||||
while (fs instanceof FilterFileSystem) {
|
while (fs instanceof FilterFileSystem) {
|
||||||
FilterFileSystem ffs = (FilterFileSystem) fs;
|
FilterFileSystem ffs = (FilterFileSystem) fs;
|
||||||
if (ffs.getParent() instanceof VirusCheckingFS) {
|
if (ffs.provider() instanceof VirusCheckingFS) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
fs = ffs.getDelegate();
|
fs = ffs.getDelegate();
|
||||||
|
@ -1735,8 +1735,8 @@ public final class TestUtil {
|
||||||
FileSystem fs = ((FSDirectory) dir).getDirectory().getFileSystem();
|
FileSystem fs = ((FSDirectory) dir).getDirectory().getFileSystem();
|
||||||
while (fs instanceof FilterFileSystem) {
|
while (fs instanceof FilterFileSystem) {
|
||||||
FilterFileSystem ffs = (FilterFileSystem) fs;
|
FilterFileSystem ffs = (FilterFileSystem) fs;
|
||||||
if (ffs.getParent() instanceof VirusCheckingFS) {
|
if (ffs.provider() instanceof VirusCheckingFS) {
|
||||||
VirusCheckingFS vfs = (VirusCheckingFS) ffs.getParent();
|
VirusCheckingFS vfs = (VirusCheckingFS) ffs.provider();
|
||||||
boolean isEnabled = vfs.isEnabled();
|
boolean isEnabled = vfs.isEnabled();
|
||||||
vfs.disable();
|
vfs.disable();
|
||||||
return isEnabled;
|
return isEnabled;
|
||||||
|
@ -1755,8 +1755,8 @@ public final class TestUtil {
|
||||||
FileSystem fs = ((FSDirectory) dir).getDirectory().getFileSystem();
|
FileSystem fs = ((FSDirectory) dir).getDirectory().getFileSystem();
|
||||||
while (fs instanceof FilterFileSystem) {
|
while (fs instanceof FilterFileSystem) {
|
||||||
FilterFileSystem ffs = (FilterFileSystem) fs;
|
FilterFileSystem ffs = (FilterFileSystem) fs;
|
||||||
if (ffs.getParent() instanceof VirusCheckingFS) {
|
if (ffs.provider() instanceof VirusCheckingFS) {
|
||||||
VirusCheckingFS vfs = (VirusCheckingFS) ffs.getParent();
|
VirusCheckingFS vfs = (VirusCheckingFS) ffs.provider();
|
||||||
vfs.enable();
|
vfs.enable();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.lucene.tests.mockfile;
|
package org.apache.lucene.tests.mockfile;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
|
|
||||||
|
@ -28,8 +26,8 @@ public class TestDisableFsyncFS extends MockFileSystemTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Path wrap(Path path) {
|
protected Path wrap(Path path) {
|
||||||
FileSystem fs = new DisableFsyncFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
|
DisableFsyncFS provider = new DisableFsyncFS(path.getFileSystem());
|
||||||
return new FilterPath(path, fs);
|
return provider.wrapPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Test that we don't corrumpt fsync: it just doesnt happen */
|
/** Test that we don't corrumpt fsync: it just doesnt happen */
|
||||||
|
|
|
@ -16,9 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.lucene.tests.mockfile;
|
package org.apache.lucene.tests.mockfile;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.file.DirectoryStream;
|
import java.nio.file.DirectoryStream;
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -34,10 +32,8 @@ public class TestExtrasFS extends MockFileSystemTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
Path wrap(Path path, boolean active, boolean createDirectory) {
|
Path wrap(Path path, boolean active, boolean createDirectory) {
|
||||||
FileSystem fs =
|
ExtrasFS provider = new ExtrasFS(path.getFileSystem(), active, createDirectory);
|
||||||
new ExtrasFS(path.getFileSystem(), active, createDirectory)
|
return provider.wrapPath(path);
|
||||||
.getFileSystem(URI.create("file:///"));
|
|
||||||
return new FilterPath(path, fs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** test where extra file is created */
|
/** test where extra file is created */
|
||||||
|
|
|
@ -18,8 +18,6 @@ package org.apache.lucene.tests.mockfile;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -35,9 +33,8 @@ public class TestHandleLimitFS extends MockFileSystemTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
Path wrap(Path path, int limit) {
|
Path wrap(Path path, int limit) {
|
||||||
FileSystem fs =
|
HandleLimitFS provider = new HandleLimitFS(path.getFileSystem(), limit);
|
||||||
new HandleLimitFS(path.getFileSystem(), limit).getFileSystem(URI.create("file:///"));
|
return provider.wrapPath(path);
|
||||||
return new FilterPath(path, fs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** set a limit at n files, then open more than that and ensure we hit exception */
|
/** set a limit at n files, then open more than that and ensure we hit exception */
|
||||||
|
|
|
@ -19,10 +19,8 @@ package org.apache.lucene.tests.mockfile;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.channels.SeekableByteChannel;
|
import java.nio.channels.SeekableByteChannel;
|
||||||
import java.nio.file.DirectoryStream;
|
import java.nio.file.DirectoryStream;
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
@ -31,8 +29,8 @@ public class TestHandleTrackingFS extends MockFileSystemTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Path wrap(Path path) {
|
protected Path wrap(Path path) {
|
||||||
FileSystem fs = new LeakFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
|
LeakFS provider = new LeakFS(path.getFileSystem());
|
||||||
return new FilterPath(path, fs);
|
return provider.wrapPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Test that the delegate gets closed on exception in HandleTrackingFS#onClose */
|
/** Test that the delegate gets closed on exception in HandleTrackingFS#onClose */
|
||||||
|
@ -40,7 +38,7 @@ public class TestHandleTrackingFS extends MockFileSystemTestCase {
|
||||||
Path path =
|
Path path =
|
||||||
wrap(createTempDir()); // we are using LeakFS under the hood if we don't get closed the test
|
wrap(createTempDir()); // we are using LeakFS under the hood if we don't get closed the test
|
||||||
// fails
|
// fails
|
||||||
FileSystem fs =
|
HandleTrackingFS provider =
|
||||||
new HandleTrackingFS("test://", path.getFileSystem()) {
|
new HandleTrackingFS("test://", path.getFileSystem()) {
|
||||||
@Override
|
@Override
|
||||||
protected void onClose(Path path, Object stream) throws IOException {
|
protected void onClose(Path path, Object stream) throws IOException {
|
||||||
|
@ -51,8 +49,8 @@ public class TestHandleTrackingFS extends MockFileSystemTestCase {
|
||||||
protected void onOpen(Path path, Object stream) throws IOException {
|
protected void onOpen(Path path, Object stream) throws IOException {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}.getFileSystem(URI.create("file:///"));
|
};
|
||||||
Path dir = new FilterPath(path, fs);
|
Path dir = provider.wrapPath(path);
|
||||||
|
|
||||||
OutputStream file = Files.newOutputStream(dir.resolve("somefile"));
|
OutputStream file = Files.newOutputStream(dir.resolve("somefile"));
|
||||||
file.write(5);
|
file.write(5);
|
||||||
|
@ -63,7 +61,6 @@ public class TestHandleTrackingFS extends MockFileSystemTestCase {
|
||||||
|
|
||||||
InputStream stream = Files.newInputStream(dir.resolve("somefile"));
|
InputStream stream = Files.newInputStream(dir.resolve("somefile"));
|
||||||
expectThrows(IOException.class, stream::close);
|
expectThrows(IOException.class, stream::close);
|
||||||
fs.close();
|
|
||||||
|
|
||||||
DirectoryStream<Path> dirStream = Files.newDirectoryStream(dir);
|
DirectoryStream<Path> dirStream = Files.newDirectoryStream(dir);
|
||||||
expectThrows(IOException.class, dirStream::close);
|
expectThrows(IOException.class, dirStream::close);
|
||||||
|
@ -74,7 +71,7 @@ public class TestHandleTrackingFS extends MockFileSystemTestCase {
|
||||||
Path path =
|
Path path =
|
||||||
wrap(createTempDir()); // we are using LeakFS under the hood if we don't get closed the test
|
wrap(createTempDir()); // we are using LeakFS under the hood if we don't get closed the test
|
||||||
// fails
|
// fails
|
||||||
FileSystem fs =
|
HandleTrackingFS provider =
|
||||||
new HandleTrackingFS("test://", path.getFileSystem()) {
|
new HandleTrackingFS("test://", path.getFileSystem()) {
|
||||||
@Override
|
@Override
|
||||||
protected void onClose(Path path, Object stream) throws IOException {}
|
protected void onClose(Path path, Object stream) throws IOException {}
|
||||||
|
@ -83,17 +80,15 @@ public class TestHandleTrackingFS extends MockFileSystemTestCase {
|
||||||
protected void onOpen(Path path, Object stream) throws IOException {
|
protected void onOpen(Path path, Object stream) throws IOException {
|
||||||
throw new IOException("boom");
|
throw new IOException("boom");
|
||||||
}
|
}
|
||||||
}.getFileSystem(URI.create("file:///"));
|
};
|
||||||
Path dir = new FilterPath(path, fs);
|
Path dir = provider.wrapPath(path);
|
||||||
|
|
||||||
expectThrows(IOException.class, () -> Files.newOutputStream(dir.resolve("somefile")));
|
expectThrows(IOException.class, () -> Files.newOutputStream(dir.resolve("somefile")));
|
||||||
|
|
||||||
expectThrows(IOException.class, () -> Files.newByteChannel(dir.resolve("somefile")));
|
expectThrows(IOException.class, () -> Files.newByteChannel(dir.resolve("somefile")));
|
||||||
|
|
||||||
expectThrows(IOException.class, () -> Files.newInputStream(dir.resolve("somefile")));
|
expectThrows(IOException.class, () -> Files.newInputStream(dir.resolve("somefile")));
|
||||||
fs.close();
|
|
||||||
|
|
||||||
expectThrows(IOException.class, () -> Files.newDirectoryStream(dir));
|
expectThrows(IOException.class, () -> Files.newDirectoryStream(dir));
|
||||||
fs.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,9 @@ package org.apache.lucene.tests.mockfile;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.channels.AsynchronousFileChannel;
|
import java.nio.channels.AsynchronousFileChannel;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.channels.SeekableByteChannel;
|
import java.nio.channels.SeekableByteChannel;
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -37,8 +35,8 @@ public class TestLeakFS extends MockFileSystemTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Path wrap(Path path) {
|
protected Path wrap(Path path) {
|
||||||
FileSystem fs = new LeakFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
|
LeakFS provider = new LeakFS(path.getFileSystem());
|
||||||
return new FilterPath(path, fs);
|
return provider.wrapPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Test leaks via Files.newInputStream */
|
/** Test leaks via Files.newInputStream */
|
||||||
|
|
|
@ -17,9 +17,7 @@
|
||||||
package org.apache.lucene.tests.mockfile;
|
package org.apache.lucene.tests.mockfile;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.file.DirectoryStream;
|
import java.nio.file.DirectoryStream;
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -35,8 +33,8 @@ public class TestShuffleFS extends MockFileSystemTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
Path wrap(Path path, long seed) {
|
Path wrap(Path path, long seed) {
|
||||||
FileSystem fs = new ShuffleFS(path.getFileSystem(), seed).getFileSystem(URI.create("file:///"));
|
ShuffleFS provider = new ShuffleFS(path.getFileSystem(), seed);
|
||||||
return new FilterPath(path, fs);
|
return provider.wrapPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** test that we return directory listings correctly */
|
/** test that we return directory listings correctly */
|
||||||
|
|
|
@ -18,11 +18,9 @@ package org.apache.lucene.tests.mockfile;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.channels.AsynchronousFileChannel;
|
import java.nio.channels.AsynchronousFileChannel;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.channels.SeekableByteChannel;
|
import java.nio.channels.SeekableByteChannel;
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.NoSuchFileException;
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -44,9 +42,8 @@ public class TestVerboseFS extends MockFileSystemTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
Path wrap(Path path, InfoStream stream) {
|
Path wrap(Path path, InfoStream stream) {
|
||||||
FileSystem fs =
|
VerboseFS provider = new VerboseFS(path.getFileSystem(), stream);
|
||||||
new VerboseFS(path.getFileSystem(), stream).getFileSystem(URI.create("file:///"));
|
return provider.wrapPath(path);
|
||||||
return new FilterPath(path, fs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** InfoStream that looks for a substring and indicates if it saw it */
|
/** InfoStream that looks for a substring and indicates if it saw it */
|
||||||
|
|
|
@ -19,9 +19,7 @@ package org.apache.lucene.tests.mockfile;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.file.AccessDeniedException;
|
import java.nio.file.AccessDeniedException;
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
@ -30,10 +28,8 @@ public class TestVirusCheckingFS extends MockFileSystemTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Path wrap(Path path) {
|
protected Path wrap(Path path) {
|
||||||
FileSystem fs =
|
VirusCheckingFS provider = new VirusCheckingFS(path.getFileSystem(), random().nextLong());
|
||||||
new VirusCheckingFS(path.getFileSystem(), random().nextLong())
|
return provider.wrapPath(path);
|
||||||
.getFileSystem(URI.create("file:///"));
|
|
||||||
return new FilterPath(path, fs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Test Files.delete fails if a file has an open inputstream against it */
|
/** Test Files.delete fails if a file has an open inputstream against it */
|
||||||
|
|
|
@ -20,8 +20,6 @@ import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.NoSuchFileException;
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -42,8 +40,8 @@ public class TestWindowsFS extends MockFileSystemTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Path wrap(Path path) {
|
protected Path wrap(Path path) {
|
||||||
FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
|
WindowsFS provider = new WindowsFS(path.getFileSystem());
|
||||||
return new FilterPath(path, fs);
|
return provider.wrapPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Test Files.delete fails if a file has an open inputstream against it */
|
/** Test Files.delete fails if a file has an open inputstream against it */
|
||||||
|
|
Loading…
Reference in New Issue