diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:54:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:54:43 +0000 |
commit | e4283f6d48b98e764b988b43bbc86b9d52e6ec94 (patch) | |
tree | c8f7f7a6c2f5faa2942d27cefc6fd46cca492656 /js/misc/fileUtils.js | |
parent | Initial commit. (diff) | |
download | gnome-shell-e4283f6d48b98e764b988b43bbc86b9d52e6ec94.tar.xz gnome-shell-e4283f6d48b98e764b988b43bbc86b9d52e6ec94.zip |
Adding upstream version 43.9.upstream/43.9upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/misc/fileUtils.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/js/misc/fileUtils.js b/js/misc/fileUtils.js new file mode 100644 index 0000000..a6bb182 --- /dev/null +++ b/js/misc/fileUtils.js @@ -0,0 +1,68 @@ +// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- +/* exported collectFromDatadirs, recursivelyDeleteDir, + recursivelyMoveDir, loadInterfaceXML, loadSubInterfaceXML */ + +const { Gio, GLib } = imports.gi; + +var { loadInterfaceXML } = imports.misc.dbusUtils; + +function collectFromDatadirs(subdir, includeUserDir, processFile) { + let dataDirs = GLib.get_system_data_dirs(); + if (includeUserDir) + dataDirs.unshift(GLib.get_user_data_dir()); + + for (let i = 0; i < dataDirs.length; i++) { + let path = GLib.build_filenamev([dataDirs[i], 'gnome-shell', subdir]); + let dir = Gio.File.new_for_path(path); + + let fileEnum; + try { + fileEnum = dir.enumerate_children('standard::name,standard::type', + Gio.FileQueryInfoFlags.NONE, null); + } catch (e) { + fileEnum = null; + } + if (fileEnum != null) { + let info; + while ((info = fileEnum.next_file(null))) + processFile(fileEnum.get_child(info), info); + } + } +} + +function recursivelyDeleteDir(dir, deleteParent) { + let children = dir.enumerate_children('standard::name,standard::type', + Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null); + + let info; + while ((info = children.next_file(null)) != null) { + let type = info.get_file_type(); + let child = dir.get_child(info.get_name()); + if (type == Gio.FileType.REGULAR) + child.delete(null); + else if (type == Gio.FileType.DIRECTORY) + recursivelyDeleteDir(child, true); + } + + if (deleteParent) + dir.delete(null); +} + +function recursivelyMoveDir(srcDir, destDir) { + let children = srcDir.enumerate_children('standard::name,standard::type', + Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null); + + if (!destDir.query_exists(null)) + destDir.make_directory_with_parents(null); + + let info; + while ((info = children.next_file(null)) != null) { + let type = info.get_file_type(); + let srcChild = srcDir.get_child(info.get_name()); + let destChild = destDir.get_child(info.get_name()); + if (type == Gio.FileType.REGULAR) + srcChild.move(destChild, Gio.FileCopyFlags.NONE, null, null); + else if (type == Gio.FileType.DIRECTORY) + recursivelyMoveDir(srcChild, destChild); + } +} |