Skip to content

Commit 8c71fb8

Browse files
committed
groot/riofs: fix overlaping blocks w/ big-file mode
TKeys sizes computation was broken for "big files". The code was indeed changing the `key.rvers` field to indicate the "big file" mode was enabled, but it wasn't updating the on-disk size of the TKey (ie: missing 8bytes). This CL computes the correct size in one-go instead of fixing it after the facts. Fixes #821.
1 parent 43e74de commit 8c71fb8

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

groot/riofs/key.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,16 @@ func newKey(dir *tdirectoryFile, name, title, class string, objlen int32, f *Fil
9999
// if the key's payload is actually compressed, we introduce a hole
100100
// with the f.setEnd call below.
101101
k.nbytes = k.objlen + k.keylen
102+
eof := f.end
102103
if objlen > 0 {
103-
k.seekkey = f.end
104+
k.seekkey = eof
104105
err := f.setEnd(k.seekkey + int64(k.nbytes))
105106
if err != nil {
106107
panic(err)
107108
}
108109
}
109110

110-
if f.end > kStartBigFile {
111+
if eof > kStartBigFile {
111112
k.rvers += 1000
112113
}
113114

@@ -135,7 +136,7 @@ func newKeyFrom(dir *tdirectoryFile, name, title, class string, obj root.Object,
135136
dir = &f.dir
136137
}
137138

138-
keylen := keylenFor(name, title, class, dir)
139+
keylen := keylenFor(name, title, class, dir, f.end)
139140

140141
buf := rbytes.NewWBuffer(nil, nil, uint32(keylen), dir.file)
141142
switch obj := obj.(type) {
@@ -190,7 +191,7 @@ func newKeyFromBuf(dir *tdirectoryFile, name, title, class string, cycle int16,
190191
dir = &f.dir
191192
}
192193

193-
keylen := keylenFor(name, title, class, dir)
194+
keylen := keylenFor(name, title, class, dir, f.end)
194195
objlen := int32(len(buf))
195196
k := Key{
196197
f: f,
@@ -464,12 +465,12 @@ func (k *Key) isBigFile() bool {
464465

465466
// sizeof returns the size in bytes of the key header structure.
466467
func (k *Key) sizeof() int32 {
467-
return keylenFor(k.name, k.title, k.class, &k.f.dir)
468+
return keylenFor(k.name, k.title, k.class, &k.f.dir, k.f.end)
468469
}
469470

470-
func keylenFor(name, title, class string, dir *tdirectoryFile) int32 {
471+
func keylenFor(name, title, class string, dir *tdirectoryFile, eof int64) int32 {
471472
nbytes := int32(22)
472-
if dir.isBigFile() {
473+
if dir.isBigFile() || eof > kStartBigFile {
473474
nbytes += 8
474475
}
475476
nbytes += datimeSizeof()

0 commit comments

Comments
 (0)