hjfs: update mtime and qid.vers for directory on rename

when wstating a file, its directory should be updated to
reflect this change.

here is what the manpage states:

> The mtime field reflects the time of the last change of content
> (except when later changed by wstat). For a directory it is the
> time of the most recent remove, create, or wstat of a file in the
> directory.
This commit is contained in:
cinap_lenrek 2020-07-12 18:54:22 +02:00
parent a469cffafe
commit 2c8c2bc727
3 changed files with 19 additions and 13 deletions

View file

@ -41,7 +41,7 @@ int haveloc(Fs *, uvlong, int, Loc *);
Loc * cloneloc(Fs *, Loc *); Loc * cloneloc(Fs *, Loc *);
void putloc(Fs *, Loc *, int); void putloc(Fs *, Loc *, int);
int findentry(Fs *, FLoc *, Buf *, char *, FLoc *, int); int findentry(Fs *, FLoc *, Buf *, char *, FLoc *, int);
void modified(Chan *, Dentry *); void modified(Loc *, Dentry *, short);
int trunc(Fs *, FLoc *, Buf *, uvlong); int trunc(Fs *, FLoc *, Buf *, uvlong);
int dprint(char *fmt, ...); int dprint(char *fmt, ...);
int delete(Fs *, FLoc *, Buf *); int delete(Fs *, FLoc *, Buf *);

View file

@ -849,12 +849,12 @@ findentry(Fs *fs, FLoc *l, Buf *b, char *name, FLoc *rl, int dump)
} }
void void
modified(Chan *ch, Dentry *d) modified(Loc *loc, Dentry *d, short uid)
{ {
d->mtime = time(0); d->mtime = time(0);
d->atime = d->mtime; d->atime = d->mtime;
d->muid = ch->uid; d->muid = uid;
ch->loc->vers = ++d->vers; loc->vers = ++d->vers;
} }
typedef struct Del Del; typedef struct Del Del;

View file

@ -149,7 +149,7 @@ chancreat(Chan *ch, char *name, int perm, int mode)
if(newqid(ch->fs, &f.path) < 0) if(newqid(ch->fs, &f.path) < 0)
goto error; goto error;
l = getloc(ch->fs, f, ch->loc); l = getloc(ch->fs, f, ch->loc);
modified(ch, d); modified(ch->loc, d, ch->uid);
b->op |= BDELWRI; b->op |= BDELWRI;
pgid = d->gid; pgid = d->gid;
putbuf(b); putbuf(b);
@ -273,7 +273,7 @@ chanopen(Chan *ch, int mode)
} }
if((mode & OTRUNC) != 0){ if((mode & OTRUNC) != 0){
trunc(ch->fs, ch->loc, b, 0); trunc(ch->fs, ch->loc, b, 0);
modified(ch, d); modified(ch->loc, d, ch->uid);
b->op |= BDELWRI; b->op |= BDELWRI;
} }
if((mode & ORCLOSE) != 0) if((mode & ORCLOSE) != 0)
@ -380,7 +380,7 @@ chanwrite(Chan *ch, void *buf, ulong n, uvlong off)
p += rn; p += rn;
} }
done: done:
modified(ch, d); modified(ch->loc, d, ch->uid);
e = off + (p - (uchar *) buf); e = off + (p - (uchar *) buf);
if(e > d->size) if(e > d->size)
d->size = e; d->size = e;
@ -679,7 +679,7 @@ int
chanwstat(Chan *ch, Dir *di) chanwstat(Chan *ch, Dir *di)
{ {
Buf *b, *pb; Buf *b, *pb;
Dentry *d; Dentry *d, *pd;
int isdir, owner, rc; int isdir, owner, rc;
short nuid, ngid; short nuid, ngid;
@ -689,23 +689,26 @@ chanwstat(Chan *ch, Dir *di)
goto inval; goto inval;
if(willmodify(ch->fs, ch->loc, ch->flags & CHFNOLOCK) < 0) if(willmodify(ch->fs, ch->loc, ch->flags & CHFNOLOCK) < 0)
goto error; goto error;
pd = nil;
if(*di->name){ if(*di->name){
FLoc f; FLoc f;
if(!namevalid(di->name) || ch->loc->next == nil) if(!namevalid(di->name) || ch->loc->next == nil)
goto inval; goto inval;
if(willmodify(ch->fs, ch->loc->next, ch->flags & CHFNOLOCK) < 0)
goto error;
pb = getbuf(ch->fs->d, ch->loc->next->blk, TDENTRY, 0); pb = getbuf(ch->fs->d, ch->loc->next->blk, TDENTRY, 0);
if(pb == nil) if(pb == nil)
goto error; goto error;
d = getdent(ch->loc->next, pb); pd = getdent(ch->loc->next, pb);
if(d == nil) if(pd == nil)
goto error; goto error;
rc = findentry(ch->fs, ch->loc->next, pb, di->name, &f, ch->flags & CHFDUMP); rc = findentry(ch->fs, ch->loc->next, pb, di->name, &f, ch->flags & CHFDUMP);
if(rc < 0) if(rc < 0)
goto error; goto error;
else if(rc == 0){ else if(rc == 0){
if((ch->flags & CHFNOPERM) == 0) if((ch->flags & CHFNOPERM) == 0)
if(!permcheck(ch->fs, d, ch->uid, OWRITE)) if(!permcheck(ch->fs, pd, ch->uid, OWRITE))
goto perm; goto perm;
} else if(f.blk != ch->loc->blk || f.deind != ch->loc->deind){ } else if(f.blk != ch->loc->blk || f.deind != ch->loc->deind){
werrstr(Eexists); werrstr(Eexists);
@ -748,7 +751,7 @@ chanwstat(Chan *ch, Dir *di)
d->gid = ngid; d->gid = ngid;
if(di->length != ~0 && di->length != d->size && !isdir){ if(di->length != ~0 && di->length != d->size && !isdir){
trunc(ch->fs, ch->loc, b, di->length); trunc(ch->fs, ch->loc, b, di->length);
modified(ch, d); modified(ch->loc, d, ch->uid);
} }
if(di->mtime != ~0) if(di->mtime != ~0)
d->mtime = di->mtime; d->mtime = di->mtime;
@ -761,8 +764,11 @@ chanwstat(Chan *ch, Dir *di)
strcpy(d->name, di->name); strcpy(d->name, di->name);
} }
b->op |= BDELWRI; b->op |= BDELWRI;
if(pb != nil) if(pb != nil){
modified(ch->loc->next, pd, ch->uid);
pb->op |= BDELWRI;
putbuf(pb); putbuf(pb);
}
putbuf(b); putbuf(b);
chend(ch); chend(ch);
return 1; return 1;