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
1df2c1e0
Commit
1df2c1e0
authored
Oct 04, 2018
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add GetSize function
parent
135b2edb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
0 deletions
+56
-0
flatfs.go
flatfs.go
+12
-0
flatfs_test.go
flatfs_test.go
+44
-0
No files found.
flatfs.go
View file @
1df2c1e0
...
...
@@ -577,6 +577,18 @@ func (fs *Datastore) Has(key datastore.Key) (exists bool, err error) {
}
}
func
(
fs
*
Datastore
)
GetSize
(
key
datastore
.
Key
)
(
size
int
,
err
error
)
{
_
,
path
:=
fs
.
encode
(
key
)
switch
s
,
err
:=
os
.
Stat
(
path
);
{
case
err
==
nil
:
return
int
(
s
.
Size
()),
nil
case
os
.
IsNotExist
(
err
)
:
return
-
1
,
datastore
.
ErrNotFound
default
:
return
-
1
,
err
}
}
// Delete removes a key/value from the Datastore. Please read
// the Put() explanation about the handling of concurrent write
// operations to the same key.
...
...
flatfs_test.go
View file @
1df2c1e0
...
...
@@ -289,6 +289,50 @@ func testHasFound(dirFunc mkShardFunc, t *testing.T) {
func
TestHasFound
(
t
*
testing
.
T
)
{
tryAllShardFuncs
(
t
,
testHasFound
)
}
func
testGetSizeFound
(
dirFunc
mkShardFunc
,
t
*
testing
.
T
)
{
temp
,
cleanup
:=
tempdir
(
t
)
defer
cleanup
()
fs
,
err
:=
flatfs
.
CreateOrOpen
(
temp
,
dirFunc
(
2
),
false
)
if
err
!=
nil
{
t
.
Fatalf
(
"New fail: %v
\n
"
,
err
)
}
defer
fs
.
Close
()
_
,
err
=
fs
.
GetSize
(
datastore
.
NewKey
(
"quux"
))
if
err
!=
datastore
.
ErrNotFound
{
t
.
Fatalf
(
"GetSize should have returned ErrNotFound, got: %v
\n
"
,
err
)
}
}
func
TestGetSizeFound
(
t
*
testing
.
T
)
{
tryAllShardFuncs
(
t
,
testGetSizeFound
)
}
func
testGetSizeNotFound
(
dirFunc
mkShardFunc
,
t
*
testing
.
T
)
{
temp
,
cleanup
:=
tempdir
(
t
)
defer
cleanup
()
fs
,
err
:=
flatfs
.
CreateOrOpen
(
temp
,
dirFunc
(
2
),
false
)
if
err
!=
nil
{
t
.
Fatalf
(
"New fail: %v
\n
"
,
err
)
}
defer
fs
.
Close
()
err
=
fs
.
Put
(
datastore
.
NewKey
(
"quux"
),
[]
byte
(
"foobar"
))
if
err
!=
nil
{
t
.
Fatalf
(
"Put fail: %v
\n
"
,
err
)
}
size
,
err
:=
fs
.
GetSize
(
datastore
.
NewKey
(
"quux"
))
if
err
!=
nil
{
t
.
Fatalf
(
"GetSize failed with: %v
\n
"
,
err
)
}
if
size
!=
len
(
"foobar"
)
{
t
.
Fatalf
(
"GetSize returned wrong size: got %d, expected %d"
,
size
,
len
(
"foobar"
))
}
}
func
TestGetSizeNotFound
(
t
*
testing
.
T
)
{
tryAllShardFuncs
(
t
,
testGetSizeNotFound
)
}
func
testDeleteNotFound
(
dirFunc
mkShardFunc
,
t
*
testing
.
T
)
{
temp
,
cleanup
:=
tempdir
(
t
)
defer
cleanup
()
...
...
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