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

Commit e4c9a9f

Browse files
committed
fix: root is not a store inside the store
1 parent 376701e commit e4c9a9f

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/utils.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,19 @@ function getDatastoreAndOptions (name, options) {
3030
}
3131
}
3232

33-
// This function in js-ipfs-repo defaults to not using sharding
34-
// but the default value of the options.sharding is true hence this
35-
// function defaults to use sharding.
36-
function maybeWithSharding (store, options) {
37-
if (options.sharding === false) {
38-
return store
33+
async function createStore (location, name, options) {
34+
const { StorageBackend, storageOptions } = getDatastoreAndOptions(name, options)
35+
36+
if (name !== 'root') {
37+
location = `${location}/${name}`
3938
}
4039

41-
const shard = new core.shard.NextToLast(2)
42-
return ShardingStore.createOrOpen(store, shard)
43-
}
40+
let store = new StorageBackend(location, storageOptions)
4441

45-
async function createStore (location, name, options) {
46-
const { StorageBackend, storageOptions } = getDatastoreAndOptions(name, options)
47-
let store = new StorageBackend(`${location}/${name}`, storageOptions)
48-
store = await maybeWithSharding(store, storageOptions)
42+
if (storageOptions.sharding) {
43+
const shard = new core.shard.NextToLast(2)
44+
store = await ShardingStore.createOrOpen(store, shard)
45+
}
4946

5047
await store.close()
5148

0 commit comments

Comments
 (0)