Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/530#discussion_r25697825
  
    --- Diff: 
software/database/src/main/java/brooklyn/entity/database/mysql/MySqlSshDriver.java
 ---
    @@ -186,9 +192,20 @@ protected void copyDatabaseConfigScript() {
         }
     
         protected boolean copyDatabaseCreationScript() {
    -        InputStream creationScript = 
DatastoreMixins.getDatabaseCreationScript(entity);
    -        if (creationScript==null) return false;
    -        getMachine().copyTo(creationScript, getRunDir() + 
"/creation-script.sql");
    +        String creationScriptContents = 
DatastoreMixins.getDatabaseCreationScriptAsString(entity);
    +        if (creationScriptContents==null) return false;
    +
    +        File templateFile;
    +        try {
    +            templateFile = File.createTempFile("mysql", null);
    +            templateFile.deleteOnExit();
    +            BufferedWriter writer = new BufferedWriter(new 
FileWriter(templateFile));
    +            writer.write (creationScriptContents);
    +        } catch (IOException e) {
    +            throw Exceptions.propagate(e);
    +        }
    +        copyTemplate(templateFile.getAbsoluteFile(), getRunDir() + 
"/creation-script.sql");
    +        templateFile.delete();
    --- End diff --
    
    Personally I'd have put the `copyTemplate` inside the try block, and the 
`templateFile.delete()` in a finally block.
    Another slight concern about this approach is that the file permission 
could mean the file is readable by others for the brief time it exists - if the 
sql script contained any passwords, that would not be good.
    
    However, I don't feel strongly enough about this to delay the PR. Happy to 
merge.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to