cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject [44/50] git commit: updated refs/heads/CLOUDSTACK-8581 to 1a2e80b
Date Fri, 10 Jul 2015 10:08:39 GMT
coverity 1116693: properties template file creation unlikely but if repetitive, serious.

Signed-off-by: Daan Hoogland <daan@onecht.net>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/bb2c02d1
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/bb2c02d1
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/bb2c02d1

Branch: refs/heads/CLOUDSTACK-8581
Commit: bb2c02d14478ec3c1256f8739dd3e9a09deacb10
Parents: 2c7e19f
Author: Daan Hoogland <daan@onecht.net>
Authored: Tue Jul 7 22:55:09 2015 +0200
Committer: Daan Hoogland <daan@onecht.net>
Committed: Thu Jul 9 21:30:24 2015 +0200

----------------------------------------------------------------------
 .../resource/NfsSecondaryStorageResource.java   | 108 +++++++++----------
 1 file changed, 54 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bb2c02d1/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
index 606cc10..a529b87 100644
--- a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
@@ -495,66 +495,66 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
             String destFileFullPath = destFile.getAbsolutePath() + File.separator + fileName;
             s_logger.debug("copy snapshot " + srcFile.getAbsolutePath() + " to template "
+ destFileFullPath);
             Script.runSimpleBashScript("cp " + srcFile.getAbsolutePath() + " " + destFileFullPath);
+            String metaFileName = destFile.getAbsolutePath() + File.separator + "template.properties";
+            File metaFile = new File(metaFileName);
             try {
-                // generate template.properties file
-                String metaFileName = destFile.getAbsolutePath() + File.separator + "template.properties";
                 _storage.create(destFile.getAbsolutePath(), "template.properties");
-                File metaFile = new File(metaFileName);
-                FileWriter writer = new FileWriter(metaFile);
-                BufferedWriter bufferWriter = new BufferedWriter(writer);
-                // KVM didn't change template unique name, just used the template name passed
from orchestration layer, so no need
-                // to send template name back.
-                bufferWriter.write("uniquename=" + destData.getName());
-                bufferWriter.write("\n");
-                bufferWriter.write("filename=" + fileName);
-                bufferWriter.write("\n");
-                long size = _storage.getSize(destFileFullPath);
-                bufferWriter.write("size=" + size);
-                bufferWriter.close();
-                writer.close();
-
-                /**
-                 * Snapshots might be in either QCOW2 or RAW image format
-                 *
-                 * For example RBD snapshots are in RAW format
-                 */
-                Processor processor = null;
-                if (srcFormat == ImageFormat.QCOW2) {
-                    processor = new QCOW2Processor();
-                } else if (srcFormat == ImageFormat.RAW) {
-                    processor = new RawImageProcessor();
-                } else {
-                    throw new ConfigurationException("Unknown image format " + srcFormat.toString());
-                }
-
-                Map<String, Object> params = new HashMap<String, Object>();
-                params.put(StorageLayer.InstanceConfigKey, _storage);
-
-                processor.configure("template processor", params);
-                String destPath = destFile.getAbsolutePath();
-
-                FormatInfo info = processor.process(destPath, null, templateName);
-                TemplateLocation loc = new TemplateLocation(_storage, destPath);
-                loc.create(1, true, destData.getName());
-                loc.addFormat(info);
-                loc.save();
+                try ( // generate template.properties file
+                     FileWriter writer = new FileWriter(metaFile);
+                     BufferedWriter bufferWriter = new BufferedWriter(writer);
+                    ) {
+                    // KVM didn't change template unique name, just used the template name
passed from orchestration layer, so no need
+                    // to send template name back.
+                    bufferWriter.write("uniquename=" + destData.getName());
+                    bufferWriter.write("\n");
+                    bufferWriter.write("filename=" + fileName);
+                    bufferWriter.write("\n");
+                    long size = _storage.getSize(destFileFullPath);
+                    bufferWriter.write("size=" + size);
+
+                    /**
+                     * Snapshots might be in either QCOW2 or RAW image format
+                     *
+                     * For example RBD snapshots are in RAW format
+                     */
+                    Processor processor = null;
+                    if (srcFormat == ImageFormat.QCOW2) {
+                        processor = new QCOW2Processor();
+                    } else if (srcFormat == ImageFormat.RAW) {
+                        processor = new RawImageProcessor();
+                    } else {
+                        throw new ConfigurationException("Unknown image format " + srcFormat.toString());
+                    }
 
-                TemplateProp prop = loc.getTemplateInfo();
-                TemplateObjectTO newTemplate = new TemplateObjectTO();
-                newTemplate.setPath(destData.getPath() + File.separator + fileName);
-                newTemplate.setFormat(srcFormat);
-                newTemplate.setSize(prop.getSize());
-                newTemplate.setPhysicalSize(prop.getPhysicalSize());
-                return new CopyCmdAnswer(newTemplate);
-            } catch (ConfigurationException e) {
-                s_logger.debug("Failed to create template:" + e.toString());
-                return new CopyCmdAnswer(e.toString());
+                    Map<String, Object> params = new HashMap<String, Object>();
+                    params.put(StorageLayer.InstanceConfigKey, _storage);
+
+                    processor.configure("template processor", params);
+                    String destPath = destFile.getAbsolutePath();
+
+                    FormatInfo info = processor.process(destPath, null, templateName);
+                    TemplateLocation loc = new TemplateLocation(_storage, destPath);
+                    loc.create(1, true, destData.getName());
+                    loc.addFormat(info);
+                    loc.save();
+
+                    TemplateProp prop = loc.getTemplateInfo();
+                    TemplateObjectTO newTemplate = new TemplateObjectTO();
+                    newTemplate.setPath(destData.getPath() + File.separator + fileName);
+                    newTemplate.setFormat(srcFormat);
+                    newTemplate.setSize(prop.getSize());
+                    newTemplate.setPhysicalSize(prop.getPhysicalSize());
+                    return new CopyCmdAnswer(newTemplate);
+                } catch (ConfigurationException e) {
+                    s_logger.debug("Failed to create template:" + e.toString());
+                    return new CopyCmdAnswer(e.toString());
+                } catch (InternalErrorException e) {
+                    s_logger.debug("Failed to create template:" + e.toString());
+                    return new CopyCmdAnswer(e.toString());
+                }
             } catch (IOException e) {
                 s_logger.debug("Failed to create template:" + e.toString());
                 return new CopyCmdAnswer(e.toString());
-            } catch (InternalErrorException e) {
-                s_logger.debug("Failed to create template:" + e.toString());
-                return new CopyCmdAnswer(e.toString());
             }
         }
 


Mime
View raw message