@cryptotaxi247 / kubo / commits / 5127ef497

remove rawblocks -> cidv1 constraint on add command

We probably should have this but it's a breaking change. License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>

Steven Allen committed Jan 23, 2018 at 21:42 UTC 5127ef497049f3e1dcdb1285cef4865c04c46a81
1 file changed +10 -27
core/commands/add.go
+10 -27
@@ -114,7 +114,7 @@ You can now check what blocks have been created by:
114 cmdkit.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add."),
115 cmdkit.StringOption(chunkerOptionName, "s", "Chunking algorithm, size-[bytes] or rabin-[min]-[avg]-[max]").WithDefault("size-262144"),
116 cmdkit.BoolOption(pinOptionName, "Pin this object when adding.").WithDefault(true),
117 - cmdkit.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. Implies CIDv1, defaults to on if CIDv1 is enabled. (experimental)"),
117 + cmdkit.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"),
118 cmdkit.BoolOption(noCopyOptionName, "Add the file using filestore. Implies raw-leaves. (experimental)"),
119 cmdkit.BoolOption(fstoreCacheOptionName, "Check the filestore for pre-existing blocks. (experimental)"),
120 cmdkit.IntOption(cidVersionOptionName, "CID version. Defaults to 0 unless an option that depends on CIDv1 is passed. (experimental)"),
@@ -173,22 +173,15 @@ You can now check what blocks have been created by:
173 cidVer, cidVerSet := req.Options[cidVersionOptionName].(int)
174 hashFunStr, _ := req.Options[hashOptionName].(string)
175
176 - // Given the following constraints:
176 + // The arguments are subject to the following constraints.
177 //
178 // nocopy -> filestoreEnabled
179 // nocopy -> rawblocks
180 - // rawblocks -> cidv1
180 // (hash != sha2-256) -> cidv1
182 - //
183 - // We solve for the values of rawblocks and cidv1 in the
184 - // following order of preference:
185 - //
186 - // 1. If cidv1 isn't fixed, set it to false and try solving.
187 - // 2. If rawblocks isn't fixed, set it to true and try solving.
188 - //
189 - // If neither solution works, give up (we have a conflict).
181
191 - // nocopy -> filestorEnabled
182 + // NOTE: 'rawblocks -> cidv1' is missing. Legacy reasons.
183 +
184 + // nocopy -> filestoreEnabled
185 if nocopy && !cfg.Experimental.FilestoreEnabled {
186 res.SetError(errors.New("filestore is not enabled, see https://git.io/vy4XN"),
187 cmdkit.ErrClient)
@@ -209,26 +202,16 @@ You can now check what blocks have been created by:
202 rawblks = true
203 }
204
212 - if !cidVerSet {
213 - // Default to CIDv0 if possible.
214 - // Conditions: no raw blocks, sha2-256
215 - if hashFunStr == "sha2-256" && !rawblks {
216 - cidVer = 0
217 - } else {
218 - cidVer = 1
219 - }
220 - } else if cidVer == 0 {
221 - // CIDv0 *was* set...
222 - if hashFunStr != "sha2-256" {
223 - res.SetError(errors.New("CIDv0 only supports sha2-256"), cmdkit.ErrClient)
224 - return
225 - } else if rawblks {
205 + // (hash != "sha2-256") -> CIDv1
206 + if hashFunStr != "sha2-256" && cidVer == 0 {
207 + if cidVerSet {
208 res.SetError(
227 - errors.New("CIDv0 incompatible with raw-leaves and/or nocopy"),
209 + errors.New("CIDv0 only supports sha2-256"),
210 cmdkit.ErrClient,
211 )
212 return
213 }
214 + cidVer = 1
215 }
216
217 // cidV1 -> raw blocks (by default)