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

Commit 7cfd208

Browse files
authored
Merge pull request #169 from ipfs/fix/add-dir
fix: adding a dir: leaf node gets replaced with dir if necessary
2 parents a7904ff + 1d682ec commit 7cfd208

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

src/importer/dir-flat.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ const dagPB = require('ipld-dag-pb')
77
const UnixFS = require('ipfs-unixfs')
88
const DAGLink = dagPB.DAGLink
99
const DAGNode = dagPB.DAGNode
10+
const Dir = require('./dir')
1011

11-
class DirFlat {
12+
class DirFlat extends Dir {
1213
constructor (props) {
14+
super()
1315
this._children = {}
1416
Object.assign(this, props)
1517
}

src/importer/dir-sharded.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const UnixFS = require('ipfs-unixfs')
99
const DAGLink = dagPB.DAGLink
1010
const DAGNode = dagPB.DAGNode
1111
const multihashing = require('multihashing-async')
12+
const Dir = require('./dir')
1213

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

@@ -38,8 +39,9 @@ const defaultOptions = {
3839
hashFn: hashFn
3940
}
4041

41-
class DirSharded {
42+
class DirSharded extends Dir {
4243
constructor (props, _options) {
44+
super()
4345
const options = Object.assign({}, defaultOptions, _options)
4446
this._options = options
4547
this._bucket = Bucket(options)

src/importer/dir.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'use strict'
2+
3+
module.exports = class Dir {
4+
}

src/importer/tree-builder.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const writable = require('pull-write')
88
const pushable = require('pull-pushable')
99
const DirFlat = require('./dir-flat')
1010
const flatToShard = require('./flat-to-shard')
11+
const Dir = require('./dir')
1112

1213
module.exports = createTreeBuilder
1314

@@ -122,7 +123,7 @@ function createTreeBuilder (ipldResolver, _options) {
122123
return // early
123124
}
124125
let dir = treeNode
125-
if (!dir) {
126+
if (!dir || !(dir instanceof Dir)) {
126127
dir = DirFlat({
127128
dir: true,
128129
parent: parent,

0 commit comments

Comments
 (0)