summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorralph isenmann2022-01-27 11:35:09 +0100
committerralph isenmann2022-01-27 11:35:09 +0100
commitb0b1d7dc05e27f94cbca2e703eb0c6bfbc562e78 (patch)
tree855d7620221df4dda6b70550c028573c5f1f7b53
parent[CLIENT] fix isPageValid check for container (diff)
downloadtutor-module-b0b1d7dc05e27f94cbca2e703eb0c6bfbc562e78.tar.gz
tutor-module-b0b1d7dc05e27f94cbca2e703eb0c6bfbc562e78.tar.xz
tutor-module-b0b1d7dc05e27f94cbca2e703eb0c6bfbc562e78.zip
[CLIENT,SERVER] move handling of tar into TarArchiveReader and TarArchiveWriter in master-sync-shared
-rwxr-xr-xdozentenmodul/pom.xml7
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java42
-rw-r--r--dozentenmodulserver/pom.xml7
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java33
4 files changed, 21 insertions, 68 deletions
diff --git a/dozentenmodul/pom.xml b/dozentenmodul/pom.xml
index 7085b199..86540335 100755
--- a/dozentenmodul/pom.xml
+++ b/dozentenmodul/pom.xml
@@ -180,12 +180,6 @@
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>org.kamranzafar</groupId>
- <artifactId>jtar</artifactId>
- <version>[2.0,3.0)</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>[2.17,3.0)</version>
@@ -205,4 +199,3 @@
</dependency>
</dependencies>
</project>
-
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java
index 5f0dd887..783fb0fa 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java
@@ -5,9 +5,6 @@ import com.google.gson.JsonParser;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.thrift.TException;
-import org.kamranzafar.jtar.TarEntry;
-import org.kamranzafar.jtar.TarHeader;
-import org.kamranzafar.jtar.TarInputStream;
import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
import org.openslx.bwlp.thrift.iface.LectureSummary;
import org.openslx.dozmod.gui.Gui;
@@ -21,6 +18,8 @@ import org.openslx.dozmod.thrift.cache.LectureCache;
import org.openslx.thrifthelper.TConst;
import org.openslx.thrifthelper.ThriftManager;
import org.openslx.util.ThriftUtil;
+import org.openslx.util.Util;
+import org.openslx.util.TarArchiveUtil.TarArchiveReader;
import org.openslx.virtualization.configuration.container.ContainerMeta;
import javax.swing.*;
@@ -28,7 +27,6 @@ import java.awt.*;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
@@ -124,39 +122,25 @@ public class ContainerUtils {
JsonArray manifestJson = null;
try {
- TarInputStream tis = new TarInputStream(new FileInputStream(tarFile));
- ByteArrayOutputStream output = new ByteArrayOutputStream();
- byte[] rawData = new byte[1024];
- TarEntry entry;
-
- // setDefaultSkip seems to fasten things up while processing the file,
- // because we want only to check manifest.json and repositories file
- tis.setDefaultSkip(true);
- while ((entry = tis.getNextEntry()) != null) {
- if (!TarHeader.USTAR_MAGIC.equals(entry.getHeader().magic.toString()))
- break;
- Arrays.fill(rawData, (byte) 0);
- output.reset();
- int count = 0;
-
- if (entry.getName().equals("manifest.json")) {
+ TarArchiveReader tarReader = new TarArchiveReader(new FileInputStream(tarFile));
+
+ while (tarReader.hasNextEntry()) {
+ if (tarReader.getEntryName().equals("manifest.json")) {
containsManifest = true;
- while ((count = tis.read(rawData)) != -1) {
- output.write(rawData, 0, count);
- }
- manifestJson = JsonParser.parseString(new String(output.toByteArray(), StandardCharsets.UTF_8))
- .getAsJsonArray();
+ manifestJson = JsonParser.parseString(new String(tarReader.readCurrentEntry(), StandardCharsets.UTF_8))
+ .getAsJsonArray();
}
-
- if (entry.getName().equals("repositories")) {
+
+ if (tarReader.getEntryName().equals("repositories")) {
containsRepositories = true;
- // dont read the file, no checks for the Content
+ // just check if the file exists
}
if (containsManifest && containsRepositories)
break;
}
- tis.close();
+ Util.safeClose(tarReader);
+
// check the json files inside the tar file
if (containsManifest && containsRepositories && manifestJson.isJsonArray() && manifestJson.size() == 1) {
isValid = true;
diff --git a/dozentenmodulserver/pom.xml b/dozentenmodulserver/pom.xml
index dae50672..62f46413 100644
--- a/dozentenmodulserver/pom.xml
+++ b/dozentenmodulserver/pom.xml
@@ -250,12 +250,6 @@
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>org.kamranzafar</groupId>
- <artifactId>jtar</artifactId>
- <version>[2.0,3.0)</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>[2.17,3.0)</version>
@@ -269,4 +263,3 @@
</dependency>
</dependencies>
</project>
-
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java
index 088cf5b0..f90a246a 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java
@@ -4,7 +4,6 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
-import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@@ -13,14 +12,10 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
-import java.util.zip.GZIPOutputStream;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import org.kamranzafar.jtar.TarEntry;
-import org.kamranzafar.jtar.TarHeader;
-import org.kamranzafar.jtar.TarOutputStream;
import org.openslx.bwlp.sat.database.mappers.DbImage;
import org.openslx.bwlp.sat.database.mappers.DbLecture;
import org.openslx.bwlp.sat.database.mappers.DbLecture.LaunchData;
@@ -34,6 +29,7 @@ import org.openslx.bwlp.thrift.iface.TNotFoundException;
import org.openslx.util.GrowingThreadPoolExecutor;
import org.openslx.util.Json;
import org.openslx.util.Util;
+import org.openslx.util.TarArchiveUtil.TarArchiveWriter;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
@@ -130,19 +126,6 @@ public class WebServer extends NanoHTTPD {
Json.serialize(FileServer.instance().getStatus()));
}
- private static void tarPutFile(TarOutputStream output, String fileName, String data) throws IOException {
- if (data == null)
- return;
- tarPutFile(output, fileName, data.getBytes(StandardCharsets.UTF_8));
- }
-
- private static void tarPutFile(TarOutputStream output, String fileName, byte[] data) throws IOException {
- if (data == null)
- return;
- output.putNextEntry(new TarEntry(TarHeader.createHeader(fileName, data.length, Util.unixTime(), false, 0644)));
- output.write(data);
- }
-
/**
* Return meta data (eg. *.vmx) required to start the given lecture.
*
@@ -152,7 +135,7 @@ public class WebServer extends NanoHTTPD {
private Response serveMetaData(final String lectureId) {
PipedInputStream sink = new PipedInputStream(10000);
try {
- final TarOutputStream output = new TarOutputStream(new GZIPOutputStream(new PipedOutputStream(sink)));
+ final TarArchiveWriter tarArchiveWriter = new TarArchiveWriter(new PipedOutputStream(sink));
final LaunchData ld;
try {
ld = DbLecture.getClientLaunchData(lectureId);
@@ -167,20 +150,20 @@ public class WebServer extends NanoHTTPD {
@Override
public void run() {
try {
- tarPutFile(output, "vmx", ld.configuration);
- tarPutFile(output, "runscript", ld.legacyRunScript);
- tarPutFile(output, "netshares", serializeNetShares(ld.netShares));
+ tarArchiveWriter.writeFile("vmx", ld.configuration);
+ tarArchiveWriter.writeFile("runscript", ld.legacyRunScript);
+ tarArchiveWriter.writeFile("netshares", serializeNetShares(ld.netShares));
if (ld.runScript != null) {
int cnt = 0;
for (RunScript rs : ld.runScript) {
- tarPutFile(output, String.format("adminrun/%04d-%d-%d.%s", cnt++, rs.visibility,
- rs.passCreds ? 1 : 0, rs.extension), rs.content);
+ tarArchiveWriter.writeFile(String.format("adminrun/%04d-%d-%d.%s", cnt++, rs.visibility,
+ rs.passCreds ? 1 : 0, rs.extension), rs.content);
}
}
} catch (IOException e) {
LOGGER.warn("Error writing to tar stream", e);
} finally {
- Util.safeClose(output);
+ Util.safeClose(tarArchiveWriter);
}
}
});