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
b49a06df
Commit
b49a06df
authored
Jan 13, 2017
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor cleanups.
parent
fbc4d441
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
14 deletions
+13
-14
flatfs.go
flatfs.go
+9
-11
shard.go
shard.go
+4
-3
No files found.
flatfs.go
View file @
b49a06df
...
...
@@ -40,9 +40,11 @@ var _ datastore.Datastore = (*Datastore)(nil)
type
ShardFunc
func
(
string
)
string
var
DatastoreExists
=
errors
.
New
(
"Datastore already exist"
)
var
DatastoreDoesNotExist
=
errors
.
New
(
"Datastore directory does not exist"
)
var
ShardingFileMissing
=
errors
.
New
(
"SHARDING file not found in datastore"
)
var
(
ErrDatastoreExists
=
errors
.
New
(
"Datastore already exist"
)
ErrDatastoreDoesNotExist
=
errors
.
New
(
"Datastore directory does not exist"
)
ErrShardingFileMissing
=
errors
.
New
(
"SHARDING file not found in datastore"
)
)
const
IPFS_DEF_SHARD
=
"/repo/flatfs/shard/v1/next-to-last/2"
...
...
@@ -60,7 +62,7 @@ func Create(path string, funStr string) error {
dsFun
,
err
:=
ReadShardFunc
(
path
)
switch
err
{
case
ShardingFileMissing
:
case
Err
ShardingFileMissing
:
// fixme: make sure directory is empty and return an error if
// it is not
err
:=
WriteShardFunc
(
path
,
fun
)
...
...
@@ -74,7 +76,7 @@ func Create(path string, funStr string) error {
return
fmt
.
Errorf
(
"specified shard func '%s' does not match repo shard func '%s'"
,
fun
.
String
(),
dsFun
.
String
())
}
return
DatastoreExists
return
Err
DatastoreExists
default
:
return
err
}
...
...
@@ -83,7 +85,7 @@ func Create(path string, funStr string) error {
func
Open
(
path
string
,
sync
bool
)
(
*
Datastore
,
error
)
{
_
,
err
:=
os
.
Stat
(
path
)
if
os
.
IsNotExist
(
err
)
{
return
nil
,
DatastoreDoesNotExist
return
nil
,
Err
DatastoreDoesNotExist
}
else
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -93,10 +95,6 @@ func Open(path string, sync bool) (*Datastore, error) {
return
nil
,
err
}
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"unable to parse shard func: %v"
,
err
)
}
fs
:=
&
Datastore
{
path
:
path
,
shardFunc
:
shardId
.
String
(),
...
...
@@ -109,7 +107,7 @@ func Open(path string, sync bool) (*Datastore, error) {
// convince method, fixme: maybe just call it "New"?
func
CreateOrOpen
(
path
string
,
fun
string
,
sync
bool
)
(
*
Datastore
,
error
)
{
err
:=
Create
(
path
,
fun
)
if
err
!=
nil
&&
err
!=
DatastoreExists
{
if
err
!=
nil
&&
err
!=
Err
DatastoreExists
{
return
nil
,
err
}
return
Open
(
path
,
sync
)
...
...
shard.go
View file @
b49a06df
...
...
@@ -32,10 +32,11 @@ func ParseShardFunc(str string) (*ShardIdV1, error) {
return
nil
,
fmt
.
Errorf
(
"empty shard identifier"
)
}
if
str
[
0
]
==
'/'
{
if
!
strings
.
HasPrefix
(
str
,
PREFIX
)
{
trimmed
:=
strings
.
TrimPrefix
(
str
,
PREFIX
)
if
str
==
trimmed
{
// nothing trimmed
return
nil
,
fmt
.
Errorf
(
"invalid prefix in shard identifier: %s"
,
str
)
}
str
=
s
tr
[
len
(
PREFIX
)
:
]
str
=
tr
immed
}
parts
:=
strings
.
Split
(
str
,
"/"
)
if
len
(
parts
)
==
3
{
...
...
@@ -74,7 +75,7 @@ func ParseShardFunc(str string) (*ShardIdV1, error) {
func
ReadShardFunc
(
dir
string
)
(
*
ShardIdV1
,
error
)
{
buf
,
err
:=
ioutil
.
ReadFile
(
filepath
.
Join
(
dir
,
"SHARDING"
))
if
os
.
IsNotExist
(
err
)
{
return
nil
,
ShardingFileMissing
return
nil
,
Err
ShardingFileMissing
}
else
if
err
!=
nil
{
return
nil
,
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