Skip to content

Commit

Permalink
Fix malformed header.
Browse files Browse the repository at this point in the history
Closes #452.
  • Loading branch information
flatheadmill committed Feb 5, 2015
1 parent d5cf728 commit 010f571
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions strata.js
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,7 @@ Sheaf.prototype.writeDelete = function (queue, page, index, callback) {
}

Sheaf.prototype.writeHeader = function (queue, page) {
var header = [ 0, ++page.entries, page.right ]
var header = [ ++page.entries, 0, page.right ]
return this.writeEntry({ queue: queue, page: page, header: header, type: 'header' })
}

Expand Down Expand Up @@ -1594,7 +1594,10 @@ prototype(Sheaf, 'replay', cadence(function (async, fd, stat, read, page, positi
page.position += length
var entry = this.readEntry(slice.slice(offset, offset + length), !leaf)
var header = this.readHeader(entry)
if (entry.header[0]) {
if (entry.header[1] == 0) {
page.right = entry.header[2]
page.entries++
} else {
ok(header.entry == ++page.entries, 'entry count is off')
var index = header.index
if (leaf) {
Expand All @@ -1621,9 +1624,6 @@ prototype(Sheaf, 'replay', cadence(function (async, fd, stat, read, page, positi
key: key, address: address, heft: heft
})
}
} else {
page.right = entry.header[2]
page.entries++
}
i = offset = offset + length
}
Expand Down
2 changes: 1 addition & 1 deletion t/basics/create.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function prove (async, assert) {
vivify(tmp, async())
load(__dirname + '/fixtures/create.after.json', async())
}, function (actual, expected) {
assert.say(actual)
assert.say(actual[1])
assert.say(expected)

assert(actual, expected, 'written')
Expand Down
6 changes: 3 additions & 3 deletions t/proof.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function abstracted (dir) {
position = 0
dir[file].forEach(function (line, index) {
var json = line.header
if (json[0]) {
if (json[1]) {
ok(index + 1 == json[0], 'entry record is wrong')
if (json[1] > 0) {
record.log.push({ type: 'add', value: line.body })
Expand All @@ -168,7 +168,7 @@ function abstracted (dir) {
}
} else {
ok(index == 0, 'header not first entry')
ok(json[1] == 1, 'header not first entry')
ok(json[0] == 1, 'header not first entry')
if (json[2]) record.right = Math.abs(json[2])
}
})
Expand Down Expand Up @@ -310,7 +310,7 @@ function directivize (json) {
position += length
return record
})
directory[address].unshift({ header: [ 0, 1, object.right || 0 ]})
directory[address].unshift({ header: [ 1, 0, object.right || 0 ]})
}
}

Expand Down

0 comments on commit 010f571

Please sign in to comment.