coverity 1116693: properties template file creation unlikely but if repetitive, serious.

Signed-off-by: Daan Hoogland <daan@onecht.net>
This commit is contained in:
Daan Hoogland 2015-07-07 22:55:09 +02:00
parent 2c7e19faff
commit bb2c02d144

View File

@ -495,13 +495,14 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
String destFileFullPath = destFile.getAbsolutePath() + File.separator + fileName; String destFileFullPath = destFile.getAbsolutePath() + File.separator + fileName;
s_logger.debug("copy snapshot " + srcFile.getAbsolutePath() + " to template " + destFileFullPath); s_logger.debug("copy snapshot " + srcFile.getAbsolutePath() + " to template " + destFileFullPath);
Script.runSimpleBashScript("cp " + srcFile.getAbsolutePath() + " " + destFileFullPath); Script.runSimpleBashScript("cp " + srcFile.getAbsolutePath() + " " + destFileFullPath);
try {
// generate template.properties file
String metaFileName = destFile.getAbsolutePath() + File.separator + "template.properties"; String metaFileName = destFile.getAbsolutePath() + File.separator + "template.properties";
_storage.create(destFile.getAbsolutePath(), "template.properties");
File metaFile = new File(metaFileName); File metaFile = new File(metaFileName);
try {
_storage.create(destFile.getAbsolutePath(), "template.properties");
try ( // generate template.properties file
FileWriter writer = new FileWriter(metaFile); FileWriter writer = new FileWriter(metaFile);
BufferedWriter bufferWriter = new BufferedWriter(writer); BufferedWriter bufferWriter = new BufferedWriter(writer);
) {
// KVM didn't change template unique name, just used the template name passed from orchestration layer, so no need // KVM didn't change template unique name, just used the template name passed from orchestration layer, so no need
// to send template name back. // to send template name back.
bufferWriter.write("uniquename=" + destData.getName()); bufferWriter.write("uniquename=" + destData.getName());
@ -510,8 +511,6 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
bufferWriter.write("\n"); bufferWriter.write("\n");
long size = _storage.getSize(destFileFullPath); long size = _storage.getSize(destFileFullPath);
bufferWriter.write("size=" + size); bufferWriter.write("size=" + size);
bufferWriter.close();
writer.close();
/** /**
* Snapshots might be in either QCOW2 or RAW image format * Snapshots might be in either QCOW2 or RAW image format
@ -549,10 +548,11 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
} catch (ConfigurationException e) { } catch (ConfigurationException e) {
s_logger.debug("Failed to create template:" + e.toString()); s_logger.debug("Failed to create template:" + e.toString());
return new CopyCmdAnswer(e.toString()); return new CopyCmdAnswer(e.toString());
} catch (IOException e) { } catch (InternalErrorException e) {
s_logger.debug("Failed to create template:" + e.toString()); s_logger.debug("Failed to create template:" + e.toString());
return new CopyCmdAnswer(e.toString()); return new CopyCmdAnswer(e.toString());
} catch (InternalErrorException e) { }
} catch (IOException e) {
s_logger.debug("Failed to create template:" + e.toString()); s_logger.debug("Failed to create template:" + e.toString());
return new CopyCmdAnswer(e.toString()); return new CopyCmdAnswer(e.toString());
} }