From 1d682ec6249bd02307268d7f0dfc3d5efa8c1b4a Mon Sep 17 00:00:00 2001 From: Pedro Teixeira Date: Wed, 29 Mar 2017 10:36:09 +0100 Subject: [PATCH] fix: adding a dir: leaf node gets replaced with dir if necessary --- src/importer/dir-flat.js | 4 +++- src/importer/dir-sharded.js | 4 +++- src/importer/dir.js | 4 ++++ src/importer/tree-builder.js | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 src/importer/dir.js diff --git a/src/importer/dir-flat.js b/src/importer/dir-flat.js index a8d625b7..ead6f5fe 100644 --- a/src/importer/dir-flat.js +++ b/src/importer/dir-flat.js @@ -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) } diff --git a/src/importer/dir-sharded.js b/src/importer/dir-sharded.js index dc474dc6..676361c6 100644 --- a/src/importer/dir-sharded.js +++ b/src/importer/dir-sharded.js @@ -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') @@ -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) diff --git a/src/importer/dir.js b/src/importer/dir.js new file mode 100644 index 00000000..cd1a0e51 --- /dev/null +++ b/src/importer/dir.js @@ -0,0 +1,4 @@ +'use strict' + +module.exports = class Dir { +} diff --git a/src/importer/tree-builder.js b/src/importer/tree-builder.js index 039dcb83..22c17906 100644 --- a/src/importer/tree-builder.js +++ b/src/importer/tree-builder.js @@ -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 @@ -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,