summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavfsa <[email protected]>2025-03-03 02:38:00 +0100
committerGitHub <[email protected]>2025-03-03 02:38:00 +0100
commit4b283b0045c0752c36c6e8306fc137f2c9f244a4 (patch)
treec79fc8228b68ef1afd71181e5281b12d9bb49324
parent23cdbc8088b5c308a068b432a6b03213ede68f07 (diff)
feat: follow symlinks in file write and monitor functions (#303)
-rw-r--r--lib/astal/io/file.vala22
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/astal/io/file.vala b/lib/astal/io/file.vala
index e8e8a8b..a1e773c 100644
--- a/lib/astal/io/file.vala
+++ b/lib/astal/io/file.vala
@@ -31,7 +31,14 @@ public void write_file(string path, string content) {
File.new_for_path(dir).make_directory_with_parents(null);
}
- FileUtils.set_contents(path, content);
+ File.new_for_path(path).replace_contents(
+ content.data,
+ null,
+ false,
+ FileCreateFlags.NONE,
+ null,
+ null
+ );
} catch (Error error) {
critical(error.message);
}
@@ -50,9 +57,10 @@ public async void write_file_async(string path, string content) throws Error {
content.data,
null,
false,
- FileCreateFlags.REPLACE_DESTINATION,
+ FileCreateFlags.NONE,
null,
- null);
+ null
+ );
}
/**
@@ -63,7 +71,11 @@ public async void write_file_async(string path, string content) throws Error {
public FileMonitor? monitor_file(string path, Closure callback) {
try {
var file = File.new_for_path(path);
- var mon = file.monitor(FileMonitorFlags.NONE);
+ var mon = file.monitor(
+ FileMonitorFlags.WATCH_HARD_LINKS |
+ FileMonitorFlags.WATCH_MOUNTS |
+ FileMonitorFlags.WATCH_MOVES
+ );
mon.changed.connect((file, _file, event) => {
var f = Value(Type.STRING);
@@ -85,7 +97,7 @@ public FileMonitor? monitor_file(string path, Closure callback) {
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);
+ var m = monitor_file(filepath, callback);
mon.notify["cancelled"].connect(() => {
m.cancel();
});