diff options
author | Russ Cox <rsc@swtch.com> | 2017-10-10 13:49:37 -0400 |
---|---|---|
committer | Russ Cox <rsc@swtch.com> | 2017-10-10 13:51:24 -0400 |
commit | 67dbeee5fe9e2a855384048615bafe100e876f4c (patch) | |
tree | f5e2960b2bf7abcc774678b65f947aac792c7fd0 /src/cmd/acme/text.c | |
parent | 680c57a15c51c302d89aec134e25f08820d3f30d (diff) | |
download | plan9port-67dbeee5fe9e2a855384048615bafe100e876f4c.tar.gz plan9port-67dbeee5fe9e2a855384048615bafe100e876f4c.tar.bz2 plan9port-67dbeee5fe9e2a855384048615bafe100e876f4c.zip |
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.)
Diffstat (limited to 'src/cmd/acme/text.c')
-rw-r--r-- | src/cmd/acme/text.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/cmd/acme/text.c b/src/cmd/acme/text.c index c53694c6..4832de8e 100644 --- a/src/cmd/acme/text.c +++ b/src/cmd/acme/text.c @@ -8,6 +8,7 @@ #include <frame.h> #include <fcall.h> #include <plumb.h> +#include <libsec.h> #include <complete.h> #include "dat.h" #include "fns.h" @@ -198,6 +199,7 @@ textload(Text *t, uint q0, char *file, int setqid) Dir *d, *dbuf; char *tmp; Text *u; + DigestState *h; if(t->ncache!=0 || t->file->b.nc || t->w==nil || t!=&t->w->body) error("text.load"); @@ -220,6 +222,7 @@ textload(Text *t, uint q0, char *file, int setqid) goto Rescue; } nulls = FALSE; + h = nil; if(d->qid.type & QTDIR){ /* this is checked in get() but it's possible the file changed underfoot */ if(t->file->ntext > 1){ @@ -264,9 +267,17 @@ textload(Text *t, uint q0, char *file, int setqid) }else{ t->w->isdir = FALSE; t->w->filemenu = TRUE; - q1 = q0 + fileload(t->file, q0, fd, &nulls); + if(q0 == 0) + h = sha1(nil, 0, nil, nil); + q1 = q0 + fileload(t->file, q0, fd, &nulls, h); } if(setqid){ + if(h != nil) { + sha1(nil, 0, t->file->sha1, h); + h = nil; + } else { + memset(t->file->sha1, 0, sizeof t->file->sha1); + } t->file->dev = d->dev; t->file->mtime = d->mtime; t->file->qidpath = d->qid.path; |