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-ds-flatfs
Commits
9492e359
Commit
9492e359
authored
Jan 13, 2017
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Always require the version string.
parent
b49a06df
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
17 deletions
+16
-17
flatfs.go
flatfs.go
+2
-2
flatfs_test.go
flatfs_test.go
+5
-5
shard.go
shard.go
+9
-10
No files found.
flatfs.go
View file @
9492e359
...
...
@@ -41,9 +41,9 @@ var _ datastore.Datastore = (*Datastore)(nil)
type
ShardFunc
func
(
string
)
string
var
(
ErrDatastoreExists
=
errors
.
New
(
"Datastore already exist"
)
ErrDatastoreExists
=
errors
.
New
(
"Datastore already exist"
)
ErrDatastoreDoesNotExist
=
errors
.
New
(
"Datastore directory does not exist"
)
ErrShardingFileMissing
=
errors
.
New
(
"SHARDING file not found in datastore"
)
ErrShardingFileMissing
=
errors
.
New
(
"SHARDING file not found in datastore"
)
)
const
IPFS_DEF_SHARD
=
"/repo/flatfs/shard/v1/next-to-last/2"
...
...
flatfs_test.go
View file @
9492e359
...
...
@@ -33,16 +33,16 @@ func tempdir(t testing.TB) (path string, cleanup func()) {
}
func
tryAllShardFuncs
(
t
*
testing
.
T
,
testFunc
func
(
string
,
*
testing
.
T
))
{
t
.
Run
(
"prefix"
,
func
(
t
*
testing
.
T
)
{
testFunc
(
"prefix"
,
t
)
})
t
.
Run
(
"suffix"
,
func
(
t
*
testing
.
T
)
{
testFunc
(
"suffix"
,
t
)
})
t
.
Run
(
"next-to-last"
,
func
(
t
*
testing
.
T
)
{
testFunc
(
"next-to-last"
,
t
)
})
t
.
Run
(
"prefix"
,
func
(
t
*
testing
.
T
)
{
testFunc
(
"
v1/
prefix"
,
t
)
})
t
.
Run
(
"suffix"
,
func
(
t
*
testing
.
T
)
{
testFunc
(
"
v1/
suffix"
,
t
)
})
t
.
Run
(
"next-to-last"
,
func
(
t
*
testing
.
T
)
{
testFunc
(
"
v1/
next-to-last"
,
t
)
})
}
func
TestPutBadValueType
(
t
*
testing
.
T
)
{
temp
,
cleanup
:=
tempdir
(
t
)
defer
cleanup
()
fs
,
err
:=
flatfs
.
CreateOrOpen
(
temp
,
"prefix/2"
,
false
)
fs
,
err
:=
flatfs
.
CreateOrOpen
(
temp
,
"
v1/
prefix/2"
,
false
)
if
err
!=
nil
{
t
.
Fatalf
(
"New fail: %v
\n
"
,
err
)
}
...
...
@@ -454,7 +454,7 @@ func TestNoCluster(t *testing.T) {
tempdir
,
cleanup
:=
tempdir
(
t
)
defer
cleanup
()
fs
,
err
:=
flatfs
.
CreateOrOpen
(
tempdir
,
"next-to-last/1"
,
false
)
fs
,
err
:=
flatfs
.
CreateOrOpen
(
tempdir
,
"
v1/
next-to-last/1"
,
false
)
if
err
!=
nil
{
t
.
Fatalf
(
"New fail: %v
\n
"
,
err
)
}
...
...
shard.go
View file @
9492e359
...
...
@@ -38,21 +38,20 @@ func ParseShardFunc(str string) (*ShardIdV1, error) {
}
str
=
trimmed
}
parts
:=
strings
.
Split
(
str
,
"/"
)
if
len
(
parts
)
==
3
{
version
:=
parts
[
0
]
if
version
!=
"v1"
{
return
nil
,
fmt
.
Errorf
(
"expected 'v1' for version string got: %s
\n
"
,
version
)
}
parts
=
parts
[
1
:
]
}
if
len
(
parts
)
!=
2
{
if
len
(
parts
)
!=
3
{
return
nil
,
fmt
.
Errorf
(
"invalid shard identifier: %s"
,
str
)
}
id
:=
&
ShardIdV1
{
funName
:
parts
[
0
]}
version
:=
parts
[
0
]
if
version
!=
"v1"
{
return
nil
,
fmt
.
Errorf
(
"expected 'v1' for version string got: %s
\n
"
,
version
)
}
id
:=
&
ShardIdV1
{
funName
:
parts
[
1
]}
param
,
err
:=
strconv
.
Atoi
(
parts
[
1
])
param
,
err
:=
strconv
.
Atoi
(
parts
[
2
])
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid parameter: %v"
,
err
)
}
...
...
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