mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-06 22:40:26 -05:00
fix "offset out of bounds" issue
This commit is contained in:
parent
1cb1e91ca1
commit
20f748be12
1 changed files with 18 additions and 5 deletions
|
@ -163,20 +163,33 @@ function open_flock(name, opmod, flmod, tries, backoff, cb) {
|
||||||
|
|
||||||
// this function neither unlocks file nor closes it
|
// this function neither unlocks file nor closes it
|
||||||
// it'll have to be done manually later
|
// it'll have to be done manually later
|
||||||
function lock_and_read(name, callback) {
|
function lock_and_read(name, _callback) {
|
||||||
open_flock(name, 'r', 'exnb', 4, 10, function(err, fd) {
|
open_flock(name, 'r', 'exnb', 4, 10, function(err, fd) {
|
||||||
|
function callback(err) {
|
||||||
|
if (err && fd) {
|
||||||
|
fs.close(fd, function(err2) {
|
||||||
|
_callback(err)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
_callback.apply(null, arguments)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (err) return callback(err, fd)
|
if (err) return callback(err, fd)
|
||||||
|
|
||||||
fs.fstat(fd, function(err, st) {
|
fs.fstat(fd, function(err, st) {
|
||||||
if (err) return callback(err, fd)
|
if (err) return callback(err, fd)
|
||||||
|
|
||||||
var buffer = new Buffer(st.size)
|
var buffer = new Buffer(st.size)
|
||||||
fs.read(fd, buffer, 0, st.size, null, function(err, bytesRead, buffer) {
|
if (st.size === 0) return onRead(null, 0, buffer)
|
||||||
if (err) return callback(err)
|
fs.read(fd, buffer, 0, st.size, null, onRead)
|
||||||
if (bytesRead != st.size) return callback(Error('st.size != bytesRead'), fd)
|
|
||||||
|
function onRead(err, bytesRead, buffer) {
|
||||||
|
if (err) return callback(err, fd)
|
||||||
|
if (bytesRead != st.size) return callback(new Error('st.size != bytesRead'), fd)
|
||||||
|
|
||||||
callback(null, fd, buffer)
|
callback(null, fd, buffer)
|
||||||
})
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue