Search in sources :

Example 61 with FileSystem

use of java.nio.file.FileSystem in project gerrit by GerritCodeReview.

the class GerritLauncher method getZipFileSystem.

public static synchronized FileSystem getZipFileSystem(Path zip) throws IOException {
    // FileSystems canonicalizes the path, so we should too.
    zip = zip.toRealPath();
    FileSystem zipFs = zipFileSystems.get(zip);
    if (zipFs == null) {
        zipFs = newZipFileSystem(zip);
        zipFileSystems.put(zip, zipFs);
    }
    return zipFs;
}
Also used : FileSystem(java.nio.file.FileSystem)

Example 62 with FileSystem

use of java.nio.file.FileSystem in project lucene-solr by apache.

the class TestUtil method hasVirusChecker.

public static boolean hasVirusChecker(Path path) {
    FileSystem fs = path.getFileSystem();
    while (fs instanceof FilterFileSystem) {
        FilterFileSystem ffs = (FilterFileSystem) fs;
        if (ffs.getParent() instanceof VirusCheckingFS) {
            return true;
        }
        fs = ffs.getDelegate();
    }
    return false;
}
Also used : FileSystem(java.nio.file.FileSystem) FilterFileSystem(org.apache.lucene.mockfile.FilterFileSystem) FilterFileSystem(org.apache.lucene.mockfile.FilterFileSystem) VirusCheckingFS(org.apache.lucene.mockfile.VirusCheckingFS)

Example 63 with FileSystem

use of java.nio.file.FileSystem in project lucene-solr by apache.

the class TestUtil method enableVirusChecker.

public static void enableVirusChecker(Directory in) {
    Directory dir = FilterDirectory.unwrap(in);
    if (dir instanceof FSDirectory) {
        FileSystem fs = ((FSDirectory) dir).getDirectory().getFileSystem();
        while (fs instanceof FilterFileSystem) {
            FilterFileSystem ffs = (FilterFileSystem) fs;
            if (ffs.getParent() instanceof VirusCheckingFS) {
                VirusCheckingFS vfs = (VirusCheckingFS) ffs.getParent();
                vfs.enable();
                return;
            }
            fs = ffs.getDelegate();
        }
    }
}
Also used : FileSystem(java.nio.file.FileSystem) FilterFileSystem(org.apache.lucene.mockfile.FilterFileSystem) FilterFileSystem(org.apache.lucene.mockfile.FilterFileSystem) FSDirectory(org.apache.lucene.store.FSDirectory) VirusCheckingFS(org.apache.lucene.mockfile.VirusCheckingFS) Directory(org.apache.lucene.store.Directory) RAMDirectory(org.apache.lucene.store.RAMDirectory) FSDirectory(org.apache.lucene.store.FSDirectory) FilterDirectory(org.apache.lucene.store.FilterDirectory)

Example 64 with FileSystem

use of java.nio.file.FileSystem in project lucene-solr by apache.

the class TestUtil method disableVirusChecker.

/** Returns true if VirusCheckingFS is in use and was in fact already enabled */
public static boolean disableVirusChecker(Directory in) {
    Directory dir = FilterDirectory.unwrap(in);
    if (dir instanceof FSDirectory) {
        FileSystem fs = ((FSDirectory) dir).getDirectory().getFileSystem();
        while (fs instanceof FilterFileSystem) {
            FilterFileSystem ffs = (FilterFileSystem) fs;
            if (ffs.getParent() instanceof VirusCheckingFS) {
                VirusCheckingFS vfs = (VirusCheckingFS) ffs.getParent();
                boolean isEnabled = vfs.isEnabled();
                vfs.disable();
                return isEnabled;
            }
            fs = ffs.getDelegate();
        }
    }
    return false;
}
Also used : FileSystem(java.nio.file.FileSystem) FilterFileSystem(org.apache.lucene.mockfile.FilterFileSystem) FilterFileSystem(org.apache.lucene.mockfile.FilterFileSystem) FSDirectory(org.apache.lucene.store.FSDirectory) VirusCheckingFS(org.apache.lucene.mockfile.VirusCheckingFS) Directory(org.apache.lucene.store.Directory) RAMDirectory(org.apache.lucene.store.RAMDirectory) FSDirectory(org.apache.lucene.store.FSDirectory) FilterDirectory(org.apache.lucene.store.FilterDirectory)

Example 65 with FileSystem

use of java.nio.file.FileSystem in project lucene-solr by apache.

the class TestIOUtils method testSSD.

public void testSSD() throws Exception {
    assumeFalse("windows is not supported", Constants.WINDOWS);
    Path dir = createTempDir();
    dir = FilterPath.unwrap(dir).toRealPath();
    // fake ssd
    FileStore root = new MockFileStore(dir.toString() + " (/dev/zzz1)", "btrfs", "/dev/zzz1");
    // make a fake /dev/zzz1 for it
    Path devdir = dir.resolve("dev");
    Files.createDirectories(devdir);
    Files.createFile(devdir.resolve("zzz1"));
    // make a fake /sys/block/zzz/queue/rotational file for it
    Path sysdir = dir.resolve("sys").resolve("block").resolve("zzz").resolve("queue");
    Files.createDirectories(sysdir);
    try (OutputStream o = Files.newOutputStream(sysdir.resolve("rotational"))) {
        o.write("0\n".getBytes(StandardCharsets.US_ASCII));
    }
    Map<String, FileStore> mappings = Collections.singletonMap(dir.toString(), root);
    FileSystem mockLinux = new MockLinuxFileSystemProvider(dir.getFileSystem(), mappings, dir).getFileSystem(null);
    Path mockPath = mockLinux.getPath(dir.toString());
    assertFalse(IOUtils.spinsLinux(mockPath));
}
Also used : FilterPath(org.apache.lucene.mockfile.FilterPath) Path(java.nio.file.Path) FileStore(java.nio.file.FileStore) OutputStream(java.io.OutputStream) FileSystem(java.nio.file.FileSystem) FilterFileSystem(org.apache.lucene.mockfile.FilterFileSystem)

Aggregations

FileSystem (java.nio.file.FileSystem)159 Path (java.nio.file.Path)112 Test (org.junit.Test)66 IOException (java.io.IOException)25 File (java.io.File)17 ArrayList (java.util.ArrayList)14 FilterFileSystem (org.apache.lucene.mockfile.FilterFileSystem)13 URI (java.net.URI)11 FilterPath (org.apache.lucene.mockfile.FilterPath)11 InputStream (java.io.InputStream)10 OutputStream (java.io.OutputStream)10 FileStore (java.nio.file.FileStore)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)6 HashMap (java.util.HashMap)6 DefaultProjectFilesystemDelegate (com.facebook.buck.io.DefaultProjectFilesystemDelegate)5 ProjectFilesystemDelegate (com.facebook.buck.io.ProjectFilesystemDelegate)5 WindowsFS (org.apache.lucene.mockfile.WindowsFS)5 FSDirectory (org.apache.lucene.store.FSDirectory)5 BuckConfig (com.facebook.buck.cli.BuckConfig)4 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)4