It fixes problem when downloading zip files where some files are missing

parent 4975d7d0
......@@ -3,3 +3,5 @@
/.classpath
/.project
/.pydevproject
.metadata/
RemoteSystemsTempFiles/
......@@ -4,7 +4,7 @@
<groupId>org.icatproject</groupId>
<artifactId>ids.server</artifactId>
<packaging>war</packaging>
<version>1.8.0</version>
<version>1.8.0-patched</version>
<name>IDS Server</name>
<properties>
......
......@@ -209,6 +209,7 @@ public class IdsBean {
zos.setLevel(0); // Otherwise use default compression
}
List<String> missingFiles = new ArrayList<String>();
for (DfInfoImpl dfInfo : dfInfos) {
logger.debug("Adding " + dfInfo + " to zip");
transfer = dfInfo;
......@@ -217,19 +218,41 @@ public class IdsBean {
InputStream stream = null;
try {
zos.putNextEntry(new ZipEntry(entryName));
stream = mainStorage.get(dfInfo.getDfLocation(), dfInfo.getCreateId(), dfInfo.getModId());
int length;
while ((length = stream.read(bytes)) >= 0) {
zos.write(bytes, 0, length);
if (new File( dfInfo.getDfLocation()).exists()){
stream = mainStorage.get(dfInfo.getDfLocation(), dfInfo.getCreateId(), dfInfo.getModId());
int length;
while ((length = stream.read(bytes)) >= 0) {
zos.write(bytes, 0, length);
}
}
else{
System.out.println("File does not exist: " + dfInfo.getDfLocation());
missingFiles.add(dfInfo.getDfLocation());
}
} catch (ZipException e) {
logger.debug("Skipped duplicate");
}
zos.closeEntry();
if (stream != null) {
if (stream != null) {
stream.close();
}
}
/** Adds report to the zip file **/
if (missingFiles.size() > 0){
ZipEntry e = new ZipEntry("readme.txt");
zos.putNextEntry(e);
StringBuilder sb = new StringBuilder();
sb.append("# Archiving Report").append("\n");
sb.append("# Restoration completed successfully with warnings").append("\n");
for (String file : missingFiles) {
sb.append("\t").append("[WARNING]").append("\t").append("Missing file").append("\t").append(file).append("\n");
}
byte[] data = sb.toString().getBytes();
zos.write(data, 0, data.length);
zos.closeEntry();
}
zos.close();
} else {
DfInfoImpl dfInfo = dfInfos.iterator().next();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment