Skip to content

Commit

Permalink
fix(PinApi): store the original CID
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Jul 28, 2019
1 parent 928430c commit 02b4c24
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/CoreApi/PinApi.cs
Expand Up @@ -10,7 +10,7 @@ namespace Ipfs.Engine.CoreApi
{
class Pin
{
public static Pin Default = new Pin();
public Cid Id;
}

class PinApi : IPinApi
Expand All @@ -32,13 +32,12 @@ public PinApi(IpfsEngine ipfs)
var folder = Path.Combine(ipfs.Options.Repository.Folder, "pins");
if (!Directory.Exists(folder))
Directory.CreateDirectory(folder);
// TODO: Need cid.Encode("base32")
store = new FileStore<Cid, Pin>
{
Folder = folder,
NameToKey = (cid) => cid.Hash.ToBase32(),
KeyToName = (key) => new MultiHash(key.FromBase32()),
Serialize = (stream, cid, block, cancel) => Task.CompletedTask,
Deserialize = (stream, cid, cancel) => Task.FromResult(Pin.Default)
KeyToName = (key) => new MultiHash(key.FromBase32())
};
}
return store;
Expand All @@ -61,7 +60,7 @@ public async Task<IEnumerable<Cid>> AddAsync(string path, bool recursive = true,
var current = todos.Pop();

// Add CID to PIN database.
await Store.PutAsync(current, Pin.Default).ConfigureAwait(false);
await Store.PutAsync(current, new Pin { Id = current }).ConfigureAwait(false);

// Make sure that the content is stored locally.
await ipfs.Block.GetAsync(current, cancel).ConfigureAwait(false);
Expand All @@ -84,8 +83,9 @@ public async Task<IEnumerable<Cid>> AddAsync(string path, bool recursive = true,

public Task<IEnumerable<Cid>> ListAsync(CancellationToken cancel = default(CancellationToken))
{
var cids = Store.Names.ToArray();
return Task.FromResult((IEnumerable<Cid>)cids);
var cids = Store.Values
.Select(pin => pin.Id);
return Task.FromResult(cids);
}

public async Task<IEnumerable<Cid>> RemoveAsync(Cid id, bool recursive = true, CancellationToken cancel = default(CancellationToken))
Expand Down

0 comments on commit 02b4c24

Please sign in to comment.