From 67dbeee5fe9e2a855384048615bafe100e876f4c Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 10 Oct 2017 13:49:37 -0400 Subject: acme: check file content before declaring file "modified since last read" Bad remote file systems can change mtime unexpectedly, and then there is the problem that git rebase and similar operations like to change the files and then change them back, modifying the mtimes but not the content. Avoid spurious Put errors on both of those by checking file content. (False positive "modified since last read" make the real ones difficult to notice.) --- src/cmd/acme/buff.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/cmd/acme/buff.c') diff --git a/src/cmd/acme/buff.c b/src/cmd/acme/buff.c index 875bb0b0..bb938ca4 100644 --- a/src/cmd/acme/buff.c +++ b/src/cmd/acme/buff.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "dat.h" #include "fns.h" @@ -231,7 +232,7 @@ bufloader(void *v, uint q0, Rune *r, int nr) } uint -loadfile(int fd, uint q0, int *nulls, int(*f)(void*, uint, Rune*, int), void *arg) +loadfile(int fd, uint q0, int *nulls, int(*f)(void*, uint, Rune*, int), void *arg, DigestState *h) { char *p; Rune *r; @@ -253,6 +254,8 @@ loadfile(int fd, uint q0, int *nulls, int(*f)(void*, uint, Rune*, int), void *ar warning(nil, "read error in Buffer.load"); break; } + if(h != nil) + sha1((uchar*)p+m, n, nil, h); m += n; p[m] = 0; l = m; @@ -269,11 +272,11 @@ loadfile(int fd, uint q0, int *nulls, int(*f)(void*, uint, Rune*, int), void *ar } uint -bufload(Buffer *b, uint q0, int fd, int *nulls) +bufload(Buffer *b, uint q0, int fd, int *nulls, DigestState *h) { if(q0 > b->nc) error("internal error: bufload"); - return loadfile(fd, q0, nulls, bufloader, b); + return loadfile(fd, q0, nulls, bufloader, b, h); } void -- cgit v1.2.3