Create mime/packages folder if it doesn't exit yet [IDEA-247921]

GitOrigin-RevId: b4e670bca4d421ac783ce47fc0e6ccb90964eddd
This commit is contained in:
Rustam Vishnyakov
2020-09-28 10:55:56 +00:00
committed by intellij-monorepo-bot
parent b12d48b52b
commit cf10d01288
@@ -19,6 +19,7 @@ import javax.xml.stream.XMLStreamWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -71,10 +72,12 @@ class LinuxMimeTypeUpdater {
}
static void createMimeFile(@NotNull List<MimeTypeDescription> mimeTypeDescriptions) throws IOException, XMLStreamException {
static void createMimeFile(@NotNull List<MimeTypeDescription> mimeTypeDescriptions)
throws IOException, XMLStreamException, OSFileAssociationException {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
final FileWriter fileWriter = new FileWriter(
System.getProperty("user.home") + File.separator + LOCAL_MIME_PACKAGES_PATH + File.separator + EXTENSIONS_FILE_NAME);
String mimePackagesPath = System.getProperty("user.home") + File.separator + LOCAL_MIME_PACKAGES_PATH;
ensureMimePackagesDirExists(mimePackagesPath);
final FileWriter fileWriter = new FileWriter(mimePackagesPath + File.separator + EXTENSIONS_FILE_NAME, StandardCharsets.UTF_8);
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(fileWriter);
try {
writer.writeStartDocument("UTF-8", "1.0");
@@ -94,6 +97,15 @@ class LinuxMimeTypeUpdater {
}
}
private static void ensureMimePackagesDirExists(@NotNull String mimePackagesPath) throws OSFileAssociationException {
File packagesDir = new File(mimePackagesPath);
if (!packagesDir.exists()) {
if (!packagesDir.mkdirs()) {
throw new OSFileAssociationException( mimePackagesPath + " directory doesn't exist and can't be created.");
}
}
}
private static void writeDescription(@NotNull XMLStreamWriter writer, @NotNull MimeTypeDescription description)
throws XMLStreamException {
writer.writeCharacters(" ");