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

Commit 7b692c6

Browse files
authored
Mtime passed as timespec (#42)
* fix: support mtime as timespec * fix: use unixfs pr version * fix: handle unwrapped directories * fix: update to support optional mtime * chore: update deps * fix: linting * chore: update deps
1 parent 9cf50e1 commit 7b692c6

File tree

8 files changed

+89
-95
lines changed

8 files changed

+89
-95
lines changed

package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,27 @@
4343
"deep-extend": "~0.6.0",
4444
"detect-node": "^2.0.4",
4545
"dirty-chai": "^2.0.1",
46-
"ipfs-unixfs-exporter": "^0.39.0",
46+
"ipfs-unixfs-exporter": "^0.40.0",
4747
"ipld": "^0.25.0",
4848
"ipld-in-memory": "^3.0.0",
4949
"it-buffer-stream": "^1.0.0",
5050
"it-last": "^1.0.0",
51-
"multihashes": "~0.4.14",
52-
"nyc": "^14.0.0",
53-
"sinon": "^7.1.0"
51+
"multihashes": "^0.4.14",
52+
"nyc": "^15.0.0",
53+
"sinon": "^8.0.4"
5454
},
5555
"dependencies": {
5656
"bl": "^4.0.0",
5757
"err-code": "^2.0.0",
58-
"hamt-sharding": "~0.0.2",
59-
"ipfs-unixfs": "^0.2.0",
58+
"hamt-sharding": "^1.0.0",
59+
"ipfs-unixfs": "^0.3.0",
6060
"ipld-dag-pb": "^0.18.0",
6161
"it-all": "^1.0.1",
6262
"it-batch": "^1.0.3",
6363
"it-first": "^1.0.1",
64-
"it-parallel-batch": "1.0.2",
64+
"it-parallel-batch": "^1.0.3",
6565
"merge-options": "^2.0.0",
66-
"multicodec": "~0.5.1",
66+
"multicodec": "^1.0.0",
6767
"multihashing-async": "^0.8.0",
6868
"rabin-wasm": "~0.0.8"
6969
},

src/dag-builder/dir.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@ const {
77
} = require('ipld-dag-pb')
88

99
const dirBuilder = async (item, ipld, options) => {
10-
const unixfs = new UnixFS('directory')
11-
12-
if (item.mtime) {
13-
unixfs.mtime = item.mtime
14-
}
15-
16-
if (item.mode) {
17-
unixfs.mode = item.mode
18-
}
10+
const unixfs = new UnixFS({
11+
type: 'directory',
12+
mtime: item.mtime,
13+
mode: item.mode
14+
})
1915

2016
const node = new DAGNode(unixfs.marshal(), [])
2117
const cid = await persist(node, ipld, options)

src/dag-builder/file/index.js

+11-18
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,12 @@ async function * importBuffer (file, source, ipld, options) {
3333
opts.codec = 'raw'
3434
opts.cidVersion = 1
3535
} else {
36-
unixfs = new UnixFS(options.leafType, buffer)
37-
38-
if (file.mtime) {
39-
unixfs.mtime = file.mtime
40-
}
41-
42-
if (file.mode) {
43-
unixfs.mode = file.mode
44-
}
36+
unixfs = new UnixFS({
37+
type: options.leafType,
38+
data: buffer,
39+
mtime: file.mtime,
40+
mode: file.mode
41+
})
4542

4643
node = new DAGNode(unixfs.marshal())
4744
}
@@ -96,15 +93,11 @@ const reduce = (file, ipld, options) => {
9693
}
9794

9895
// create a parent node and add all the leaves
99-
const f = new UnixFS('file')
100-
101-
if (file.mtime) {
102-
f.mtime = file.mtime
103-
}
104-
105-
if (file.mode) {
106-
f.mode = file.mode
107-
}
96+
const f = new UnixFS({
97+
type: 'file',
98+
mtime: file.mtime,
99+
mode: file.mode
100+
})
108101

109102
const links = leaves
110103
.filter(leaf => {

src/dir-flat.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,11 @@ class DirFlat extends Dir {
6868
links.push(new DAGLink(children[i], child.node.length || child.node.size, child.cid))
6969
}
7070

71-
const unixfs = new UnixFS('directory')
72-
73-
if (this.mtime) {
74-
unixfs.mtime = this.mtime
75-
}
76-
77-
if (this.mode) {
78-
unixfs.mode = this.mode
79-
}
71+
const unixfs = new UnixFS({
72+
type: 'directory',
73+
mtime: this.mtime,
74+
mode: this.mode
75+
})
8076

8177
const node = new DAGNode(unixfs.marshal(), links)
8278
const cid = await persist(node, ipld, this.options)

src/dir-sharded.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,14 @@ async function * flush (path, bucket, ipld, shardRoot, options) {
141141
// go-ipfs uses little endian, that's why we have to
142142
// reverse the bit field before storing it
143143
const data = Buffer.from(children.bitField().reverse())
144-
const dir = new UnixFS('hamt-sharded-directory', data)
145-
dir.fanout = bucket.tableSize()
146-
dir.hashType = options.hamtHashFn.code
147-
148-
if (shardRoot && shardRoot.mtime) {
149-
dir.mtime = shardRoot.mtime
150-
}
151-
152-
if (shardRoot && shardRoot.mode) {
153-
dir.mode = shardRoot.mode
154-
}
144+
const dir = new UnixFS({
145+
type: 'hamt-sharded-directory',
146+
data,
147+
fanout: bucket.tableSize(),
148+
hashType: options.hamtHashFn.code,
149+
mtime: shardRoot && shardRoot.mtime,
150+
mode: shardRoot && shardRoot.mode
151+
})
155152

156153
const node = new DAGNode(dir.marshal(), links)
157154
const cid = await persist(node, ipld, options)

src/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const defaultOptions = {
2929
wrapWithDirectory: false,
3030
pin: true,
3131
recursive: false,
32-
ignore: null, // []
3332
hidden: false,
3433
preload: true
3534
}

src/tree-builder.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ async function * treeBuilder (source, ipld, options) {
6464
if (!entry) {
6565
continue
6666
}
67+
6768
tree = await addToTree(entry, tree, options)
6869

69-
yield entry
70+
if (!entry.unixfs || !entry.unixfs.isDirectory()) {
71+
yield entry
72+
}
7073
}
7174

7275
if (!options.wrapWithDirectory) {
@@ -83,13 +86,15 @@ async function * treeBuilder (source, ipld, options) {
8386
tree = unwrapped.child
8487
}
8588

86-
if (!tree.dir) {
89+
if (!(tree instanceof Dir)) {
90+
if (tree && tree.unixfs && tree.unixfs.isDirectory()) {
91+
yield tree
92+
}
93+
8794
return
8895
}
8996

90-
for await (const entry of tree.flush(tree.path, ipld)) {
91-
yield entry
92-
}
97+
yield * tree.flush(tree.path, ipld)
9398
}
9499

95100
module.exports = treeBuilder

0 commit comments

Comments
 (0)