Forked from trisharia/createTemporaryFileInVro.js
Last active
August 2, 2022 05:55
-
-
Save imtrinity94/2f27e640f3c8f2ee2499622016cc2a91 to your computer and use it in GitHub Desktop.
Create a temporary text-based file on the vRO server, which can then be copied elsewhere like a guest vCenter VM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @module actions.mayank.goyal | |
* @name createTemporaryFileInVro | |
* @version 1.0.0 | |
* @description Create a temporary text-based file, in a temporary directory, on the vRO server | |
* @param {string} fileContents | |
* @param {string} fileName | |
* | |
* @outputType string | |
* | |
*/ | |
function createTemporaryFileInVro(fileContents, fileName) { | |
var tempDir = System.getTempDirectory(); | |
vroTempFileFullPath = tempDir + "/" + fileName; | |
var writer; | |
try { | |
writer = new FileWriter(vroTempFileFullPath); | |
} catch (e) { | |
throw "Failed to create temp file in vRO server: " + vroTempFileFullPath + " :: " + e; | |
} | |
try { | |
writer.open(); | |
} catch (e) { | |
throw "Failed to open temp file for editing in vRO server: " + vroTempFileFullPath + " :: " + e; | |
} | |
try { | |
writer.write(fileContents); | |
} catch (e) { | |
throw "Failed to write contents to temp file in vRO server: " + vroTempFileFullPath + " :: " + e; | |
} | |
try { | |
writer.close(); | |
System.debug("Contents written to vRO temp file " + vroTempFileFullPath + " successfully."); | |
} catch (e) { | |
throw "Failed to close temp file after editing in vRO server: " + vroTempFileFullPath + " :: " + e; | |
} | |
return vroTempFileFullPath; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment