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

fix: adding a dir: leaf node gets replaced with dir if necessary #169

Merged
merged 1 commit into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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