holepunchto / hyperdrive

Hyperdrive is a secure, real time distributed file system
Apache License 2.0
1.86k stars 134 forks source link

hyperdrive/hyperdb file storage issues #215

Closed joehand closed 1 year ago

joehand commented 6 years ago

Bug:

All files are getting appended to the first file imported.

Cause:

Seems like the file.end is not getting set (not sure how that should get set).

In the _find function of lib/storage the first file is always returned because file.start = 0 and file.end = Infinity, so the offset is always between those two.

ContentStorage.prototype._find = function (offset, cb) {
  for (var i = 0; i < this.files.length; i++) {
    var file = this.files[i]
    // ALWAYS RETURNS FIRST FILE
    if (file.start <= offset && offset < file.end) {
      return cb(null, file)
    }
  }

  this._findInFeed(offset, cb)
}

https://github.com/mafintosh/hyperdrive/blob/hyperdb-backend/lib/storage.js#L53-L62

Reproduce

You can use reproduce with this repo https://github.com/datproject/dat-node/tree/hyperdb by running node examples/share.js. Everything will get appended to CHANGELOG.md.