use of org.neo4j.io.fs.FileHandle in project neo4j by neo4j.
the class ZipUtils method zip.
/**
* Create zip archive for requested <code>sourceToCompress</code>.
* If <code>sourceToCompress</code> is a directory then content of that directory and all its sub-directories will be added to the archive.
* If <code>sourceToCompress</code> does not exist or is an empty directory then archive will not be created.
* @param fileSystem source file system
* @param sourceToCompress source file to compress
* @param destinationZip zip file compress source to
* @param includeSourceDirectoryInRelativePath true if relative path of content should include sourceToCompress, otherwise false.
* This is only meaningful sourceToCompress is a directory.
* @throws IOException when underlying file system access produce IOException
*/
public static void zip(FileSystemAbstraction fileSystem, Path sourceToCompress, Path destinationZip, boolean includeSourceDirectoryInRelativePath) throws IOException {
if (!fileSystem.fileExists(sourceToCompress)) {
return;
}
if (isEmptyDirectory(fileSystem, sourceToCompress)) {
return;
}
Map<String, String> env = Map.of("create", "true");
URI archiveAbsoluteURI = URI.create("jar:file:" + destinationZip.toUri().getRawPath());
Path baseForRelativePath = sourceToCompress;
if (includeSourceDirectoryInRelativePath) {
baseForRelativePath = sourceToCompress.getParent();
}
try (FileSystem zipFs = FileSystems.newFileSystem(archiveAbsoluteURI, env)) {
List<FileHandle> fileHandles = fileSystem.streamFilesRecursive(sourceToCompress).collect(toList());
for (FileHandle fileHandle : fileHandles) {
Path sourcePath = fileHandle.getPath();
Path zipFsPath = fileSystem.isDirectory(sourceToCompress) ? zipFs.getPath(baseForRelativePath.relativize(sourcePath).toString()) : zipFs.getPath(sourcePath.getFileName().toString());
if (zipFsPath.getParent() != null) {
Files.createDirectories(zipFsPath.getParent());
}
Files.copy(sourcePath, zipFsPath);
}
}
}
use of org.neo4j.io.fs.FileHandle in project neo4j by neo4j.
the class ConsistencyCheckWithCorruptGBPTreeIT method schemaIndexFiles.
private Path[] schemaIndexFiles(FileSystemAbstraction fs, Path databaseDir, GraphDatabaseSettings.SchemaIndex schemaIndex) throws IOException {
final String fileNameFriendlyProviderName = IndexDirectoryStructure.fileNameFriendly(schemaIndex.providerName());
Path indexDir = databaseDir.resolve("schema/index/");
return fs.streamFilesRecursive(indexDir).map(FileHandle::getPath).filter(path -> path.toAbsolutePath().toString().contains(fileNameFriendlyProviderName)).toArray(Path[]::new);
}
Aggregations