Skip to content

Commit 099ce9c

Browse files
lidelhacdias
authored andcommitted
feat: profiles for legacy-cid-v0 test-cid-v1
1 parent 6ba3542 commit 099ce9c

File tree

4 files changed

+67
-4
lines changed

4 files changed

+67
-4
lines changed

config/profile.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,28 @@ fetching may be degraded.
204204
return nil
205205
},
206206
},
207+
"legacy-cid-v0": {
208+
Description: `Makes UnixFS import produce legacy CIDv0 with no raw leaves, sha2-256 and 256 KiB chunks.`,
209+
210+
Transform: func(c *Config) error {
211+
c.Import.CidVersion = *NewOptionalInteger(0)
212+
c.Import.UnixFSRawLeaves = False
213+
c.Import.UnixFSChunker = *NewOptionalString("size-262144")
214+
c.Import.HashFunction = *NewOptionalString("sha2-256")
215+
return nil
216+
},
217+
},
218+
"test-cid-v1": {
219+
Description: `Makes UnixFS import produce modern CIDv1 with raw leaves, sha2-256 and 1 MiB chunks.`,
220+
221+
Transform: func(c *Config) error {
222+
c.Import.CidVersion = *NewOptionalInteger(1)
223+
c.Import.UnixFSRawLeaves = True
224+
c.Import.UnixFSChunker = *NewOptionalString("size-1048576")
225+
c.Import.HashFunction = *NewOptionalString("sha2-256")
226+
return nil
227+
},
228+
},
207229
}
208230

209231
func getAvailablePort() (port int, err error) {

docs/changelogs/v0.29.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [Overview](#overview)
88
- [🔦 Highlights](#-highlights)
99
- [Add search functionality for pin names](#add-search-functionality-for-pin-names)
10+
- [Customizing `ipfs add` defaults](#customizing-ipfs-add-defaults)
1011
- [📝 Changelog](#-changelog)
1112
- [👨‍👩‍👧‍👦 Contributors](#-contributors)
1213

@@ -18,9 +19,15 @@
1819

1920
It is now possible to search for pins by name. To do so, use `ipfs pin ls --name "SomeName"`. The search is case-sensitive and will return all pins having a name which contains the exact word provided.
2021

21-
#### Global configuration for data ingestion
22+
#### Customizing `ipfs add` defaults
2223

23-
A new configuration section, `Import`, was introduced. This section allows to override the default values of options used across several commands that do data ingestion. Read more in the [config documentation](../config.md).
24+
This release supports overriding global data ingestion defaults used by commands like `ipfs add` via user-defined [`Import.*` configuration options](../config.md#import).
25+
The hash function, CID version, or UnixFS raw leaves and chunker behaviors can be set once, and used as the new implicit default for `ipfs add`.
26+
27+
> [!TIP]
28+
> As a convenience, two CID [profiles](../config.md#profile) are provided: `legacy-cid-v0` and `test-cid-v1`.
29+
> A test profile that defaults to modern CIDv1 can be applied via `ipfs config profile apply test-cid-v1`.
30+
> We encourage users to try it and report any issues.
2431
2532
### 📝 Changelog
2633

docs/config.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,21 @@ documented in `ipfs config profile --help`.
270270

271271
Use this profile with caution.
272272

273+
- `legacy-cid-v0`
274+
275+
Makes UnixFS import (`ipfs add`) produce legacy CIDv0 with no raw leaves, sha2-256 and 256 KiB chunks.
276+
277+
> [!WARNING]
278+
> This profile is provided for legacy users and should not be used for new projects.
279+
280+
- `test-cid-v1`
281+
282+
Makes UnixFS import (`ipfs add`) produce modern CIDv1 with raw leaves, sha2-256 and 1 MiB chunks.
283+
284+
> [!NOTE]
285+
> This profile will become the new implicit default, provided for testing purposes.
286+
> Follow [kubo#4143](https://github.com/ipfs/kubo/issues/4143) for more details.
287+
273288
## Types
274289

275290
This document refers to the standard JSON types (e.g., `null`, `string`,
@@ -2401,7 +2416,7 @@ Type: `optionalInteger`
24012416

24022417
The default UnixFS raw leaves option. Commands affected: `ipfs add`, `ipfs files write`.
24032418

2404-
Default: `false`
2419+
Default: `false` if `CidVersion=0`; `true` if `CidVersion=1`
24052420

24062421
Type: `flag`
24072422

@@ -2413,7 +2428,6 @@ Default: `size-262144`
24132428

24142429
Type: `optionalString`
24152430

2416-
24172431
### `Import.HashFunction`
24182432

24192433
The default hash function. Commands affected: `ipfs add`, `ipfs block put`, `ipfs dag put`.

test/cli/add_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,24 @@ func TestAdd(t *testing.T) {
9595
cidStr := node.IPFSAddStr(shortString)
9696
require.Equal(t, shortStringCidV1NoRawLeaves, cidStr)
9797
})
98+
99+
t.Run("ipfs init --profile=legacy-cid-v0 sets config that produces legacy CIDv0", func(t *testing.T) {
100+
t.Parallel()
101+
node := harness.NewT(t).NewNode().Init("--profile=legacy-cid-v0")
102+
node.StartDaemon()
103+
defer node.StopDaemon()
104+
105+
cidStr := node.IPFSAddStr(shortString)
106+
require.Equal(t, shortStringCidV0, cidStr)
107+
})
108+
109+
t.Run("ipfs init --profile=test-cid-v1 produces modern CIDv1", func(t *testing.T) {
110+
t.Parallel()
111+
node := harness.NewT(t).NewNode().Init("--profile=test-cid-v1")
112+
node.StartDaemon()
113+
defer node.StopDaemon()
114+
115+
cidStr := node.IPFSAddStr(shortString)
116+
require.Equal(t, shortStringCidV1, cidStr)
117+
})
98118
}

0 commit comments

Comments
 (0)