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
d4844efe
Commit
d4844efe
authored
Dec 15, 2016
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for NextToLast shard function.
parent
ace251fd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
0 deletions
+18
-0
flatfs.go
flatfs.go
+9
-0
flatfs_test.go
flatfs_test.go
+9
-0
No files found.
flatfs.go
View file @
d4844efe
...
...
@@ -62,6 +62,15 @@ func Suffix(suffixLen int) ShardFunc {
}
}
func
NextToLast
(
suffixLen
int
)
ShardFunc
{
padding
:=
strings
.
Repeat
(
"_"
,
suffixLen
+
1
)
return
func
(
noslash
string
)
string
{
str
:=
padding
+
noslash
offset
:=
len
(
str
)
-
suffixLen
-
1
return
str
[
offset
:
offset
+
suffixLen
]
}
}
func
(
fs
*
Datastore
)
encode
(
key
datastore
.
Key
)
(
dir
,
file
string
)
{
noslash
:=
key
.
String
()[
1
:
]
dir
=
path
.
Join
(
fs
.
path
,
fs
.
getDir
(
noslash
))
...
...
flatfs_test.go
View file @
d4844efe
...
...
@@ -33,6 +33,7 @@ func tempdir(t testing.TB) (path string, cleanup func()) {
func
tryAllShardFuncs
(
t
*
testing
.
T
,
testFunc
func
(
mkShardFunc
,
*
testing
.
T
))
{
t
.
Run
(
"prefix"
,
func
(
t
*
testing
.
T
)
{
testFunc
(
flatfs
.
Prefix
,
t
)
})
t
.
Run
(
"suffix"
,
func
(
t
*
testing
.
T
)
{
testFunc
(
flatfs
.
Suffix
,
t
)
})
t
.
Run
(
"next-to-last"
,
func
(
t
*
testing
.
T
)
{
testFunc
(
flatfs
.
NextToLast
,
t
)
})
}
func
TestPutBadValueType
(
t
*
testing
.
T
)
{
...
...
@@ -230,6 +231,14 @@ func TestStorage(t *testing.T) {
dirFunc
:
flatfs
.
Suffix
,
},
t
)
})
t
.
Run
(
"next-to-last"
,
func
(
t
*
testing
.
T
)
{
testStorage
(
&
params
{
what
:
"next-to-last"
,
dir
:
"uu"
,
key
:
"quux"
,
dirFunc
:
flatfs
.
NextToLast
,
},
t
)
})
}
func
testHasNotFound
(
dirFunc
mkShardFunc
,
t
*
testing
.
T
)
{
...
...
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