Skip to content

Commit

Permalink
Merge pull request #1372 from virtualcell/WindowOmexExportFixForMetadata
Browse files Browse the repository at this point in the history
Fixed bug where if windows OS, omex manifest would contain bad separator
  • Loading branch information
CodeByDrescher authored Nov 1, 2024
2 parents 192138a + 528552c commit b68183d
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions vcell-core/src/main/java/org/vcell/sedml/SEDMLExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.*;
Expand Down Expand Up @@ -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) {
Expand All @@ -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<String> 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) {
Expand Down

0 comments on commit b68183d

Please sign in to comment.