Store all temp files in app named temp subdirectory

This commit is contained in:
Rafał Dzięgiel
2021-03-17 11:57:02 +01:00
parent 4021745a56
commit fcff4b4450
2 changed files with 18 additions and 12 deletions

View File

@@ -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),

View File

@@ -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));
});
}