diff options
author | pommicket <pommicket@gmail.com> | 2025-06-15 23:43:03 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2025-06-15 23:43:23 -0400 |
commit | 21eb7b3790b843b7e4db6c2ac2acedbb5c78eee5 (patch) | |
tree | 6b33a98d0edbc0e4084a54056d5ae5a4b754f2ab /buffer.c | |
parent | 100a4286688d6627698f857333a37ddec1f12d4a (diff) |
block until whatever program is writing the file finishes
Diffstat (limited to 'buffer.c')
-rw-r--r-- | buffer.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -3192,7 +3192,21 @@ void buffer_reload(TextBuffer *buffer) { bool buffer_externally_changed(TextBuffer *buffer) { if (!buffer_is_named_file(buffer)) return false; - return buffer->last_write_time != timespec_to_seconds(time_last_modified(buffer->path)); + double last_modified = timespec_to_seconds(time_last_modified(buffer->path)); + if (last_modified == buffer->last_write_time) + return false; + + // block until whatever program is writing the file finishes + for (int i = 0; i < 10; i++) { // give up after 200ms + time_sleep_ms(20); + double new_last_modified = timespec_to_seconds(time_last_modified(buffer->path)); + if (new_last_modified == last_modified) { + // probably done now + break; + } + last_modified = new_last_modified; + } + return true; } void buffer_new_file(TextBuffer *buffer, const char *path) { |