Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
4909c5a5
Commit
4909c5a5
authored
Jan 23, 2018
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correctly handle add flag constraints
License: MIT Signed-off-by:
Steven Allen
<
steven@stebalien.com
>
parent
fcef972c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
18 deletions
+57
-18
core/commands/add.go
core/commands/add.go
+57
-18
No files found.
core/commands/add.go
View file @
4909c5a5
...
@@ -114,11 +114,11 @@ You can now check what blocks have been created by:
...
@@ -114,11 +114,11 @@ 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. (experimental)"
),
cmdkit
.
BoolOption
(
rawLeavesOptionName
,
"Use raw blocks for leaf nodes.
Implies CIDv1, defaults to on if CIDv1 is enabled.
(experimental)"
),
cmdkit
.
BoolOption
(
noCopyOptionName
,
"Add the file using filestore. (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
,
"C
id
version.
Non-zero value will change default of 'raw-leaves' to true
. (experimental)"
)
.
WithDefault
(
0
)
,
cmdkit
.
IntOption
(
cidVersionOptionName
,
"C
ID
version.
Defaults to 0 unless an option that depends on CIDv1 is passed
. (experimental)"
),
cmdkit
.
StringOption
(
hashOptionName
,
"Hash function to use.
Will set Cid version to 1 if used
. (experimental)"
)
.
WithDefault
(
"sha2-256"
),
cmdkit
.
StringOption
(
hashOptionName
,
"Hash function to use.
Implies CIDv1 if not sha2-256
. (experimental)"
)
.
WithDefault
(
"sha2-256"
),
},
},
PreRun
:
func
(
req
*
cmds
.
Request
,
env
cmds
.
Environment
)
error
{
PreRun
:
func
(
req
*
cmds
.
Request
,
env
cmds
.
Environment
)
error
{
quiet
,
_
:=
req
.
Options
[
quietOptionName
]
.
(
bool
)
quiet
,
_
:=
req
.
Options
[
quietOptionName
]
.
(
bool
)
...
@@ -170,31 +170,70 @@ You can now check what blocks have been created by:
...
@@ -170,31 +170,70 @@ You can now check what blocks have been created by:
rawblks
,
rbset
:=
req
.
Options
[
rawLeavesOptionName
]
.
(
bool
)
rawblks
,
rbset
:=
req
.
Options
[
rawLeavesOptionName
]
.
(
bool
)
nocopy
,
_
:=
req
.
Options
[
noCopyOptionName
]
.
(
bool
)
nocopy
,
_
:=
req
.
Options
[
noCopyOptionName
]
.
(
bool
)
fscache
,
_
:=
req
.
Options
[
fstoreCacheOptionName
]
.
(
bool
)
fscache
,
_
:=
req
.
Options
[
fstoreCacheOptionName
]
.
(
bool
)
cidVer
,
_
:=
req
.
Options
[
cidVersionOptionName
]
.
(
int
)
cidVer
,
cidVerSet
:=
req
.
Options
[
cidVersionOptionName
]
.
(
int
)
hashFunStr
,
hfset
:=
req
.
Options
[
hashOptionName
]
.
(
string
)
hashFunStr
,
_
:=
req
.
Options
[
hashOptionName
]
.
(
string
)
// Given the following constraints:
//
// nocopy -> filestoreEnabled
// nocopy -> rawblocks
// rawblocks -> 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
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
)
return
return
}
}
if
hfset
&&
hashFunStr
!=
"sha2-256"
&&
cidVer
==
0
{
// nocopy -> rawblocks
cidVer
=
1
if
nocopy
&&
!
rawblks
{
}
// fixed?
if
rbset
{
if
cidVer
>
0
&&
!
rbset
{
res
.
SetError
(
fmt
.
Errorf
(
"nocopy option requires '--raw-leaves' to be enabled as well"
),
cmdkit
.
ErrNormal
,
)
return
}
// No, satisfy mandatory constraint.
rawblks
=
true
rawblks
=
true
}
}
// if rawblocks is not explicitly set but nocopy is, set rawblocks
if
!
cidVerSet
{
if
nocopy
&&
!
rbset
{
// Default to CIDv0 if possible.
rawblks
=
true
// Conditions: no raw blocks, sha2-256
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
(
errors
.
New
(
"CIDv0 incompatible with raw-leaves and/or nocopy"
),
cmdkit
.
ErrClient
,
)
return
}
}
}
if
nocopy
&&
!
rawblks
{
// cidV1 ->
raw
bl
oc
ks
(by default)
res
.
SetError
(
fmt
.
Errorf
(
"nocopy option requires '--raw-leaves' to be enabled as well"
),
cmdkit
.
ErrNormal
)
if
cidVer
>
0
&&
!
rbset
{
r
eturn
r
awblks
=
true
}
}
prefix
,
err
:=
dag
.
PrefixForCidVersion
(
cidVer
)
prefix
,
err
:=
dag
.
PrefixForCidVersion
(
cidVer
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment