Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing two files with the same name results in a directory with just one #232

Open
alanshaw opened this issue Jun 28, 2022 · 1 comment
Labels
exp/novice Someone with a little familiarity can pick up help wanted Seeking public contribution on this issue kind/enhancement A net-new feature or improvement to an existing feature

Comments

@alanshaw
Copy link
Member

Repro:

import { importer } from 'ipfs-unixfs-importer'
import { MemoryBlockstore } from 'blockstore-core/memory'
import * as pb from '@ipld/dag-pb'

const blockstore = new MemoryBlockstore()
const source = [{
  path: 'blob',
  content: Buffer.from('first')
}, {
  path: 'blob',
  content: Buffer.from('seconds')
}]
const options = { cidVersion: 1, rawLeaves: true, wrapWithDirectory: true }
const entries = []

for await (const entry of importer(source, blockstore, options)) {
  console.info(entry)
  entries.push(entry)
}

const bytes = await blockstore.get(entries[entries.length - 1].cid)
console.log(pb.decode(bytes))

Output:

{
  cid: CID(bafkreifhsn5wjogkuwhqg4q3w25m6xdyzmrv727a44frxbgntfkbiynary),
  path: 'blob',
  unixfs: undefined,
  size: 5
}
{
  cid: CID(bafkreicz6adnmo6qbg37d4oxxv7ctyptxhnwkboopbgkgilovegg23olce),
  path: 'blob',
  unixfs: undefined,
  size: 7
}
{
  cid: CID(bafybeicjuj5znbntswyl5qdqacqinysb37sdwky335oinjn3gt43bpvtki),
  path: '',
  unixfs: UnixFS {
    type: 'directory',
    data: undefined,
    hashType: undefined,
    fanout: undefined,
    blockSizes: [],
    _originalMode: 0,
    _mode: 493
  },
  size: 59
}
{
  Data: Uint8Array(2) [ 8, 1 ],
  Links: [
    {
      Hash: CID(bafkreicz6adnmo6qbg37d4oxxv7ctyptxhnwkboopbgkgilovegg23olce),
      Name: 'blob',
      Tsize: 7
    }
  ]
}

The directory node includes only the second "blob".

It should not silently succeed but should throw an error. Alternatively, create a directory with both.

@alanshaw alanshaw added the need/triage Needs initial labeling and prioritization label Jun 28, 2022
@achingbrain
Copy link
Member

Alternatively, create a directory with both

A directory can only have one link with a given name. You'd have to rename one of the links which might be surprising?

It should not silently succeed but should throw an error.

Probably this. PRs accepted!

@achingbrain achingbrain added help wanted Seeking public contribution on this issue exp/novice Someone with a little familiarity can pick up kind/enhancement A net-new feature or improvement to an existing feature and removed need/triage Needs initial labeling and prioritization labels Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exp/novice Someone with a little familiarity can pick up help wanted Seeking public contribution on this issue kind/enhancement A net-new feature or improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants