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

Mtime passed as timespec #42

Merged
merged 7 commits into from
Jan 8, 2020
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
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,27 @@
"deep-extend": "~0.6.0",
"detect-node": "^2.0.4",
"dirty-chai": "^2.0.1",
"ipfs-unixfs-exporter": "^0.39.0",
"ipfs-unixfs-exporter": "^0.40.0",
"ipld": "^0.25.0",
"ipld-in-memory": "^3.0.0",
"it-buffer-stream": "^1.0.0",
"it-last": "^1.0.0",
"multihashes": "~0.4.14",
"nyc": "^14.0.0",
"sinon": "^7.1.0"
"multihashes": "^0.4.14",
"nyc": "^15.0.0",
"sinon": "^8.0.4"
},
"dependencies": {
"bl": "^4.0.0",
"err-code": "^2.0.0",
"hamt-sharding": "~0.0.2",
"ipfs-unixfs": "^0.2.0",
"hamt-sharding": "^1.0.0",
"ipfs-unixfs": "^0.3.0",
"ipld-dag-pb": "^0.18.0",
"it-all": "^1.0.1",
"it-batch": "^1.0.3",
"it-first": "^1.0.1",
"it-parallel-batch": "1.0.2",
"it-parallel-batch": "^1.0.3",
"merge-options": "^2.0.0",
"multicodec": "~0.5.1",
"multicodec": "^1.0.0",
"multihashing-async": "^0.8.0",
"rabin-wasm": "~0.0.8"
},
Expand Down
14 changes: 5 additions & 9 deletions src/dag-builder/dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ const {
} = require('ipld-dag-pb')

const dirBuilder = async (item, ipld, options) => {
const unixfs = new UnixFS('directory')

if (item.mtime) {
unixfs.mtime = item.mtime
}

if (item.mode) {
unixfs.mode = item.mode
}
const unixfs = new UnixFS({
type: 'directory',
mtime: item.mtime,
mode: item.mode
})

const node = new DAGNode(unixfs.marshal(), [])
const cid = await persist(node, ipld, options)
Expand Down
29 changes: 11 additions & 18 deletions src/dag-builder/file/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,12 @@ async function * importBuffer (file, source, ipld, options) {
opts.codec = 'raw'
opts.cidVersion = 1
} else {
unixfs = new UnixFS(options.leafType, buffer)

if (file.mtime) {
unixfs.mtime = file.mtime
}

if (file.mode) {
unixfs.mode = file.mode
}
unixfs = new UnixFS({
type: options.leafType,
data: buffer,
mtime: file.mtime,
mode: file.mode
})

node = new DAGNode(unixfs.marshal())
}
Expand Down Expand Up @@ -96,15 +93,11 @@ const reduce = (file, ipld, options) => {
}

// create a parent node and add all the leaves
const f = new UnixFS('file')

if (file.mtime) {
f.mtime = file.mtime
}

if (file.mode) {
f.mode = file.mode
}
const f = new UnixFS({
type: 'file',
mtime: file.mtime,
mode: file.mode
})

const links = leaves
.filter(leaf => {
Expand Down
14 changes: 5 additions & 9 deletions src/dir-flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,11 @@ class DirFlat extends Dir {
links.push(new DAGLink(children[i], child.node.length || child.node.size, child.cid))
}

const unixfs = new UnixFS('directory')

if (this.mtime) {
unixfs.mtime = this.mtime
}

if (this.mode) {
unixfs.mode = this.mode
}
const unixfs = new UnixFS({
type: 'directory',
mtime: this.mtime,
mode: this.mode
})

const node = new DAGNode(unixfs.marshal(), links)
const cid = await persist(node, ipld, this.options)
Expand Down
19 changes: 8 additions & 11 deletions src/dir-sharded.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,14 @@ async function * flush (path, bucket, ipld, shardRoot, options) {
// go-ipfs uses little endian, that's why we have to
// reverse the bit field before storing it
const data = Buffer.from(children.bitField().reverse())
const dir = new UnixFS('hamt-sharded-directory', data)
dir.fanout = bucket.tableSize()
dir.hashType = options.hamtHashFn.code

if (shardRoot && shardRoot.mtime) {
dir.mtime = shardRoot.mtime
}

if (shardRoot && shardRoot.mode) {
dir.mode = shardRoot.mode
}
const dir = new UnixFS({
type: 'hamt-sharded-directory',
data,
fanout: bucket.tableSize(),
hashType: options.hamtHashFn.code,
mtime: shardRoot && shardRoot.mtime,
mode: shardRoot && shardRoot.mode
})

const node = new DAGNode(dir.marshal(), links)
const cid = await persist(node, ipld, options)
Expand Down
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const defaultOptions = {
wrapWithDirectory: false,
pin: true,
recursive: false,
ignore: null, // []
hidden: false,
preload: true
}
Expand Down
15 changes: 10 additions & 5 deletions src/tree-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ async function * treeBuilder (source, ipld, options) {
if (!entry) {
continue
}

tree = await addToTree(entry, tree, options)

yield entry
if (!entry.unixfs || !entry.unixfs.isDirectory()) {
yield entry
}
}

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

if (!tree.dir) {
if (!(tree instanceof Dir)) {
if (tree && tree.unixfs && tree.unixfs.isDirectory()) {
yield tree
}

return
}

for await (const entry of tree.flush(tree.path, ipld)) {
yield entry
}
yield * tree.flush(tree.path, ipld)
}

module.exports = treeBuilder
Loading