summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-01-03 23:09:32 -0500
committerpommicket <pommicket@gmail.com>2023-01-03 23:09:32 -0500
commitadabc989a118190a4dc7e85315b5a337b806b314 (patch)
tree0b73bdc55201ce5a38bd8c4c6a79288014775131
parentaa4f61bcaeaa7c3c028ac98a3206b41eedb59fd7 (diff)
fix problem when file is modified while it's read into the buffer.
before, the file wouldn't be reloaded properly
-rw-r--r--buffer.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/buffer.c b/buffer.c
index 0d372fc..d34b6da 100644
--- a/buffer.c
+++ b/buffer.c
@@ -2283,6 +2283,10 @@ void buffer_paste(TextBuffer *buffer) {
// if an error occurs, buffer is left untouched (except for the error field) and the function returns false.
Status buffer_load_file(TextBuffer *buffer, const char *filename) {
+ // it's important we do this first, since someone might write to the file while we're reading it,
+ // and we want to detect that in buffer_externally_changed
+ double modified_time = timespec_to_seconds(time_last_modified(buffer->filename));
+
FILE *fp = fopen(filename, "rb");
bool success = true;
Line *lines = NULL;
@@ -2368,7 +2372,7 @@ Status buffer_load_file(TextBuffer *buffer, const char *filename) {
buffer->frame_latest_line_modified = nlines - 1;
buffer->lines_capacity = lines_capacity;
buffer->filename = filename_copy;
- buffer->last_write_time = timespec_to_seconds(time_last_modified(buffer->filename));
+ buffer->last_write_time = modified_time;
if (!(fs_path_permission(filename) & FS_PERMISSION_WRITE)) {
// can't write to this file; make the buffer view only.
buffer->view_only = true;