summaryrefslogtreecommitdiff
path: root/core/src/file.vala
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-10-15 15:30:04 +0200
committerGitHub <[email protected]>2024-10-15 15:30:04 +0200
commitcbe650afb31c24faea6da45b4aeeffc6e964969d (patch)
treed5c3788835ca7e50d68cd023026e7738f39f6f71 /core/src/file.vala
parentbdb23e20f171da7c769cba9e393d7e406e563a78 (diff)
parentbafd48d3df9b43a1d49ec015eff30619d595468b (diff)
Merge pull request #46 from Aylur/small-refactor
Small refactor
Diffstat (limited to 'core/src/file.vala')
-rw-r--r--core/src/file.vala81
1 files changed, 0 insertions, 81 deletions
diff --git a/core/src/file.vala b/core/src/file.vala
deleted file mode 100644
index d8acccc..0000000
--- a/core/src/file.vala
+++ /dev/null
@@ -1,81 +0,0 @@
-namespace Astal {
-public string read_file(string path) {
- var str = "";
- try {
- FileUtils.get_contents(path, out str, null);
- } catch (Error error) {
- critical(error.message);
- }
- return str;
-}
-
-public async string read_file_async(string path) throws Error {
- uint8[] content;
- yield File.new_for_path(path).load_contents_async(null, out content, null);
- return (string)content;
-}
-
-public void write_file(string path, string content) {
- try {
- FileUtils.set_contents(path, content);
- } catch (Error error) {
- critical(error.message);
- }
-}
-
-public async void write_file_async(string path, string content) throws Error {
- yield File.new_for_path(path).replace_contents_async(
- content.data,
- null,
- false,
- GLib.FileCreateFlags.REPLACE_DESTINATION,
- null,
- null);
-}
-
-public FileMonitor? monitor_file(string path, Closure callback) {
- try {
- var file = File.new_for_path(path);
- var mon = file.monitor(GLib.FileMonitorFlags.NONE);
-
- mon.changed.connect((file, _file, event) => {
- var f = Value(Type.STRING);
- var e = Value(Type.INT);
- var ret = Value(Type.POINTER);
-
- f.set_string(file.get_path());
- e.set_int(event);
-
- callback.invoke(ref ret, { f, e });
- });
-
- if (FileUtils.test(path, FileTest.IS_DIR)) {
- var enumerator = file.enumerate_children("standard::*",
- FileQueryInfoFlags.NONE, null);
-
- var i = enumerator.next_file(null);
- while (i != null) {
- if (i.get_file_type() == FileType.DIRECTORY) {
- var filepath = file.get_child(i.get_name()).get_path();
- if (filepath != null) {
- var m = monitor_file(path, callback);
- mon.notify["cancelled"].connect(() => {
- m.cancel();
- });
- }
- }
- i = enumerator.next_file(null);
- }
- }
-
- mon.ref();
- mon.notify["cancelled"].connect(() => {
- mon.unref();
- });
- return mon;
- } catch (Error error) {
- critical(error.message);
- return null;
- }
-}
-}