Skip to content

Commit 7826298

Browse files
committed
util: Add createTmpDir function
This function will allow to create temporary directory. This will allow, for instance, meson to create a builddir that will not be stored inside a session.
1 parent 7172d06 commit 7826298

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/util.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,25 @@ export async function copy(filename, source_dir, dest_dir, flags) {
211211

212212
return dest_file;
213213
}
214+
215+
const tmp_dirs = {};
216+
217+
export async function createTmpDir(filename) {
218+
if (filename in tmp_dirs) {
219+
return tmp_dirs[filename];
220+
}
221+
222+
const tmp_dir = Gio.File.new_for_path(
223+
GLib.build_filenamev([GLib.get_tmp_dir(), filename]),
224+
);
225+
226+
try {
227+
tmp_dir.make_directory(null);
228+
tmp_dirs[filename] = tmp_dir;
229+
} catch (err) {
230+
console.error(err);
231+
return null;
232+
}
233+
234+
return tmp_dir;
235+
}

0 commit comments

Comments
 (0)