Skip to content
This repository has been archived by the owner on Aug 12, 2020. It is now read-only.

Commit

Permalink
fix: adding a dir: leaf node gets replaced with dir if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte committed Mar 29, 2017
1 parent a7904ff commit 1d682ec
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/importer/dir-flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ const dagPB = require('ipld-dag-pb')
const UnixFS = require('ipfs-unixfs')
const DAGLink = dagPB.DAGLink
const DAGNode = dagPB.DAGNode
const Dir = require('./dir')

class DirFlat {
class DirFlat extends Dir {
constructor (props) {
super()
this._children = {}
Object.assign(this, props)
}
Expand Down
4 changes: 3 additions & 1 deletion src/importer/dir-sharded.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const UnixFS = require('ipfs-unixfs')
const DAGLink = dagPB.DAGLink
const DAGNode = dagPB.DAGNode
const multihashing = require('multihashing-async')
const Dir = require('./dir')

const Bucket = require('../hamt')

Expand Down Expand Up @@ -38,8 +39,9 @@ const defaultOptions = {
hashFn: hashFn
}

class DirSharded {
class DirSharded extends Dir {
constructor (props, _options) {
super()
const options = Object.assign({}, defaultOptions, _options)
this._options = options
this._bucket = Bucket(options)
Expand Down
4 changes: 4 additions & 0 deletions src/importer/dir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict'

module.exports = class Dir {
}
3 changes: 2 additions & 1 deletion src/importer/tree-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const writable = require('pull-write')
const pushable = require('pull-pushable')
const DirFlat = require('./dir-flat')
const flatToShard = require('./flat-to-shard')
const Dir = require('./dir')

module.exports = createTreeBuilder

Expand Down Expand Up @@ -122,7 +123,7 @@ function createTreeBuilder (ipldResolver, _options) {
return // early
}
let dir = treeNode
if (!dir) {
if (!dir || !(dir instanceof Dir)) {
dir = DirFlat({
dir: true,
parent: parent,
Expand Down

0 comments on commit 1d682ec

Please sign in to comment.