mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-29 23:32:04 +02:00
Store all temp files in app named temp subdirectory
This commit is contained in:
12
src/dash.js
12
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),
|
||||
|
@@ -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));
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user