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

parent 4975d7d0
...@@ -3,3 +3,5 @@ ...@@ -3,3 +3,5 @@
/.classpath /.classpath
/.project /.project
/.pydevproject /.pydevproject
.metadata/
RemoteSystemsTempFiles/
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<groupId>org.icatproject</groupId> <groupId>org.icatproject</groupId>
<artifactId>ids.server</artifactId> <artifactId>ids.server</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<version>1.8.0</version> <version>1.8.0-patched</version>
<name>IDS Server</name> <name>IDS Server</name>
<properties> <properties>
......
...@@ -209,6 +209,7 @@ public class IdsBean { ...@@ -209,6 +209,7 @@ public class IdsBean {
zos.setLevel(0); // Otherwise use default compression zos.setLevel(0); // Otherwise use default compression
} }
List<String> missingFiles = new ArrayList<String>();
for (DfInfoImpl dfInfo : dfInfos) { for (DfInfoImpl dfInfo : dfInfos) {
logger.debug("Adding " + dfInfo + " to zip"); logger.debug("Adding " + dfInfo + " to zip");
transfer = dfInfo; transfer = dfInfo;
...@@ -217,19 +218,41 @@ public class IdsBean { ...@@ -217,19 +218,41 @@ public class IdsBean {
InputStream stream = null; InputStream stream = null;
try { try {
zos.putNextEntry(new ZipEntry(entryName)); zos.putNextEntry(new ZipEntry(entryName));
stream = mainStorage.get(dfInfo.getDfLocation(), dfInfo.getCreateId(), dfInfo.getModId()); if (new File( dfInfo.getDfLocation()).exists()){
int length; stream = mainStorage.get(dfInfo.getDfLocation(), dfInfo.getCreateId(), dfInfo.getModId());
while ((length = stream.read(bytes)) >= 0) { int length;
zos.write(bytes, 0, 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) { } catch (ZipException e) {
logger.debug("Skipped duplicate"); logger.debug("Skipped duplicate");
} }
zos.closeEntry(); zos.closeEntry();
if (stream != null) { if (stream != null) {
stream.close(); 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(); zos.close();
} else { } else {
DfInfoImpl dfInfo = dfInfos.iterator().next(); 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