Skip to content

Commit e8608c8

Browse files
committed
Ensure that directory for individual files being saved exists before attempting to save file
1 parent 3637293 commit e8608c8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

app/renderer/inkFile.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const assert = require("assert");
44

55
const remote = require('electron').remote;
66
const dialog = remote.dialog;
7+
const mkdirp = require('mkdirp');
78

89
const InkFileSymbols = require("./inkFileSymbols.js").InkFileSymbols;
910

@@ -172,7 +173,12 @@ InkFile.prototype.save = function(afterSaveCallback) {
172173
var fileContent = this.aceDocument.getValue();
173174
if( !fileContent || fileContent.length < 1 ) throw "Empty file content in aceDocument!";
174175

175-
fs.writeFile(this.absolutePath(), fileContent, "utf8", (err) => {
176+
// Ensure that the enclosing folder exists beforehand
177+
var fileAbsPath = this.absolutePath();
178+
var fileDirectory = path.dirname(fileAbsPath);
179+
mkdirp.sync(fileDirectory);
180+
181+
fs.writeFile(fileAbsPath, fileContent, "utf8", (err) => {
176182
this.brandNewEmpty = false;
177183
if( err )
178184
afterSaveCallback(false);

0 commit comments

Comments
 (0)