From 528552c52f77857ba4a2ed9f2ae2ae18aac16e6c Mon Sep 17 00:00:00 2001 From: Logan Drescher Date: Fri, 1 Nov 2024 11:51:55 -0400 Subject: [PATCH] Fixed bug where if windows OS, omex manifest would contain bad separator --- .../java/org/vcell/sedml/SEDMLExporter.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/vcell-core/src/main/java/org/vcell/sedml/SEDMLExporter.java b/vcell-core/src/main/java/org/vcell/sedml/SEDMLExporter.java index e6add74ab1..aa5f03bf84 100644 --- a/vcell-core/src/main/java/org/vcell/sedml/SEDMLExporter.java +++ b/vcell-core/src/main/java/org/vcell/sedml/SEDMLExporter.java @@ -17,6 +17,7 @@ import cbit.vcell.model.Model.ReservedSymbol; import cbit.vcell.model.Structure.StructureSize; import cbit.vcell.parser.*; +import cbit.vcell.resource.OperatingSystemInfo; import cbit.vcell.solver.*; import cbit.vcell.solver.Simulation; import cbit.vcell.solver.MathOverridesResolver.SymbolReplacement; @@ -57,8 +58,7 @@ import javax.xml.stream.XMLStreamException; import java.beans.PropertyVetoException; -import java.io.File; -import java.io.IOException; +import java.io.*; import java.net.URI; import java.nio.file.*; import java.util.*; @@ -1342,6 +1342,7 @@ public boolean createOmexArchive(String srcFolder, String sFileName) { replaceMetadataRdfFileInArchive(omexFile.toPath(), rdfFilePath); } + if (OperatingSystemInfo.getInstance().isWindows()) repairManifestEntry(omexFile.toPath()); removeOtherFiles(srcFolder, files); } catch (Exception e) { @@ -1359,6 +1360,26 @@ private static void replaceMetadataRdfFileInArchive(Path zipFilePath, Path newFi } } + private static void repairManifestEntry(Path zipFilePath) throws IOException { + try (FileSystem fs = FileSystems.newFileSystem(zipFilePath)) { + Path manifestPath = fs.getPath("/", "manifest.xml"); + if (!Files.exists(manifestPath)) throw new IOException("The manifest file in " + zipFilePath + " is missing"); + + List rawLines, correctedLines = new ArrayList<>(); + try (BufferedReader reader = new BufferedReader(Files.newBufferedReader(manifestPath))) { + rawLines = reader.lines().toList(); + } + for (String rawLine : rawLines) { + correctedLines.add(rawLine.contains(".\\") ? rawLine.replace(".\\", "./") : rawLine); + } + Path tmpFilePath = Files.createTempFile("fixedManifest", ""); + try (BufferedWriter writer = new BufferedWriter(Files.newBufferedWriter(tmpFilePath))) { + for (String line : correctedLines) writer.write(line + "\n"); + } + Files.copy(tmpFilePath, manifestPath, StandardCopyOption.REPLACE_EXISTING); + } + } + private static void removeOtherFiles(String outputDir, String[] files) { boolean isDeleted = false; for (String sd : files) {