Make file append mode observable and persistent

This commit is contained in:
Nanaloveyuki
2026-05-10 12:35:15 +08:00
parent 12730fded8
commit b6673c66e4
8 changed files with 48 additions and 6 deletions
+8 -3
View File
@@ -46,7 +46,7 @@ pub impl Sink for JsonConsoleSink with write(self, rec) {
pub struct FileSink {
path : String
append : Bool
append : Ref[Bool]
handle : Ref[FileHandle?]
formatter : RecordFormatter
auto_flush : Bool
@@ -85,7 +85,7 @@ pub fn file_sink(
let handle = open_file_handle_internal(path, append)
{
path,
append,
append: Ref::new(append),
handle: Ref::new(handle),
formatter,
auto_flush,
@@ -114,6 +114,10 @@ pub fn FileSink::flush(self : FileSink) -> Bool {
}
}
pub fn FileSink::append_mode(self : FileSink) -> Bool {
self.append.val
}
pub fn FileSink::close(self : FileSink) -> Bool {
match self.handle.val {
None => false
@@ -142,7 +146,8 @@ pub fn FileSink::flush_failures(self : FileSink) -> Int {
}
pub fn FileSink::reopen(self : FileSink, append~ : Bool? = None) -> Bool {
let append_mode = append.unwrap_or(self.append)
let append_mode = append.unwrap_or(self.append.val)
self.append.val = append_mode
match self.handle.val {
None => ()
Some(handle) => {