diff --git a/src/dash.js b/src/dash.js index 36a9fa65..26b8650d 100644 --- a/src/dash.js +++ b/src/dash.js @@ -1,5 +1,6 @@ const { Gio, GLib } = imports.gi; const Debug = imports.src.debug; +const FileOps = imports.src.fileOps; const Misc = imports.src.misc; const { debug } = Debug; @@ -45,11 +46,14 @@ function generateDash(info) function saveDashPromise(dash) { - return new Promise((resolve, reject) => { - const tempPath = GLib.get_tmp_dir() + '/.clapper.mpd'; - const dashFile = Gio.File.new_for_path(tempPath); + debug('saving dash file'); - debug('saving dash file'); + return new Promise(async (resolve, reject) => { + const tempDir = await FileOps.createTempDirPromise().catch(debug); + if(!tempDir) + return reject(new Error('could not create folder in temp directory')); + + const dashFile = tempDir.get_child('.clapper.mpd'); dashFile.replace_contents_bytes_async( GLib.Bytes.new_take(dash), diff --git a/src/fileOps.js b/src/fileOps.js index d452d76b..7d3dd9bb 100644 --- a/src/fileOps.js +++ b/src/fileOps.js @@ -18,7 +18,7 @@ function createCacheDirPromise() function createTempDirPromise() { const dir = Gio.File.new_for_path( - GLib.get_tmp_dir() + '/.' + Misc.appId + GLib.get_tmp_dir() + '/' + Misc.appId ); return createDirPromise(dir); @@ -26,18 +26,20 @@ function createTempDirPromise() function createDirPromise(dir) { - return new Promise(async (resolve, reject) => { + return new Promise((resolve, reject) => { if(dir.query_exists(null)) return resolve(dir); - const dirCreated = await dir.make_directory_async( + dir.make_directory_async( GLib.PRIORITY_DEFAULT, null, - ).catch(debug); + ) + .then(success => { + if(success) + return resolve(dir); - if(!dirCreated) - return reject(new Error(`could not create dir: ${dir.get_path()}`)); - - resolve(dir); + reject(new Error(`could not create dir: ${dir.get_path()}`)); + }) + .catch(err => reject(err)); }); }