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

Commit

Permalink
fix: use ipfs.addAll for directories (#373)
Browse files Browse the repository at this point in the history
We need to use ipfs.add for single bits of content and ipfs.addAll
for multiple bits of content.
  • Loading branch information
achingbrain authored Sep 28, 2021
1 parent 77894f2 commit 92c0f98
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
5 changes: 3 additions & 2 deletions test/exchange-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import concat from 'it-concat'
import globSource from 'ipfs-utils/src/files/glob-source.js'
import { expect } from 'aegir/utils/chai.js'
import { daemonFactory } from './utils/daemon-factory.js'
import last from 'it-last'

const rmDir = promisify(rimraf)

Expand Down Expand Up @@ -161,9 +162,9 @@ describe('exchange files', function () {
number: num
})

const { cid } = await daemon1.api.add(globSource(dir, '**/*'), {
const { cid } = await last(daemon1.api.addAll(globSource(dir, '**/*'), {
wrapWithDirectory: true
})
}))

await expect(countFiles(cid, daemon2.api)).to.eventually.equal(num)
} finally {
Expand Down
10 changes: 8 additions & 2 deletions test/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ describe('files', function () {
return cid
}

const testDirectoryHashesAreEqual = async (daemon, data, options = {}) => {
const { cid } = await last(daemon.api.addAll(data, options))

return cid
}

const _writeData = async (daemon, initialData, newData, options) => {
const fileName = `file-${Math.random()}.txt`

Expand Down Expand Up @@ -381,8 +387,8 @@ describe('files', function () {
}

return compare(
testHashesAreEqual(go, files),
testHashesAreEqual(js, files)
testDirectoryHashesAreEqual(go, files),
testDirectoryHashesAreEqual(js, files)
)
})

Expand Down
12 changes: 7 additions & 5 deletions test/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import fs from 'fs'
import all from 'it-all'
import last from 'it-last'
import drain from 'it-drain'
import { tmpPath, removeAllPins } from './utils/pin-utils.js'
import { expect } from 'aegir/utils/chai.js'
import { daemonFactory } from './utils/daemon-factory.js'
Expand Down Expand Up @@ -68,7 +70,7 @@ describe('pin', function () {
// Pinning a large file recursively results in the same pins
it('pin recursively', async function () {
async function pipeline (daemon) {
const { cid } = await daemon.api.add(jupiter, { pin: false })
const { cid } = await last(daemon.api.addAll(jupiter, { pin: false }))
await daemon.api.pin.add(cid)

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

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

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

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

return all(daemon.api.pin.ls())
}
Expand Down

0 comments on commit 92c0f98

Please sign in to comment.