2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
import GLib from 'gi://GLib';
|
|
|
|
import Gio from 'gi://Gio';
|
2022-07-05 07:25:02 +00:00
|
|
|
|
2023-08-07 15:13:48 +00:00
|
|
|
export {loadInterfaceXML} from './dbusUtils.js';
|
2010-09-30 21:08:22 +00:00
|
|
|
|
2022-11-30 02:17:20 +00:00
|
|
|
/**
|
|
|
|
* @typedef {object} SubdirInfo
|
|
|
|
* @property {Gio.File} dir the file object for the subdir
|
|
|
|
* @property {Gio.FileInfo} info the file descriptor for the subdir
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} subdir the subdirectory to search within the data directories
|
|
|
|
* @param {boolean} includeUserDir whether the user's data directory should also be searched in addition
|
|
|
|
* to the system data directories
|
|
|
|
* @returns {Generator<SubdirInfo, void, void>} a generator which yields file info for subdirectories named
|
|
|
|
* `subdir` within data directories
|
|
|
|
*/
|
2023-07-10 09:53:00 +00:00
|
|
|
export function* collectFromDatadirs(subdir, includeUserDir) {
|
2012-11-30 15:36:12 +00:00
|
|
|
let dataDirs = GLib.get_system_data_dirs();
|
2013-11-04 15:07:44 +00:00
|
|
|
if (includeUserDir)
|
2012-11-30 15:36:12 +00:00
|
|
|
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);
|
|
|
|
|
2013-11-04 15:07:44 +00:00
|
|
|
let fileEnum;
|
|
|
|
try {
|
|
|
|
fileEnum = dir.enumerate_children('standard::name,standard::type',
|
2022-11-30 02:17:20 +00:00
|
|
|
Gio.FileQueryInfoFlags.NONE, null);
|
2013-11-04 15:07:44 +00:00
|
|
|
} catch (e) {
|
|
|
|
fileEnum = null;
|
|
|
|
}
|
|
|
|
if (fileEnum != null) {
|
|
|
|
let info;
|
|
|
|
while ((info = fileEnum.next_file(null)))
|
2022-11-30 02:17:20 +00:00
|
|
|
yield {dir: fileEnum.get_child(info), info};
|
2013-11-04 15:07:44 +00:00
|
|
|
}
|
2012-11-30 15:36:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-30 12:56:59 +00:00
|
|
|
/**
|
|
|
|
* @param {Gio.File} dir
|
|
|
|
* @param {boolean} deleteParent
|
|
|
|
*/
|
2023-07-10 09:53:00 +00:00
|
|
|
export function recursivelyDeleteDir(dir, deleteParent) {
|
2011-09-10 21:10:50 +00:00
|
|
|
let children = dir.enumerate_children('standard::name,standard::type',
|
2022-12-05 12:56:57 +00:00
|
|
|
Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
|
2011-09-10 21:10:50 +00:00
|
|
|
|
2019-01-31 14:04:56 +00:00
|
|
|
let info;
|
2011-09-10 21:10:50 +00:00
|
|
|
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)
|
2019-11-25 21:54:44 +00:00
|
|
|
child.delete(null);
|
2011-12-01 02:46:52 +00:00
|
|
|
else if (type == Gio.FileType.DIRECTORY)
|
2012-06-27 00:47:44 +00:00
|
|
|
recursivelyDeleteDir(child, true);
|
2011-09-10 21:10:50 +00:00
|
|
|
}
|
|
|
|
|
2012-06-27 00:47:44 +00:00
|
|
|
if (deleteParent)
|
2019-11-25 21:54:44 +00:00
|
|
|
dir.delete(null);
|
2012-06-27 00:47:44 +00:00
|
|
|
}
|
|
|
|
|
2023-07-30 12:56:59 +00:00
|
|
|
/**
|
|
|
|
* @param {Gio.File} srcDir
|
|
|
|
* @param {Gio.File} destDir
|
|
|
|
*/
|
2023-07-10 09:53:00 +00:00
|
|
|
export function recursivelyMoveDir(srcDir, destDir) {
|
2012-06-27 00:47:44 +00:00
|
|
|
let children = srcDir.enumerate_children('standard::name,standard::type',
|
2022-12-05 12:56:57 +00:00
|
|
|
Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
|
2012-06-27 00:47:44 +00:00
|
|
|
|
|
|
|
if (!destDir.query_exists(null))
|
|
|
|
destDir.make_directory_with_parents(null);
|
|
|
|
|
2019-01-31 14:04:56 +00:00
|
|
|
let info;
|
2012-06-27 00:47:44 +00:00
|
|
|
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);
|
|
|
|
}
|
2011-09-10 21:10:50 +00:00
|
|
|
}
|