mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 01:52:26 +08:00
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>
This commit is contained in:
@ -114,7 +114,7 @@ You can now check what blocks have been created by:
|
|||||||
cmdkit.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add."),
|
cmdkit.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add."),
|
||||||
cmdkit.StringOption(chunkerOptionName, "s", "Chunking algorithm, size-[bytes] or rabin-[min]-[avg]-[max]").WithDefault("size-262144"),
|
cmdkit.StringOption(chunkerOptionName, "s", "Chunking algorithm, size-[bytes] or rabin-[min]-[avg]-[max]").WithDefault("size-262144"),
|
||||||
cmdkit.BoolOption(pinOptionName, "Pin this object when adding.").WithDefault(true),
|
cmdkit.BoolOption(pinOptionName, "Pin this object when adding.").WithDefault(true),
|
||||||
cmdkit.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. Implies CIDv1, defaults to on if CIDv1 is enabled. (experimental)"),
|
cmdkit.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"),
|
||||||
cmdkit.BoolOption(noCopyOptionName, "Add the file using filestore. Implies raw-leaves. (experimental)"),
|
cmdkit.BoolOption(noCopyOptionName, "Add the file using filestore. Implies raw-leaves. (experimental)"),
|
||||||
cmdkit.BoolOption(fstoreCacheOptionName, "Check the filestore for pre-existing blocks. (experimental)"),
|
cmdkit.BoolOption(fstoreCacheOptionName, "Check the filestore for pre-existing blocks. (experimental)"),
|
||||||
cmdkit.IntOption(cidVersionOptionName, "CID version. Defaults to 0 unless an option that depends on CIDv1 is passed. (experimental)"),
|
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:
|
|||||||
cidVer, cidVerSet := req.Options[cidVersionOptionName].(int)
|
cidVer, cidVerSet := req.Options[cidVersionOptionName].(int)
|
||||||
hashFunStr, _ := req.Options[hashOptionName].(string)
|
hashFunStr, _ := req.Options[hashOptionName].(string)
|
||||||
|
|
||||||
// Given the following constraints:
|
// The arguments are subject to the following constraints.
|
||||||
//
|
//
|
||||||
// nocopy -> filestoreEnabled
|
// nocopy -> filestoreEnabled
|
||||||
// nocopy -> rawblocks
|
// nocopy -> rawblocks
|
||||||
// rawblocks -> cidv1
|
|
||||||
// (hash != sha2-256) -> cidv1
|
// (hash != sha2-256) -> cidv1
|
||||||
//
|
|
||||||
// We solve for the values of rawblocks and cidv1 in the
|
|
||||||
// following order of preference:
|
|
||||||
//
|
|
||||||
// 1. If cidv1 isn't fixed, set it to false and try solving.
|
|
||||||
// 2. If rawblocks isn't fixed, set it to true and try solving.
|
|
||||||
//
|
|
||||||
// If neither solution works, give up (we have a conflict).
|
|
||||||
|
|
||||||
// nocopy -> filestorEnabled
|
// NOTE: 'rawblocks -> cidv1' is missing. Legacy reasons.
|
||||||
|
|
||||||
|
// nocopy -> filestoreEnabled
|
||||||
if nocopy && !cfg.Experimental.FilestoreEnabled {
|
if nocopy && !cfg.Experimental.FilestoreEnabled {
|
||||||
res.SetError(errors.New("filestore is not enabled, see https://git.io/vy4XN"),
|
res.SetError(errors.New("filestore is not enabled, see https://git.io/vy4XN"),
|
||||||
cmdkit.ErrClient)
|
cmdkit.ErrClient)
|
||||||
@ -209,26 +202,16 @@ You can now check what blocks have been created by:
|
|||||||
rawblks = true
|
rawblks = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cidVerSet {
|
// (hash != "sha2-256") -> CIDv1
|
||||||
// Default to CIDv0 if possible.
|
if hashFunStr != "sha2-256" && cidVer == 0 {
|
||||||
// Conditions: no raw blocks, sha2-256
|
if cidVerSet {
|
||||||
if hashFunStr == "sha2-256" && !rawblks {
|
|
||||||
cidVer = 0
|
|
||||||
} else {
|
|
||||||
cidVer = 1
|
|
||||||
}
|
|
||||||
} else if cidVer == 0 {
|
|
||||||
// CIDv0 *was* set...
|
|
||||||
if hashFunStr != "sha2-256" {
|
|
||||||
res.SetError(errors.New("CIDv0 only supports sha2-256"), cmdkit.ErrClient)
|
|
||||||
return
|
|
||||||
} else if rawblks {
|
|
||||||
res.SetError(
|
res.SetError(
|
||||||
errors.New("CIDv0 incompatible with raw-leaves and/or nocopy"),
|
errors.New("CIDv0 only supports sha2-256"),
|
||||||
cmdkit.ErrClient,
|
cmdkit.ErrClient,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
cidVer = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// cidV1 -> raw blocks (by default)
|
// cidV1 -> raw blocks (by default)
|
||||||
|
Reference in New Issue
Block a user