Skip to content

Commit

Permalink
Merge pull request #1377 from virtualcell/New7_7Container
Browse files Browse the repository at this point in the history
Attempting to enforce needed permissions
  • Loading branch information
CodeByDrescher authored Nov 8, 2024
2 parents 9f29879 + 47c619e commit d53f86f
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions vcell-cli/src/main/java/org/vcell/cli/run/OmexHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.nio.file.*;
import java.text.ParseException;
import java.util.*;
import java.util.stream.Stream;

public class OmexHandler {
String tempPath;
Expand Down Expand Up @@ -56,30 +57,37 @@ public OmexHandler(String omexPath, String outDir) throws IOException {
}

private void replaceMetadataRdfFiles(Path zipFilePath) throws IOException {
if (!zipFilePath.toFile().exists() || !zipFilePath.toFile().isFile())
throw new IllegalArgumentException("ZipFile supposedly at `" + zipFilePath + "` is invalid");
if (!zipFilePath.toFile().canWrite()) if (!zipFilePath.toFile().setWritable(true))
throw new IllegalArgumentException("ZipFile at `" + zipFilePath + "` can not be written to.");
if (!zipFilePath.toFile().canExecute()) if (!zipFilePath.toFile().setExecutable(true))
throw new IllegalArgumentException("ZipFile at `" + zipFilePath + "` does not allow execution.");
try( FileSystem fs = FileSystems.newFileSystem(zipFilePath) ) {
for (Path root : fs.getRootDirectories()) {
Files.walk(root)
.filter(Files::isRegularFile)
.filter(path -> path.toString().endsWith(".rdf"))
.forEach(path -> {
try {
// write empty RDF file to temp file and replace the file inside the zip
Path tempFile = Files.createTempFile("temp", ".rdf");
String new_rdf_content =
"""
<?xml version='1.0' encoding='UTF-8'?>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
</rdf:RDF>
""";
Files.write(tempFile, new_rdf_content.getBytes());
// replace fileInsideZipPath with temp file
Files.delete(path);
Files.copy(tempFile, path);
Files.delete(tempFile);
} catch (IOException e) {
logger.error("Unable to delete metadata.rdf file from OMEX archive: " + e.getMessage(), e);
}
});
try (Stream<Path> contents = Files.walk(root)) {
contents.filter(Files::isRegularFile)
.filter(path -> path.toString().endsWith(".rdf"))
.forEach(path -> {
try {
// write empty RDF file to temp file and replace the file inside the zip
Path tempFile = Files.createTempFile("temp", ".rdf");
String new_rdf_content =
"""
<?xml version='1.0' encoding='UTF-8'?>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
</rdf:RDF>
""";
Files.write(tempFile, new_rdf_content.getBytes());
// replace fileInsideZipPath with temp file
Files.delete(path);
Files.copy(tempFile, path);
Files.delete(tempFile);
} catch (IOException e) {
logger.error("Unable to delete metadata.rdf file from OMEX archive: " + e.getMessage(), e);
}
});
}
}

}
Expand Down

0 comments on commit d53f86f

Please sign in to comment.