ref: 4f4d71b941e568b158da73978e25105b94afd7fd
parent: c1dc5d15c374c34395af92e002f064cd3e9ce5dc
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Sep 29 17:01:51 EDT 2014
hgfs: make data files with meta headers having the right size after open to get the right data size of a file, the revlog needs to have been opened and the metaheader parsed. as an optimization, we used to open revlog only on the first read resulting revlogs with metaheaders having the wrong size returned by fstat() until the first read(). tar relies on fstat() giving the correct file size, so just open the revlog on open. reading directories can still yield the wrong size but it is not that critical.
--- a/sys/src/cmd/hgfs/fs.c
+++ b/sys/src/cmd/hgfs/fs.c
@@ -606,6 +606,19 @@
if(rf->node == nil || rf->node->mode != 'x')
break;
case OREAD:
+ if(rf->level == Qlog){
+ if((rf->fd = revlogopentemp(&changelog, hashrev(&changelog, rf->info->chash))) < 0){
+ responderror(r);
+ return;
+ }
+ rf->doff = rf->info->logoff;
+ } else if(rf->level == Qtree && rf->node->down == nil){
+ if((rf->fd = revlogopentemp(rf->rlog, hashrev(rf->rlog, rf->node->hash))) < 0){
+ responderror(r);
+ return;
+ }
+ rf->doff = fmetaheader(rf->fd);
+ }
respond(r, nil);
return;
}
@@ -697,13 +710,6 @@
len = 0;
else if((off + len) >= rf->info->loglen)
len = rf->info->loglen - off;
- if(rf->fd >= 0)
- goto Fdgen;
- if((rf->fd = revlogopentemp(&changelog, hashrev(&changelog, rf->info->chash))) < 0){
- responderror(r);
- return;
- }
- rf->doff = rf->info->logoff;
goto Fdgen;
case Qwho:
s = rf->info->who;
@@ -724,14 +730,9 @@
respond(r, nil);
return;
}
- if(rf->fd >= 0)
- goto Fdgen;
- if((rf->fd = revlogopentemp(rf->rlog, hashrev(rf->rlog, rf->node->hash))) < 0){
- responderror(r);
- return;
- }
- rf->doff = fmetaheader(rf->fd);
Fdgen:
+ if(rf->fd < 0)
+ break;
if((n = pread(rf->fd, r->ofcall.data, len, off + rf->doff)) < 0){
responderror(r);
return;