Skip to content

Commit 3b280d9

Browse files
committed
Add: support pin-name (v0.37.0) via AddFileOptions.PinName; map to pin-name; tests for named pin integration with pin list
1 parent 4e84088 commit 3b280d9

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/CoreApi/FileSystemApi.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ private string[] ToApiOptions(AddFileOptions? options)
271271

272272
if (options.Pin is not null)
273273
opts.Add($"pin={options.Pin.ToString().ToLowerInvariant()}");
274+
275+
if (!string.IsNullOrEmpty(options.PinName))
276+
opts.Add($"pin-name={options.PinName}");
274277

275278
if (options.Wrap is not null)
276279
opts.Add($"wrap-with-directory={options.Wrap.ToString().ToLowerInvariant()}");
@@ -291,10 +294,10 @@ private string[] ToApiOptions(AddFileOptions? options)
291294
opts.Add("progress=true");
292295

293296
if (options.Hash is not null)
294-
opts.Add($"hash=${options.Hash}");
297+
opts.Add($"hash={options.Hash}");
295298

296299
if (options.FsCache is not null)
297-
opts.Add($"fscache={options.Wrap.ToString().ToLowerInvariant()}");
300+
opts.Add($"fscache={options.FsCache.ToString().ToLowerInvariant()}");
298301

299302
if (options.ToFiles is not null)
300303
opts.Add($"to-files={options.ToFiles}");

test/CoreApi/FileSystemApiTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,22 @@ public async Task Add_Wrap()
124124
}
125125
}
126126

127+
[TestMethod]
128+
public async Task Add_WithPinName_PinsNamed()
129+
{
130+
var ipfs = TestFixture.Ipfs;
131+
var name = $"add-pin-{Guid.NewGuid()}";
132+
var node = await ipfs.FileSystem.AddTextAsync("named pin via add", new AddFileOptions { Pin = true, PinName = name });
133+
134+
var items = await ipfs.Pin.ListAsync(new PinListOptions { Names = true }).ToArrayAsync();
135+
var match = items.FirstOrDefault(i => i.Cid == node.Id);
136+
Assert.IsNotNull(match, "Expected CID to be pinned");
137+
Assert.AreEqual(name, match!.Name, "Expected pin name to match");
138+
139+
// cleanup
140+
await ipfs.Pin.RemoveAsync(node.Id);
141+
}
142+
127143
[TestMethod]
128144
public async Task GetTar_EmptyDirectory()
129145
{

0 commit comments

Comments
 (0)