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

Commit 92c0f98

Browse files
authoredSep 28, 2021
fix: use ipfs.addAll for directories (#373)
We need to use ipfs.add for single bits of content and ipfs.addAll for multiple bits of content.
1 parent 77894f2 commit 92c0f98

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed
 

‎test/exchange-files.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import concat from 'it-concat'
1515
import globSource from 'ipfs-utils/src/files/glob-source.js'
1616
import { expect } from 'aegir/utils/chai.js'
1717
import { daemonFactory } from './utils/daemon-factory.js'
18+
import last from 'it-last'
1819

1920
const rmDir = promisify(rimraf)
2021

@@ -161,9 +162,9 @@ describe('exchange files', function () {
161162
number: num
162163
})
163164

164-
const { cid } = await daemon1.api.add(globSource(dir, '**/*'), {
165+
const { cid } = await last(daemon1.api.addAll(globSource(dir, '**/*'), {
165166
wrapWithDirectory: true
166-
})
167+
}))
167168

168169
await expect(countFiles(cid, daemon2.api)).to.eventually.equal(num)
169170
} finally {

‎test/files.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ describe('files', function () {
234234
return cid
235235
}
236236

237+
const testDirectoryHashesAreEqual = async (daemon, data, options = {}) => {
238+
const { cid } = await last(daemon.api.addAll(data, options))
239+
240+
return cid
241+
}
242+
237243
const _writeData = async (daemon, initialData, newData, options) => {
238244
const fileName = `file-${Math.random()}.txt`
239245

@@ -381,8 +387,8 @@ describe('files', function () {
381387
}
382388

383389
return compare(
384-
testHashesAreEqual(go, files),
385-
testHashesAreEqual(js, files)
390+
testDirectoryHashesAreEqual(go, files),
391+
testDirectoryHashesAreEqual(js, files)
386392
)
387393
})
388394

‎test/pin.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import fs from 'fs'
44
import all from 'it-all'
5+
import last from 'it-last'
6+
import drain from 'it-drain'
57
import { tmpPath, removeAllPins } from './utils/pin-utils.js'
68
import { expect } from 'aegir/utils/chai.js'
79
import { daemonFactory } from './utils/daemon-factory.js'
@@ -68,7 +70,7 @@ describe('pin', function () {
6870
// Pinning a large file recursively results in the same pins
6971
it('pin recursively', async function () {
7072
async function pipeline (daemon) {
71-
const { cid } = await daemon.api.add(jupiter, { pin: false })
73+
const { cid } = await last(daemon.api.addAll(jupiter, { pin: false }))
7274
await daemon.api.pin.add(cid)
7375

7476
return all(daemon.api.pin.ls())
@@ -84,7 +86,7 @@ describe('pin', function () {
8486
// Pinning a large file with recursive=false results in the same direct pin
8587
it('pin directly', async function () {
8688
async function pipeline (daemon) {
87-
const { cid } = await daemon.api.add(jupiter, { pin: false })
89+
const { cid } = await last(daemon.api.addAll(jupiter, { pin: false }))
8890
await daemon.api.pin.add(cid, { recursive: false })
8991

9092
return all(daemon.api.pin.ls())
@@ -103,7 +105,7 @@ describe('pin', function () {
103105
// not part of another pin's dag
104106
it('pin recursively, remove the root pin', async function () {
105107
async function pipeline (daemon) {
106-
const { cid } = await daemon.api.add(jupiter)
108+
const { cid } = await last(daemon.api.addAll(jupiter))
107109
await daemon.api.pin.rm(cid)
108110

109111
return all(daemon.api.pin.ls())
@@ -120,7 +122,7 @@ describe('pin', function () {
120122
it('remove a child shared by multiple pins', async function () {
121123
let jupiterDir
122124
async function pipeline (daemon) {
123-
const { cid } = await daemon.api.add(jupiter, { pin: false, wrapWithDirectory: true })
125+
const { cid } = await last(daemon.api.addAll(jupiter, { pin: false, wrapWithDirectory: true }))
124126
jupiterDir = jupiterDir || await daemon.api.files.stat(`/ipfs/${cid}/test/fixtures/planets`)
125127

126128
// by separately pinning all the DAG nodes created when adding,
@@ -154,7 +156,7 @@ describe('pin', function () {
154156
describe('ls', function () {
155157
it('print same pins', async function () {
156158
async function pipeline (daemon) {
157-
await daemon.api.add(jupiter)
159+
await drain(daemon.api.addAll(jupiter))
158160

159161
return all(daemon.api.pin.ls())
160162
}

0 commit comments

Comments
 (0)
This repository has been archived.