Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 2c276ec

Browse files
committed
fix: prefix pins with /
1 parent e22efed commit 2c276ec

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/core/components/pin/add.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ module.exports = ({ pinManager, gcLock, dag }) => {
1717
const isPinned = await pinManager.isPinnedWithType(cid, [PinTypes.recursive, PinTypes.direct])
1818
const pinned = isPinned.pinned
1919

20-
/* if (pinned) {
20+
if (pinned) {
2121
throw new Error(`${cid} already pinned with type ${isPinned.reason}`)
22-
} */
22+
}
2323

2424
if (!pinned) {
2525
if (recursive) {

src/core/components/pin/pin-manager.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ function invalidPinTypeErr (type) {
2121
return errCode(new Error(errMsg), 'ERR_INVALID_PIN_TYPE')
2222
}
2323

24+
function toKey (cid) {
25+
return '/' + bs58.encode(cid.multihash)
26+
}
27+
2428
const PinTypes = {
2529
direct: 'direct',
2630
recursive: 'recursive',
@@ -56,7 +60,7 @@ class PinManager {
5660
async pinDirectly (cid, options = {}) {
5761
await this.dag.get(cid, options)
5862

59-
return this.repo.pins.put(bs58.encode(cid.multihash), cbor.encode({
63+
return this.repo.pins.put(toKey(cid), cbor.encode({
6064
cid: cid.buffer,
6165
type: PinTypes.direct,
6266
name: options.name
@@ -83,13 +87,13 @@ class PinManager {
8387
cid = new CID(cbor.decode(result.value).cid)
8488
}
8589

86-
return this.repo.pins.delete(bs58.encode(cid.multihash))
90+
return this.repo.pins.delete(toKey(cid))
8791
}
8892

8993
async pinRecursively (cid, options = {}) {
9094
await this.fetchCompleteDag(cid, options)
9195

92-
await this.repo.pins.put(bs58.encode(cid.multihash), cbor.encode({
96+
await this.repo.pins.put(toKey(cid), cbor.encode({
9397
cid: cid.buffer,
9498
type: PinTypes.recursive,
9599
name: options.name
@@ -161,7 +165,7 @@ class PinManager {
161165

162166
if (recursive || direct || all) {
163167
const result = await first(this.repo.pins.query({
164-
prefix: bs58.encode(cid.multihash),
168+
prefix: toKey(cid),
165169
filters: [entry => {
166170
const pin = cbor.decode(entry.value)
167171

0 commit comments

Comments
 (0)